-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
661 lines (318 loc) · 373 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>Microsoft Edge 分屏功能推荐</title>
<link href="/archives/a375e98c.html"/>
<url>/archives/a375e98c.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h2 id="前言:"><a href="#前言:" class="headerlink" title="前言:"></a>前言:</h2><blockquote><p>很早之前就在 Edge Dev 频道的更新公告中看到过 Edge 的新分屏功能,当时没怎么注意,昨天看文档的时候发现 Edge 的侧边栏可以拖动当作一个“虚假的”分屏页面来用,但是体验不是很好就想到了这个新功能,给大家推荐一下,个人觉得蛮好用的。</p></blockquote><h2 id="Microsoft-Edge-Split-Screen"><a href="#Microsoft-Edge-Split-Screen" class="headerlink" title="Microsoft Edge Split Screen"></a>Microsoft Edge Split Screen</h2><p>微软是在 Edge Canary 110 版本更新中发布的 分屏功能: 一个窗口同时浏览两个页面。</p><p>这个功能属于实验性功能,默认是不开启的,需要手动开启,最新版本不管是哪个通道的应该都有这个功能:</p><p>在地址栏粘贴打开下面的地址:</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">edge://flags/#edge-split-screen</span><br></pre></td></tr></table></figure><p>向上滑动就能找到 Microsoft Edge Split Screen 选项,更改为 Enabled ,然后重启浏览器就能使用分屏功能了。</p><p>启用后地址栏会出现一个分屏按钮(Split Window),点击即可切换,在右侧选择已经开启的页面,或者点击打开新标签等等。</p><p>当然了,单机最上方的标签页还是会新打开一个页面,互不影响。</p><p><img src="https://img2023.cnblogs.com/blog/2913706/202303/2913706-20230331095135260-949101308.gif" alt="Split"></p><p>单个页面上的有个小按钮可以选择这个页面的链接点击后是这个页面显示还是在右侧页面显示,大家可以自己选择,需要注意的是,右侧页面选择新链接在右侧页面打开是无效的,因为一屏只能同时显示两个标签页。</p><p><img src="https://img2023.cnblogs.com/blog/2913706/202303/2913706-20230331095349278-1727787523.png" alt="image-20230331095348578"></p>]]></content>
<categories>
<category> Edge 实用小功能 </category>
</categories>
<tags>
<tag> Microsoft Edge </tag>
<tag> Edge Way </tag>
</tags>
</entry>
<entry>
<title>Winform程序制作安装包</title>
<link href="/archives/a76b87d6.html"/>
<url>/archives/a76b87d6.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><blockquote><p>记录一下Winform程序打包过程<br>参考文章:<a href="https://www.cnblogs.com/GuZhenYin/p/8176981.html" title="VS2017 WinFrom打包设置与教程">VS2017 WinFrom打包设置与教程</a></p></blockquote><h1 id="下载-Visual-Studio-Installer-拓展插件"><a href="#下载-Visual-Studio-Installer-拓展插件" class="headerlink" title="下载 Visual Studio Installer 拓展插件"></a>下载 Visual Studio Installer 拓展插件</h1><p>&#160; &#160; &#160; &#160;从VS2017开始VS已默认不再集成Installer拓展,所以需要手动下载安装,在 <strong>工具 - 插件和更新</strong> 里面的插件商店里面搜索”<strong>installer</strong>“安装。<br><img src="https://img2023.cnblogs.com/blog/2913706/202302/2913706-20230201164335955-1158786909.png"></p><h1 id="制作打包文件"><a href="#制作打包文件" class="headerlink" title="制作打包文件"></a>制作打包文件</h1><ol><li>右键 Winform程序所在的解决方案 - 添加 - 新建项目</li><li>找到 <strong>Setup Project</strong> 创建项目<ul><li>新建的Setup Project的项目名称就是打包完成以后安装程序的名称</li></ul></li><li>添加入口文件(主输出):右键 Application Folder - Add - 项目输出<ul><li>主输出就是解决方案中的启动项目,也就是<code>Main()</code>方法<br> <img src="https://img2023.cnblogs.com/blog/2913706/202302/2913706-20230201165851734-1050381890.png"></li></ul></li><li>添加快捷方式图标文件:右键 Application Folder - Add - 文件 - 找到图标文件添加即可<br> <img src="https://img2023.cnblogs.com/blog/2913706/202302/2913706-20230201170257868-1893411778.png"></li><li>创建快捷方式:右键 主输出 - Create Shortcut to …(创建快捷方式)<br> <img src="https://img2023.cnblogs.com/blog/2913706/202302/2913706-20230201170437549-449438386.png"></li><li>自定义快捷方式属性:右键 生成的快捷方式 - 属性窗口<br> <img src="https://img2023.cnblogs.com/blog/2913706/202302/2913706-20230201170707532-1504948246.png"><ul><li>将刚才创建并配置好的快捷方式拖入 <strong>User’s Desktop</strong> 文件夹,即可在程序安装时自动生成桌面快捷方式;</li><li>重复以上步骤再创建一个快捷方式,拖入到 <strong>User’s Programs Menu</strong> 文件里面即可在程序安装时自动在开始菜单中添加快捷方式;<br><img src="https://img2023.cnblogs.com/blog/2913706/202302/2913706-20230201171220534-764098646.png"></li></ul></li><li>设置程序需要的 <strong>.Net</strong> 版本:右键 安装项目 - 属性 - Prerequisites<br><img src="https://img2023.cnblogs.com/blog/2913706/202302/2913706-20230201171538759-875966091.png"></li><li>手动添加其他资源文件<ul><li>我这里没有用到其他文件资源,如果程序用到了其他配置资源,右键 Application Folder - Add - 文件 ,手动添加就可以了。</li></ul></li><li>右键 - 安装项目 - 生成 就可以生成安装程序了。<br><img src="https://img2023.cnblogs.com/blog/2913706/202302/2913706-20230201172500272-114949923.png"></li></ol><h1 id="图片不显示问题:"><a href="#图片不显示问题:" class="headerlink" title="图片不显示问题:"></a>图片不显示问题:</h1><blockquote><p>不知道为什么从博客园粘贴过来的图片没办法显示,这里贴上博客园文章链接:<br><a href="https://www.cnblogs.com/BoiledYakult/p/17083681.html">Winform程序制作安装包</a></p></blockquote>]]></content>
<categories>
<category> Winform </category>
</categories>
<tags>
<tag> 安装包制作 </tag>
</tags>
</entry>
<entry>
<title>C# 判断IP地址是否正确</title>
<link href="/archives/1b9b23f2.html"/>
<url>/archives/1b9b23f2.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><blockquote><p>参考文章:<a href="https://www.cnblogs.com/chendaoyin/p/3568881.html" title="C# 判断ip地址是否正确">C# 判断ip地址是否正确</a></p></blockquote><p>楼主提供的方法是通过<code>IPAddress.TryParse(String, IPAddress)</code>来判断字符串是否为有效地址,如果能解析IP地址,则为<code>true</code>。这个方法也蛮巧妙的,判断IP地址我第一反应是根据<code>'.'</code>分割字符串然后每个字符挨个判断,手动写格式判断啥的,效率低还麻烦,容易出错,看到楼主那个还挺好玩的,就试了一下。发现了一些问题:</p><details><summary>IPAddress.TryParse()方法</summary><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">string ipStr = "10.1";</span><br><span class="line">System.Net.IPAddress ip;</span><br><span class="line">if (System.Net.IPAddress.TryParse(ipStr,out ip))</span><br><span class="line">{</span><br><span class="line"> MessageBox.Show("IP地址合法");</span><br><span class="line">}</span><br><span class="line">else</span><br><span class="line">{</span><br><span class="line"> MessageBox.Show("IP地址不合法");</span><br><span class="line">}</span><br></pre></td></tr></table></figure></details><br><p>这个方法没办法对输入的IP的格式进行判断,测试字符串是<strong>10.1</strong>在测试过程中是可以成功转换的,但是显然输入的IP不是有效地址。可以转换成功的原因是<code>IPAddress.TryParse()</code>方法接受有效的<code>String</code>值,可以分析为一个<code>Int64</code>值,然后将这个值作为IP地址的长值,这就意味着只要接受到的字符串可以成功解析成一个<code>Int64</code>值就会返回<code>True</code>,即使它表示的不是有效的IP地址。<br>微软技术文档在说明该方法时提供了以下注解:</p><blockquote><p>例如,如果 ipString 为“1”,则此方法返回 true,即使“1” (或 0.0.0.1) 不是有效的 IP 地址,你可能期望此方法返回 false。 修复此 bug 会中断现有应用,因此不会更改当前行为。 代码可以通过确保仅使用此方法分析采用点十进制格式的 IP 地址来避免此行为。</p></blockquote><p>楼主评论区中有人提出可以用正则表达式来判断,既能判断格式也能判断数值,一举两得。</p><details><summary>正则表达式</summary><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex(@"\b((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))\b");</span><br><span class="line">string ipStr = "10.1";</span><br><span class="line">if (rx.IsMatch(ipStr) == false)</span><br><span class="line">{</span><br><span class="line">MessageBox.Show("IP地址不合法");</span><br><span class="line">return;</span><br><span class="line">}</span><br><span class="line">else</span><br><span class="line">{</span><br><span class="line">MessageBox.Show("IP地址合法");</span><br><span class="line">}</span><br></pre></td></tr></table></figure></details><br>Perfect!]]></content>
<categories>
<category> C#实用小技巧 </category>
</categories>
<tags>
<tag> C#实用小技巧 </tag>
</tags>
</entry>
<entry>
<title>C#操作EXCEL文件方法</title>
<link href="/archives/6199859c.html"/>
<url>/archives/6199859c.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><blockquote><p>目前仅尝试过微软官方提供的COM组件以及第三方类库NPOI进行EXCEL文件的操作,COM组件明显效率较低,推荐NPOI或者新兴的MiniExcel。</p></blockquote><h2 id="COM组件读取"><a href="#COM组件读取" class="headerlink" title="COM组件读取"></a>COM组件读取</h2><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 通过COM组件读取Excel文件内容</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="excelFilePath"></span>Excel文件所在路径<span class="doctag"></param></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><returns></span>数据集<span class="doctag"></returns></span></span></span><br><span class="line"><span class="function"><span class="keyword">private</span> DataSet <span class="title">GetExcelData</span>(<span class="params"><span class="built_in">string</span> excelFilePath</span>)</span></span><br><span class="line">{</span><br><span class="line"> DataSet dataSet = <span class="keyword">new</span> DataSet();</span><br><span class="line"> Excel.Application app = <span class="keyword">new</span> Excel.Application();</span><br><span class="line"> Sheets sheets;</span><br><span class="line"> Workbook workbook = <span class="literal">null</span>;</span><br><span class="line"> <span class="built_in">object</span> oMissiong = Missing.Value;</span><br><span class="line"> <span class="built_in">string</span> cellContent;<span class="comment">//Excel文件中单元格内容</span></span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (app == <span class="literal">null</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//通过已存在的Execl文件来创建workbook工作簿,即整个excel文档</span></span><br><span class="line"> workbook = app.Workbooks.Open(excelFilePath, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong,</span><br><span class="line"> oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong);</span><br><span class="line"> <span class="comment">// 获取excel内sheet表单个数</span></span><br><span class="line"> sheets = workbook.Worksheets;</span><br><span class="line"> System.Data.DataTable dt = <span class="keyword">new</span> System.Data.DataTable();</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> p = <span class="number">1</span>; p <= sheets.Count; p++)</span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//workSheet存储读取的Excel文件内的第p张表</span></span><br><span class="line"> Worksheet workSheet = (Worksheet)sheets.get_Item(p);</span><br><span class="line"> <span class="comment">//读取列标题,添加到dt表中,通过Cells中的行数坐标控制读取的列所在行</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">1</span>; j <= workSheet.UsedRange.Columns.Count; j++)</span><br><span class="line"> {</span><br><span class="line"> Range _range = (Range)workSheet.Cells[<span class="number">2</span>, j];<span class="comment">//第2行第j列</span></span><br><span class="line"> dt.Columns.Add(_range.Text.ToString().Trim());<span class="comment">//将读取到的列添加到dt表中</span></span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//读取Excel表中数据,将数据添加到dt表中</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">3</span>; i <= workSheet.UsedRange.Rows.Count; i++)</span><br><span class="line"> {</span><br><span class="line"> DataRow dr = dt.NewRow();<span class="comment">//每读一行就新建一行存储下一行数据</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">1</span>; j <= workSheet.UsedRange.Columns.Count; j++)</span><br><span class="line"> {</span><br><span class="line"> Range _range = (Range)workSheet.Cells[i, j];<span class="comment">//第i行j列</span></span><br><span class="line"> cellContent = (_range.Value2 == <span class="literal">null</span>) ? <span class="string">""</span> : _range.Text.ToString().Trim();<span class="comment">//正则表达式,分为空和不空两种情况</span></span><br><span class="line"> dr[j - <span class="number">1</span>] = cellContent;<span class="comment">//j-1是因为dt表是从0开始的,但是读取excel文件时是从1开始的</span></span><br><span class="line"> }</span><br><span class="line"> dt.Rows.Add(dr);<span class="comment">//将读取到的行内容添加到dt表中</span></span><br><span class="line"> }</span><br><span class="line"> dataSet.Tables.Add(dt);<span class="comment">//添加dt表到数据集dataSet中</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">finally</span></span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//workbook.Close(false, oMissiong, oMissiong);</span></span><br><span class="line"> <span class="comment">//System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);</span></span><br><span class="line"> <span class="comment">//workbook = null;</span></span><br><span class="line"> <span class="comment">//app.Workbooks.Close();</span></span><br><span class="line"> <span class="comment">//app.Quit();</span></span><br><span class="line"> <span class="comment">//System.Runtime.InteropServices.Marshal.ReleaseComObject(app);</span></span><br><span class="line"> <span class="comment">//app = null;</span></span><br><span class="line"> <span class="comment">//GC.Collect();</span></span><br><span class="line"> <span class="comment">//GC.WaitForPendingFinalizers();</span></span><br><span class="line"> ClosePro(app, workbook);<span class="comment">//释放资源</span></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> dataSet;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="读取过程中的资源释放问题"><a href="#读取过程中的资源释放问题" class="headerlink" title="读取过程中的资源释放问题"></a>读取过程中的资源释放问题</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">DllImport(<span class="string">"User32.dll"</span>, CharSet = CharSet.Auto)</span>]</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">extern</span> <span class="built_in">int</span> <span class="title">GetWindowThreadProcessId</span>(<span class="params">IntPtr hwnd, <span class="keyword">out</span> <span class="built_in">int</span> ID</span>)</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 关闭进程PLUS</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="xlApp"></span>应用对象<span class="doctag"></param></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="xlsWorkBook"></span>操作工作簿<span class="doctag"></param></span></span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">ClosePro</span>(<span class="params">Excel.Application xlApp, Workbook xlsWorkBook</span>)</span></span><br><span class="line">{</span><br><span class="line"> <span class="keyword">if</span> (xlsWorkBook != <span class="literal">null</span>)</span><br><span class="line"> xlsWorkBook.Close(<span class="literal">true</span>, Type.Missing, Type.Missing);</span><br><span class="line"> xlApp.Quit();</span><br><span class="line"> GC.GetGeneration(xlApp); <span class="comment">// 安全回收进程</span></span><br><span class="line"> IntPtr t = <span class="keyword">new</span> IntPtr(xlApp.Hwnd); <span class="comment">//获取句柄</span></span><br><span class="line"> GetWindowThreadProcessId(t, <span class="keyword">out</span> <span class="built_in">int</span> k); <span class="comment">//获取进程唯一标志</span></span><br><span class="line"> System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);</span><br><span class="line"> p.Kill(); <span class="comment">//关闭进程</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="COM组件打开显示Excel"><a href="#COM组件打开显示Excel" class="headerlink" title="COM组件打开显示Excel"></a>COM组件打开显示Excel</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Excel.Application app = <span class="keyword">new</span> Excel.Application();</span><br><span class="line"> app.Visible = <span class="literal">true</span>;</span><br><span class="line"> Excel.Workbook Book = app.Workbooks._Open(ExportDir,</span><br><span class="line"> Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);</span><br></pre></td></tr></table></figure><h2 id="NPOI读取Excel文件"><a href="#NPOI读取Excel文件" class="headerlink" title="NPOI读取Excel文件"></a>NPOI读取Excel文件</h2><blockquote><p>整个Excel表格叫做工作表:WorkBook(工作薄),包含的叫页(工作表):Sheet;行:Row;列:Column;单元格Cell。</p></blockquote><blockquote><p>NPOI是POI的C#版本,NPOI的行和列的index都是从0开始</p><p>参考文档:<a href="https://www.cnblogs.com/springsnow/p/13123912.html">使用NPOI进行Excel数据的导入导出</a>(<a href="https://www.cnblogs.com/springsnow/p/13123912.html#_label1">https://www.cnblogs.com/springsnow/p/13123912.html#_label1</a>)</p></blockquote><h3 id="NPOI读写单张表"><a href="#NPOI读写单张表" class="headerlink" title="NPOI读写单张表"></a>NPOI读写单张表</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> NPOI.HSSF.UserModel;</span><br><span class="line"><span class="keyword">using</span> NPOI.SS.UserModel;</span><br><span class="line"><span class="keyword">using</span> NPOI.XSSF.UserModel;</span><br><span class="line"><span class="keyword">using</span> System.Data;</span><br><span class="line"><span class="keyword">using</span> System.IO;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> <span class="title">Vol_Changer_ShortCircuit.Operate</span></span><br><span class="line">{</span><br><span class="line"> <span class="keyword">class</span> <span class="title">ExcelHelper</span></span><br><span class="line"> {</span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 从Excel读取数据,只支持单表</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="FilePath"></span>文件路径<span class="doctag"></param></span></span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> DataTable <span class="title">ReadFromExcel</span>(<span class="params"><span class="built_in">string</span> FilePath</span>)</span></span><br><span class="line"> {</span><br><span class="line"> IWorkbook wk = <span class="literal">null</span>;</span><br><span class="line"> <span class="built_in">string</span> extension = Path.GetExtension(FilePath); <span class="comment">//获取扩展名</span></span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">using</span> (FileStream fs = File.OpenRead(FilePath))</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (extension.Equals(<span class="string">".xls"</span>)) <span class="comment">//2003</span></span><br><span class="line"> {</span><br><span class="line"> wk = <span class="keyword">new</span> HSSFWorkbook(fs);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="comment">//2007以上</span></span><br><span class="line"> {</span><br><span class="line"> wk = <span class="keyword">new</span> XSSFWorkbook(fs);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//读取当前表数据,Sheet总数量</span></span><br><span class="line"> ISheet sheet = wk.GetSheetAt(<span class="number">0</span>);</span><br><span class="line"></span><br><span class="line"> <span class="comment">//构建DataTable,该部分内容可通过实际需求自行调整DataTable的结构,可以直接传入一个带结构的DataTable,也可以每次都生成</span></span><br><span class="line"> IRow row = sheet.GetRow(<span class="number">4</span>);<span class="comment">//获取行</span></span><br><span class="line"> DataTable result = BuildDataTable(row);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (result != <span class="literal">null</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (sheet.LastRowNum >= <span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">5</span>; i < sheet.LastRowNum + <span class="number">1</span>; i++)</span><br><span class="line"> {</span><br><span class="line"> IRow temp_row = sheet.GetRow(i);</span><br><span class="line"> <span class="keyword">if</span> (temp_row == <span class="literal">null</span>) { <span class="keyword">continue</span>; }<span class="comment">// 修复 行为空时会出错</span></span><br><span class="line"> List<<span class="built_in">object</span>> itemArray = <span class="keyword">new</span> List<<span class="built_in">object</span>>();</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < result.Columns.Count; j++)<span class="comment">//解决Excel超出DataTable列问题 </span></span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//itemArray.Add(temp_row.GetCell(j) == null ? string.Empty : temp_row.GetCell(j).ToString());</span></span><br><span class="line"> itemArray.Add(GetValueType(temp_row.GetCell(j)));<span class="comment">//解决 导入Excel 时间格式问题 </span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> result.Rows.Add(itemArray.ToArray());</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> result;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">catch</span> (Exception ex)</span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//自行定义异常处理方式</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 将DataTable数据导入到excel中</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="data"></span>要导入的数据<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="isColumnWritten"></span>DataTable的列名是否要导入<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="sheetName"></span>要导入的excel的sheet的名称<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="fileName"></span>导出的文件途径<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><returns></span>导入数据行数(包含列名那一行)<span class="doctag"></returns></span></span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="built_in">int</span> <span class="title">DataTableToExcel</span>(<span class="params">DataTable data, <span class="built_in">string</span> sheetName, <span class="built_in">string</span> fileName, <span class="built_in">bool</span> isColumnWritten = <span class="literal">true</span></span>)</span></span><br><span class="line"> {</span><br><span class="line"> IWorkbook workbook = <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">using</span> (FileStream fs = <span class="keyword">new</span> FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (fileName.IndexOf(<span class="string">".xlsx"</span>) > <span class="number">0</span>) <span class="comment">// 2007版本</span></span><br><span class="line"> {</span><br><span class="line"> workbook = <span class="keyword">new</span> XSSFWorkbook();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (fileName.IndexOf(<span class="string">".xls"</span>) > <span class="number">0</span>) <span class="comment">// 2003版本</span></span><br><span class="line"> {</span><br><span class="line"> workbook = <span class="keyword">new</span> HSSFWorkbook();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (workbook == <span class="literal">null</span>) { <span class="keyword">return</span> <span class="number">-1</span>; }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> {</span><br><span class="line"> ISheet sheet = workbook.CreateSheet(sheetName);</span><br><span class="line"> <span class="built_in">int</span> count = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">if</span> (isColumnWritten) <span class="comment">//写入DataTable的列名</span></span><br><span class="line"> {</span><br><span class="line"> IRow row = sheet.CreateRow(<span class="number">0</span>);</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < data.Columns.Count; ++j)</span><br><span class="line"> {</span><br><span class="line"> row.CreateCell(j).SetCellValue(data.Columns[j].ColumnName);</span><br><span class="line"> }</span><br><span class="line"> count = <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < data.Rows.Count; ++i)</span><br><span class="line"> {</span><br><span class="line"> IRow row = sheet.CreateRow(count);</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < data.Columns.Count; ++j)</span><br><span class="line"> {</span><br><span class="line"> row.CreateCell(j).SetCellValue(data.Rows[i][j].ToString());</span><br><span class="line"> }</span><br><span class="line"> count++;</span><br><span class="line"> }</span><br><span class="line"> workbook.Write(fs); <span class="comment">//写入到excel</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> count;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">catch</span> (Exception ex)</span><br><span class="line"> {</span><br><span class="line"> Console.WriteLine(<span class="string">"Exception: "</span> + ex.Message);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> DataTable <span class="title">BuildDataTable</span>(<span class="params">IRow Row</span>)</span></span><br><span class="line"> {</span><br><span class="line"> DataTable result = <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">if</span> (Row.Cells.Count > <span class="number">0</span>)</span><br><span class="line"> {</span><br><span class="line"> result = <span class="keyword">new</span> DataTable();</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < Row.LastCellNum; i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (Row.GetCell(i) != <span class="literal">null</span>)</span><br><span class="line"> {</span><br><span class="line"> result.Columns.Add(Row.GetCell(i).ToString());</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> result;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 获取单元格类型</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="cell"></span><span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><returns></span><span class="doctag"></returns></span></span></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="built_in">object</span> <span class="title">GetValueType</span>(<span class="params">ICell cell</span>)</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (cell == <span class="literal">null</span>)</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">switch</span> (cell.CellType)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">case</span> CellType.Blank: <span class="comment">//BLANK: </span></span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">case</span> CellType.Boolean: <span class="comment">//BOOLEAN: </span></span><br><span class="line"> <span class="keyword">return</span> cell.BooleanCellValue;</span><br><span class="line"> <span class="keyword">case</span> CellType.Numeric: <span class="comment">//NUMERIC: </span></span><br><span class="line"> <span class="keyword">if</span> (DateUtil.IsCellDateFormatted(cell))</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">return</span> cell.DateCellValue;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> cell.NumericCellValue;</span><br><span class="line"> <span class="keyword">case</span> CellType.String: <span class="comment">//STRING: </span></span><br><span class="line"> <span class="keyword">return</span> cell.StringCellValue;</span><br><span class="line"> <span class="keyword">case</span> CellType.Error: <span class="comment">//ERROR: </span></span><br><span class="line"> <span class="keyword">return</span> cell.ErrorCellValue;</span><br><span class="line"> <span class="keyword">case</span> CellType.Formula: <span class="comment">//FORMULA: </span></span><br><span class="line"> cell.SetCellType(CellType.String);</span><br><span class="line"> <span class="keyword">return</span> cell.StringCellValue;</span><br><span class="line"> <span class="literal">default</span>:</span><br><span class="line"> <span class="keyword">return</span> <span class="string">"="</span> + cell.CellFormula;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="多张表处理方案"><a href="#多张表处理方案" class="headerlink" title="多张表处理方案"></a>多张表处理方案</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> NPOI.HSSF.UserModel;</span><br><span class="line"><span class="keyword">using</span> NPOI.SS.UserModel;</span><br><span class="line"><span class="keyword">using</span> NPOI.XSSF.UserModel;</span><br><span class="line"><span class="keyword">using</span> System.Data;</span><br><span class="line"><span class="keyword">using</span> System.IO;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> <span class="title">Vol_Changer_ShortCircuit.Operate</span></span><br><span class="line">{</span><br><span class="line"> <span class="keyword">class</span> <span class="title">ExcelHelper</span></span><br><span class="line"> {</span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 从Excel读取数据,支持多表</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="FilePath"></span>文件路径<span class="doctag"></param></span></span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> DataSet <span class="title">ReadFromExcels</span>(<span class="params"><span class="built_in">string</span> FilePath</span>)</span></span><br><span class="line"> {</span><br><span class="line"> DataSet ds = <span class="keyword">new</span> DataSet();</span><br><span class="line"> IWorkbook wk = <span class="literal">null</span>;</span><br><span class="line"> <span class="built_in">string</span> extension = Path.GetExtension(FilePath); <span class="comment">//获取扩展名</span></span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">using</span> (FileStream fs = File.OpenRead(FilePath))</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (extension.Equals(<span class="string">".xls"</span>)) <span class="comment">//2003</span></span><br><span class="line"> {</span><br><span class="line"> wk = <span class="keyword">new</span> HSSFWorkbook(fs);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="comment">//2007以上</span></span><br><span class="line"> {</span><br><span class="line"> wk = <span class="keyword">new</span> XSSFWorkbook(fs);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="built_in">int</span> SheetCount = wk.NumberOfSheets;<span class="comment">//获取表的数量</span></span><br><span class="line"> <span class="keyword">if</span> (SheetCount < <span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">return</span> ds;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> s = <span class="number">0</span>; s < SheetCount; s++)</span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//读取当前表数据</span></span><br><span class="line"> ISheet sheet = wk.GetSheetAt(s);</span><br><span class="line"> <span class="comment">//构建DataTable</span></span><br><span class="line"> IRow row = sheet.GetRow(<span class="number">0</span>);</span><br><span class="line"> <span class="keyword">if</span> (row == <span class="literal">null</span>) { <span class="keyword">continue</span>; }</span><br><span class="line"> DataTable tempDT = BuildDataTable(row);</span><br><span class="line"> tempDT.TableName = wk.GetSheetName(s);</span><br><span class="line"> <span class="keyword">if</span> (tempDT != <span class="literal">null</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (sheet.LastRowNum >= <span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">1</span>; i < sheet.LastRowNum + <span class="number">1</span>; i++)</span><br><span class="line"> {</span><br><span class="line"> IRow temp_row = sheet.GetRow(i);</span><br><span class="line"> <span class="keyword">if</span> (temp_row == <span class="literal">null</span>) { <span class="keyword">continue</span>; }<span class="comment">// 修复 行为空时会出错</span></span><br><span class="line"> List<<span class="built_in">object</span>> itemArray = <span class="keyword">new</span> List<<span class="built_in">object</span>>();</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < tempDT.Columns.Count; j++)<span class="comment">//解决Excel超出DataTable列问题 </span></span><br><span class="line"> {</span><br><span class="line"> itemArray.Add(GetValueType(temp_row.GetCell(j)));<span class="comment">//解决 导入Excel 时间格式问题 </span></span><br><span class="line"> }</span><br><span class="line"> tempDT.Rows.Add(itemArray.ToArray());</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> ds.Tables.Add(tempDT);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> ds;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">catch</span> (Exception ex)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 将DataSet数据导入到excel中 每个datatable一个sheet,sheet名为datatable名</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="ds"></span>要导入的数据<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="isColumnWritten"></span>DataTable的列名是否要导入<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="fileName"></span>导出的文件途径<span class="doctag"></param></span></span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="built_in">bool</span> <span class="title">DataTableToExcel</span>(<span class="params">DataSet ds, <span class="built_in">string</span> fileName, <span class="built_in">bool</span> isColumnWritten = <span class="literal">true</span></span>)</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (ds == <span class="literal">null</span> || ds.Tables.Count < <span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line"> IWorkbook workbook = <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">using</span> (FileStream fs = <span class="keyword">new</span> FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (fileName.IndexOf(<span class="string">".xlsx"</span>) > <span class="number">0</span>) <span class="comment">// 2007版本</span></span><br><span class="line"> {</span><br><span class="line"> workbook = <span class="keyword">new</span> XSSFWorkbook();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (fileName.IndexOf(<span class="string">".xls"</span>) > <span class="number">0</span>) <span class="comment">// 2003版本</span></span><br><span class="line"> {</span><br><span class="line"> workbook = <span class="keyword">new</span> HSSFWorkbook();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (workbook == <span class="literal">null</span>) { <span class="keyword">return</span> <span class="literal">false</span>; }</span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">foreach</span> (DataTable dt <span class="keyword">in</span> ds.Tables)</span><br><span class="line"> {</span><br><span class="line"> ISheet sheet = workbook.CreateSheet(dt.TableName);</span><br><span class="line"> <span class="keyword">if</span> (isColumnWritten) <span class="comment">//写入DataTable的列名</span></span><br><span class="line"> {</span><br><span class="line"> IRow row = sheet.CreateRow(<span class="number">0</span>);</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < dt.Columns.Count; ++j)</span><br><span class="line"> {</span><br><span class="line"> row.CreateCell(j).SetCellValue(dt.Columns[j].ColumnName);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < dt.Rows.Count; ++i)</span><br><span class="line"> {</span><br><span class="line"> IRow row = sheet.CreateRow(isColumnWritten ? i + <span class="number">1</span> : i);</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < dt.Columns.Count; ++j)</span><br><span class="line"> {</span><br><span class="line"> row.CreateCell(j).SetCellValue(dt.Rows[i][j].ToString());</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> workbook.Write(fs); <span class="comment">//写入到excel</span></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">catch</span> (Exception ex)</span><br><span class="line"> {</span><br><span class="line"> Console.WriteLine(<span class="string">"Exception: "</span> + ex.Message);</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> DataTable <span class="title">BuildDataTable</span>(<span class="params">IRow Row</span>)</span></span><br><span class="line"> {</span><br><span class="line"> DataTable result = <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">if</span> (Row.Cells.Count > <span class="number">0</span>)</span><br><span class="line"> {</span><br><span class="line"> result = <span class="keyword">new</span> DataTable();</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < Row.LastCellNum; i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (Row.GetCell(i) != <span class="literal">null</span>)</span><br><span class="line"> {</span><br><span class="line"> result.Columns.Add(Row.GetCell(i).ToString());</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> result;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="获取单元格类型"><a href="#获取单元格类型" class="headerlink" title="获取单元格类型"></a>获取单元格类型</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 获取单元格类型</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="cell"></span><span class="doctag"></param></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><returns></span><span class="doctag"></returns></span></span></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="built_in">object</span> <span class="title">GetValueType</span>(<span class="params">ICell cell</span>)</span></span><br><span class="line">{</span><br><span class="line"> <span class="keyword">if</span> (cell == <span class="literal">null</span>)</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">switch</span> (cell.CellType)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">case</span> CellType.Blank: <span class="comment">//BLANK: </span></span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">case</span> CellType.Boolean: <span class="comment">//BOOLEAN: </span></span><br><span class="line"> <span class="keyword">return</span> cell.BooleanCellValue;</span><br><span class="line"> <span class="keyword">case</span> CellType.Numeric: <span class="comment">//NUMERIC: </span></span><br><span class="line"> <span class="keyword">if</span> (DateUtil.IsCellDateFormatted(cell))</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">return</span> cell.DateCellValue;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> cell.NumericCellValue;</span><br><span class="line"> <span class="keyword">case</span> CellType.String: <span class="comment">//STRING: </span></span><br><span class="line"> <span class="keyword">return</span> cell.StringCellValue;</span><br><span class="line"> <span class="keyword">case</span> CellType.Error: <span class="comment">//ERROR: </span></span><br><span class="line"> <span class="keyword">return</span> cell.ErrorCellValue;</span><br><span class="line"> <span class="keyword">case</span> CellType.Formula: <span class="comment">//FORMULA: </span></span><br><span class="line"> cell.SetCellType(CellType.String);</span><br><span class="line"> <span class="keyword">return</span> cell.StringCellValue;</span><br><span class="line"> <span class="literal">default</span>:</span><br><span class="line"> <span class="keyword">return</span> <span class="string">"="</span> + cell.CellFormula;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="NPOI读写数据、设置单元格样式"><a href="#NPOI读写数据、设置单元格样式" class="headerlink" title="NPOI读写数据、设置单元格样式"></a>NPOI读写数据、设置单元格样式</h4><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 将DataTable数据导入到excel中</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="data"></span>要导入的数据<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="isColumnWritten"></span>DataTable的列名是否要导入<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="sheetName"></span>要导入的excel的sheet的名称<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="fileName"></span>导出的文件途径<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><returns></span>导入数据行数(包含列名那一行)<span class="doctag"></returns></span></span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="built_in">int</span> <span class="title">DataTableToExcel</span>(<span class="params">DataTable data, <span class="built_in">string</span> sheetName, <span class="built_in">string</span> fileName, <span class="built_in">bool</span> isColumnWritten = <span class="literal">true</span></span>)</span></span><br><span class="line"> {</span><br><span class="line"> IWorkbook workbook = <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">using</span> (FileStream fs = <span class="keyword">new</span> FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (fileName.IndexOf(<span class="string">".xlsx"</span>) > <span class="number">0</span>) <span class="comment">// 2007版本</span></span><br><span class="line"> {</span><br><span class="line"> workbook = <span class="keyword">new</span> XSSFWorkbook();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (fileName.IndexOf(<span class="string">".xls"</span>) > <span class="number">0</span>) <span class="comment">// 2003版本</span></span><br><span class="line"> {</span><br><span class="line"> workbook = <span class="keyword">new</span> HSSFWorkbook();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (workbook == <span class="literal">null</span>) { <span class="keyword">return</span> <span class="number">-1</span>; }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> {</span><br><span class="line"> ISheet sheet = workbook.CreateSheet(sheetName);</span><br><span class="line"></span><br><span class="line"> <span class="built_in">int</span> count = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">if</span> (isColumnWritten) <span class="comment">//写入DataTable的列名</span></span><br><span class="line"> {</span><br><span class="line"> IRow row = sheet.CreateRow(<span class="number">0</span>);</span><br><span class="line"> ICellStyle columnStyle = workbook.CreateCellStyle();</span><br><span class="line"> <span class="comment">//设置边框</span></span><br><span class="line"> columnStyle.BorderTop = BorderStyle.Thin;</span><br><span class="line"> columnStyle.BorderBottom = BorderStyle.Thin;</span><br><span class="line"> columnStyle.BorderLeft = BorderStyle.Thin;</span><br><span class="line"> columnStyle.BorderRight = BorderStyle.Thin;</span><br><span class="line"> <span class="comment">//设置居中</span></span><br><span class="line"> columnStyle.Alignment = HorizontalAlignment.Center;</span><br><span class="line"> columnStyle.VerticalAlignment = VerticalAlignment.Center;</span><br><span class="line"> <span class="comment">//设置字体样式和单元格背景</span></span><br><span class="line"> columnStyle.FillPattern = FillPattern.SolidForeground;</span><br><span class="line"> columnStyle.FillForegroundColor = <span class="number">40</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < data.Columns.Count; ++j)</span><br><span class="line"> {</span><br><span class="line"> row.CreateCell(j).SetCellValue(data.Columns[j].ColumnName);</span><br><span class="line"> ICell cell = row.GetCell(j);</span><br><span class="line"> cell.CellStyle = columnStyle;</span><br><span class="line"> <span class="comment">//设置列宽</span></span><br><span class="line"> sheet.SetColumnWidth(j, <span class="number">20</span> * <span class="number">256</span>);</span><br><span class="line"> }</span><br><span class="line"> count = <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < data.Rows.Count; ++i)</span><br><span class="line"> {</span><br><span class="line"> IRow row = sheet.CreateRow(count);</span><br><span class="line"> ICellStyle cellStyle = workbook.CreateCellStyle();</span><br><span class="line"> cellStyle.BorderBottom = BorderStyle.Thin;</span><br><span class="line"> cellStyle.BorderLeft = BorderStyle.Thin;</span><br><span class="line"> cellStyle.BorderRight = BorderStyle.Thin;</span><br><span class="line"> cellStyle.BorderTop = BorderStyle.Thin;</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < data.Columns.Count; ++j)</span><br><span class="line"> {</span><br><span class="line"> row.CreateCell(j).SetCellValue(data.Rows[i][j].ToString());</span><br><span class="line"> ICell cell = row.GetCell(j);</span><br><span class="line"> cell.CellStyle = cellStyle;</span><br><span class="line"> }</span><br><span class="line"> count++;</span><br><span class="line"> }</span><br><span class="line"> workbook.Write(fs); <span class="comment">//写入到excel</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> count;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">catch</span> (Exception ex)</span><br><span class="line"> {</span><br><span class="line"> MessageBoxInfor.ShowMessageBox(<span class="string">"Exception:"</span> + ex.Message);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h3 id="C-IO-文件Copy"><a href="#C-IO-文件Copy" class="headerlink" title="C#-IO-文件Copy"></a>C#-IO-文件Copy</h3><h4 id="Copy"><a href="#Copy" class="headerlink" title="Copy()"></a>Copy()</h4><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">string</span> sourceFile = <span class="string">@"c:\temp\New Text Document.txt"</span>; </span><br><span class="line"><span class="built_in">string</span> destinationFile = <span class="string">@"c:\temp\test.txt"</span>; </span><br><span class="line"><span class="built_in">bool</span> isrewrite=<span class="literal">true</span>; <span class="comment">// true=覆盖已存在的同名文件,false则反之</span></span><br><span class="line">System.IO.File.Copy(sourcePath, targetPath, isrewrite); </span><br></pre></td></tr></table></figure><h4 id="CopyTo"><a href="#CopyTo" class="headerlink" title="CopyTo()"></a>CopyTo()</h4><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">string</span> sourceFile = <span class="string">@"c:\temp\New Text Document.txt"</span>; </span><br><span class="line"><span class="built_in">string</span> destinationFile = <span class="string">@"c:\temp\test.txt"</span>; </span><br><span class="line">FileInfo file = <span class="keyword">new</span> FileInfo(sourceFile); </span><br><span class="line"><span class="keyword">if</span> (file.Exists) </span><br><span class="line">{ </span><br><span class="line"> <span class="comment">// true is overwrite </span></span><br><span class="line"> file.CopyTo(destinationFile, <span class="literal">true</span>); </span><br><span class="line">} </span><br></pre></td></tr></table></figure><h4 id="文件流实现Copy"><a href="#文件流实现Copy" class="headerlink" title="文件流实现Copy"></a>文件流实现Copy</h4><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">region</span> 拷贝操作</span></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">button3_Click</span>(<span class="params"><span class="built_in">object</span> sender, EventArgs e</span>)</span></span><br><span class="line">{</span><br><span class="line"> OpenFileDialog ofd = <span class="keyword">new</span> OpenFileDialog();</span><br><span class="line"> DialogResult res = ofd.ShowDialog();</span><br><span class="line"> <span class="keyword">if</span> (res == DialogResult.OK) </span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (!<span class="built_in">string</span>.IsNullOrEmpty(ofd.FileName))</span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//1.创建读入文件流对象</span></span><br><span class="line"> FileStream streamRead = <span class="keyword">new</span> FileStream(ofd.FileName, FileMode.Open);</span><br><span class="line"> <span class="comment">//2.创建1个字节数组,用于接收文件流对象读操作文件值</span></span><br><span class="line"> <span class="built_in">byte</span>[] data = <span class="keyword">new</span> <span class="built_in">byte</span>[<span class="number">1024</span> * <span class="number">1024</span>];<span class="comment">//1M</span></span><br><span class="line"> <span class="built_in">int</span> length = <span class="number">0</span>;</span><br><span class="line"> SaveFileDialog sfd = <span class="keyword">new</span> SaveFileDialog();</span><br><span class="line"> DialogResult sres = sfd.ShowDialog();</span><br><span class="line"> <span class="keyword">if</span> (sres == DialogResult.OK)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (!<span class="built_in">string</span>.IsNullOrEmpty(ofd.FileName))</span><br><span class="line"> {</span><br><span class="line"> FileStream streamWrite = <span class="keyword">new</span> FileStream(sfd.FileName, FileMode.Create);</span><br><span class="line"> <span class="keyword">do</span></span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//3.文件流读方法的参数1.data-文件流读出数据要存的地方,2. 0--从什么位置读,3. data.Length--1次读多少字节数据</span></span><br><span class="line"> <span class="comment">//3.1 Read方法的返回值是一个int类型的,代表他真实读取 字节数据的长度,</span></span><br><span class="line"> length = streamRead.Read(data, <span class="number">0</span>, data.Length);<span class="comment">//大文件读入时候,我们定义字节长度的可能会有限,如果文件超大,要接收文件流对象的Read()方法,会返回读入的实际长度</span></span><br><span class="line"> <span class="comment">//加密 和解密</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < length; i++) </span><br><span class="line"> {</span><br><span class="line"> data[i] = (<span class="built_in">byte</span>)(<span class="number">255</span> - data[i]);</span><br><span class="line"> }</span><br><span class="line"> streamWrite.Write(data, <span class="number">0</span>, length);</span><br><span class="line"> } <span class="keyword">while</span> (length == data.Length); <span class="comment">//如果实际写入长度等于我们设定的长度,有两种情况1.文件正好是我们设定的长度2.文件超大只上传了截取的一部分</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="meta">#<span class="keyword">endregion</span> </span></span><br></pre></td></tr></table></figure><h3 id="C-NPOI实现Excel文件复制"><a href="#C-NPOI实现Excel文件复制" class="headerlink" title="C#NPOI实现Excel文件复制"></a>C#NPOI实现Excel文件复制</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//需要读取的源文件</span></span><br><span class="line"><span class="built_in">string</span> filepath = <span class="string">@"C:\Users\Administrator\Desktop\测试.xlsx"</span>;</span><br><span class="line">FileStream fs = <span class="keyword">new</span> FileStream(filepath,FileMode.Open,FileAccess.Read);</span><br><span class="line">IWorkbook wb = <span class="keyword">new</span> XSSFWorkbook(fs);</span><br><span class="line">fs.Close();</span><br><span class="line"><span class="comment">//创建新的文件</span></span><br><span class="line"><span class="built_in">string</span> outFilePath = <span class="string">@"C:\Users\Administrator\Desktop\输出测试.xlsx"</span>; </span><br><span class="line">FileStream outFs = <span class="keyword">new</span> FileStream(outFilePath,FileMode.Create,FileAccess.Write);</span><br><span class="line">wb.Write(outFs); </span><br><span class="line">outFs.Close();</span><br><span class="line">wb.Close();</span><br><span class="line"></span><br></pre></td></tr></table></figure><h4 id="复制模板问价并写入内容"><a href="#复制模板问价并写入内容" class="headerlink" title="复制模板问价并写入内容"></a>复制模板问价并写入内容</h4><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//报告生成</span></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">uiSyCreateExcel_Click</span>(<span class="params"><span class="built_in">object</span> sender, EventArgs e</span>)</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> {</span><br><span class="line"> FolderBrowserDialog folder = <span class="keyword">new</span> FolderBrowserDialog();</span><br><span class="line"> <span class="keyword">if</span> (folder.ShowDialog() == DialogResult.OK)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">string</span> ExportDir = folder.SelectedPath + <span class="string">"\\数据导出"</span> + DateTime.Now.ToString(<span class="string">"yyyyMMddHHmmss"</span>) + <span class="string">".xlsx"</span>;</span><br><span class="line"> <span class="comment">//需要读取的源文件</span></span><br><span class="line"> <span class="built_in">string</span> filepath = <span class="string">@"DataBase\Report.xlsx"</span>;</span><br><span class="line"> FileStream fs = <span class="keyword">new</span> FileStream(filepath, FileMode.Open, FileAccess.Read);</span><br><span class="line"> IWorkbook wb = <span class="keyword">new</span> XSSFWorkbook(fs);</span><br><span class="line"> fs.Close();</span><br><span class="line"> <span class="comment">//创建新的文件</span></span><br><span class="line"> FileStream outFs = <span class="keyword">new</span> FileStream(ExportDir, FileMode.Create, FileAccess.Write);</span><br><span class="line"> wb.Write(outFs);</span><br><span class="line"> outFs.Close();</span><br><span class="line"> wb.Close();</span><br><span class="line"> <span class="comment">//写入文件</span></span><br><span class="line"> <span class="built_in">bool</span> WriteSymbol = ExcelHelper.WriteDataTableToExcel(dt, ExportDir, <span class="literal">false</span>,dt.Rows.Count);</span><br><span class="line"> <span class="keyword">if</span> (WriteSymbol==<span class="literal">true</span>)</span><br><span class="line"> {</span><br><span class="line"> MessageBox.Show(<span class="string">"导出成功,文件存储在"</span> + ExportDir + <span class="string">"。"</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> {</span><br><span class="line"> MessageBox.Show(<span class="string">"导出失败,请检查导出文件是否处于打开状态或查看日志文件"</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">catch</span> (Exception ex)</span><br><span class="line"> {</span><br><span class="line"> FileOperate.WriteLog(ex);</span><br><span class="line"> }</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h3 id="输出带列名的DataTable数据表并调整Excel内容格式"><a href="#输出带列名的DataTable数据表并调整Excel内容格式" class="headerlink" title="输出带列名的DataTable数据表并调整Excel内容格式"></a>输出带列名的DataTable数据表并调整Excel内容格式</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 将DataTable数据导入到excel中</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="data"></span>要导入的数据<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="isColumnWritten"></span>DataTable的列名是否要导入<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="sheetName"></span>要导入的excel的sheet的名称<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="fileName"></span>导出的文件途径<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><returns></span>导入数据行数(包含列名那一行)<span class="doctag"></returns></span></span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="built_in">int</span> <span class="title">DataTableToExcel</span>(<span class="params">DataTable data, <span class="built_in">string</span> sheetName, <span class="built_in">string</span> fileName, <span class="built_in">bool</span> isColumnWritten = <span class="literal">true</span></span>)</span></span><br><span class="line"> {</span><br><span class="line"> IWorkbook workbook = <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">using</span> (FileStream fs = <span class="keyword">new</span> FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (fileName.IndexOf(<span class="string">".xlsx"</span>) > <span class="number">0</span>) <span class="comment">// 2007版本</span></span><br><span class="line"> {</span><br><span class="line"> workbook = <span class="keyword">new</span> XSSFWorkbook();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (fileName.IndexOf(<span class="string">".xls"</span>) > <span class="number">0</span>) <span class="comment">// 2003版本</span></span><br><span class="line"> {</span><br><span class="line"> workbook = <span class="keyword">new</span> HSSFWorkbook();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (workbook == <span class="literal">null</span>) { <span class="keyword">return</span> <span class="number">-1</span>; }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> {</span><br><span class="line"> ISheet sheet = workbook.CreateSheet(sheetName);</span><br><span class="line"></span><br><span class="line"> <span class="built_in">int</span> count = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">if</span> (isColumnWritten) <span class="comment">//写入DataTable的列名</span></span><br><span class="line"> {</span><br><span class="line"> IRow row = sheet.CreateRow(<span class="number">0</span>);</span><br><span class="line"> ICellStyle columnStyle = workbook.CreateCellStyle();</span><br><span class="line"> <span class="comment">//设置边框</span></span><br><span class="line"> columnStyle.BorderTop = BorderStyle.Thin;</span><br><span class="line"> columnStyle.BorderBottom = BorderStyle.Thin;</span><br><span class="line"> columnStyle.BorderLeft = BorderStyle.Thin;</span><br><span class="line"> columnStyle.BorderRight = BorderStyle.Thin;</span><br><span class="line"> <span class="comment">//设置居中</span></span><br><span class="line"> columnStyle.Alignment = HorizontalAlignment.Center;</span><br><span class="line"> columnStyle.VerticalAlignment = VerticalAlignment.Center;</span><br><span class="line"> <span class="comment">//设置字体样式和单元格背景</span></span><br><span class="line"> columnStyle.FillPattern = FillPattern.SolidForeground;</span><br><span class="line"> columnStyle.FillForegroundColor = <span class="number">40</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < data.Columns.Count; ++j)</span><br><span class="line"> {</span><br><span class="line"> row.CreateCell(j).SetCellValue(data.Columns[j].ColumnName);</span><br><span class="line"> ICell cell = row.GetCell(j);</span><br><span class="line"> cell.CellStyle = columnStyle;</span><br><span class="line"> <span class="comment">//设置列宽</span></span><br><span class="line"> sheet.SetColumnWidth(j, <span class="number">20</span> * <span class="number">256</span>);</span><br><span class="line"> }</span><br><span class="line"> count = <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < data.Rows.Count; ++i)</span><br><span class="line"> {</span><br><span class="line"> IRow row = sheet.CreateRow(count);</span><br><span class="line"> ICellStyle cellStyle = workbook.CreateCellStyle();</span><br><span class="line"> cellStyle.BorderBottom = BorderStyle.Thin;</span><br><span class="line"> cellStyle.BorderLeft = BorderStyle.Thin;</span><br><span class="line"> cellStyle.BorderRight = BorderStyle.Thin;</span><br><span class="line"> cellStyle.BorderTop = BorderStyle.Thin;</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < data.Columns.Count; ++j)</span><br><span class="line"> {</span><br><span class="line"> row.CreateCell(j).SetCellValue(data.Rows[i][j].ToString());</span><br><span class="line"> ICell cell = row.GetCell(j);</span><br><span class="line"> cell.CellStyle = cellStyle;</span><br><span class="line"> }</span><br><span class="line"> count++;</span><br><span class="line"> }</span><br><span class="line"> workbook.Write(fs); <span class="comment">//写入到excel</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> count;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">catch</span> (Exception ex)</span><br><span class="line"> {</span><br><span class="line"> MessageBoxInfor.ShowMessageBox(<span class="string">"Exception:"</span> + ex.Message);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h3 id="Excel单元格中写入图片"><a href="#Excel单元格中写入图片" class="headerlink" title="Excel单元格中写入图片"></a>Excel单元格中写入图片</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">ExcelHelper</span>()</span></span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">string</span> ExportPath = <span class="string">"D:\\QuickTest\\test.xlsx"</span>;</span><br><span class="line"> IWorkbook workbook = <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">using</span> (FileStream fs = <span class="keyword">new</span> FileStream(ExportPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))</span><br><span class="line"> {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (ExportPath.IndexOf(<span class="string">".xlsx"</span>) > <span class="number">0</span>) <span class="comment">// 2007版本</span></span><br><span class="line"> {</span><br><span class="line"> workbook = <span class="keyword">new</span> XSSFWorkbook();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (ExportPath.IndexOf(<span class="string">".xls"</span>) > <span class="number">0</span>) <span class="comment">// 2003版本</span></span><br><span class="line"> {</span><br><span class="line"> workbook = <span class="keyword">new</span> HSSFWorkbook();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (workbook == <span class="literal">null</span>) { <span class="keyword">return</span>; }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> {</span><br><span class="line"> ISheet sheet = workbook.CreateSheet(<span class="string">"PictureTest"</span>);<span class="comment">//创建一个Sheet</span></span><br><span class="line"> sheet.SetColumnWidth(<span class="number">0</span>, <span class="number">18</span> * <span class="number">256</span>);<span class="comment">//设置列宽</span></span><br><span class="line"> sheet.SetColumnWidth(<span class="number">1</span>, <span class="number">18</span> * <span class="number">256</span>);</span><br><span class="line"> IRow rowHeader = sheet.CreateRow(<span class="number">0</span>);<span class="comment">//创建表头行</span></span><br><span class="line"> rowHeader.CreateCell(<span class="number">0</span>, CellType.String).SetCellValue(<span class="string">"测试表头_1"</span>);</span><br><span class="line"> rowHeader.CreateCell(<span class="number">1</span>, CellType.String).SetCellValue(<span class="string">"测试表头_2"</span>);</span><br><span class="line"> IRow rowFirstRow = sheet.CreateRow(<span class="number">1</span>);<span class="comment">//创建内容第一行</span></span><br><span class="line"> rowFirstRow.Height = <span class="number">80</span> * <span class="number">40</span>;<span class="comment">//设置行高</span></span><br><span class="line"> rowFirstRow.CreateCell(<span class="number">0</span>, CellType.String).SetCellValue(<span class="string">"测试内容"</span>);</span><br><span class="line"> <span class="comment">//将图片文件读入一个字符串</span></span><br><span class="line"> <span class="built_in">byte</span>[] picByte = File.ReadAllBytes(<span class="string">"D:\\BoiledYakult\\01壁纸图片\\backiee-246720.jpg"</span>);</span><br><span class="line"> <span class="built_in">int</span> PictureIndex = workbook.AddPicture(picByte, PictureType.JPEG);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (ExportPath.IndexOf(<span class="string">".xlsx"</span>) > <span class="number">0</span>) <span class="comment">// 2007版本</span></span><br><span class="line"> {</span><br><span class="line"> IDrawing drawing = sheet.CreateDrawingPatriarch();</span><br><span class="line"> IClientAnchor anchor = drawing.CreateAnchor(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>);</span><br><span class="line"> IPicture pict = drawing.CreatePicture(anchor, PictureIndex);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (ExportPath.IndexOf(<span class="string">".xls"</span>) > <span class="number">0</span>) <span class="comment">// 2003版本</span></span><br><span class="line"> {</span><br><span class="line"> HSSFPatriarch hSSFShapes = (HSSFPatriarch)sheet.CreateDrawingPatriarch();</span><br><span class="line"> HSSFClientAnchor anchor = <span class="keyword">new</span> HSSFClientAnchor(<span class="number">70</span>, <span class="number">10</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>);<span class="comment">//插入图片位置</span></span><br><span class="line"> HSSFPicture picture = (HSSFPicture)hSSFShapes.CreatePicture(anchor, PictureIndex);</span><br><span class="line"> }</span><br><span class="line"> workbook.Write(fs);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">catch</span> (Exception ex)</span><br><span class="line"> {</span><br><span class="line"> MessageBox.Show(ex.ToString());</span><br><span class="line"> <span class="keyword">throw</span> ex;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><blockquote><p>C#将文件读取字符串</p></blockquote>]]></content>
<categories>
<category> EXCEL文件处理 </category>
<category> C# </category>
</categories>
<tags>
<tag> DataTable </tag>
<tag> EXCEL文件操作 </tag>
</tags>
</entry>
<entry>
<title>DataTable用法总结以及DataGridview相关内容</title>
<link href="/archives/dbaa473.html"/>
<url>/archives/dbaa473.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h2 id="DataTable用法总结"><a href="#DataTable用法总结" class="headerlink" title="DataTable用法总结"></a>DataTable用法总结</h2><h3 id="添加引用"><a href="#添加引用" class="headerlink" title="添加引用"></a>添加引用</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//引用命名空间</span></span><br><span class="line"><span class="keyword">using</span> System.Data;</span><br></pre></td></tr></table></figure><h3 id="创建表"><a href="#创建表" class="headerlink" title="创建表"></a>创建表</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//创建一个空表</span></span><br><span class="line">DataTable dt = <span class="keyword">new</span> DataTable();</span><br><span class="line"><span class="comment">//创建一个名为"new-tabel"的空表;</span></span><br><span class="line">DataTable dt = <span class="keyword">new</span> DataTable(<span class="string">"new-tabel"</span>);</span><br></pre></td></tr></table></figure><h3 id="创建列"><a href="#创建列" class="headerlink" title="创建列"></a>创建列</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.创建空列</span></span><br><span class="line">DataColumn dc = <span class="keyword">new</span> DataColumn();</span><br><span class="line"><span class="comment">//将空列加入到dt表中</span></span><br><span class="line">dt.Columns.Add(dc);</span><br><span class="line"><span class="comment">//2.创建带列名和类型名的列(两种方式任选其一)</span></span><br><span class="line">dt.Columns.Add(<span class="string">"column0"</span>, System.Type.GetType(<span class="string">"System.String"</span>));</span><br><span class="line">dt.Columns.Add(<span class="string">"column0"</span>, <span class="keyword">typeof</span>(String));</span><br><span class="line"><span class="comment">//3.通过列架构添加列</span></span><br><span class="line">DataColumn dc = <span class="keyword">new</span> DataColumn(<span class="string">"column1"</span>,System.Type.GetType(<span class="string">"System.DateTime"</span>));</span><br><span class="line">DataColumn dc = <span class="keyword">new</span> DataColumn(<span class="string">"column1"</span>, <span class="keyword">typeof</span>(DateTime));</span><br><span class="line">dt.Columns.Add(dc);</span><br></pre></td></tr></table></figure><h3 id="创建行"><a href="#创建行" class="headerlink" title="创建行"></a>创建行</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.创建空行</span></span><br><span class="line">DataRow dr = dt.NewRow();</span><br><span class="line">dt.Rows.Add(dr);</span><br><span class="line"><span class="comment">//2.创建空行</span></span><br><span class="line">dt.Rows.Add();</span><br><span class="line"><span class="comment">//3.通过行框架创建并赋值</span></span><br><span class="line">dt.Rows.Add(<span class="string">"张三"</span>,DateTime.Now);<span class="comment">//Add里面参数的数据顺序要和dt中的列的顺序对应 </span></span><br><span class="line"><span class="comment">//4.通过复制dt2表的某一行来创建</span></span><br><span class="line">dt.Rows.Add(dt2.Rows[i].ItemArray);</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="取值和赋值"><a href="#取值和赋值" class="headerlink" title="取值和赋值"></a>取值和赋值</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//新建行的赋值</span></span><br><span class="line">DataRow dr = dt.NewRow();</span><br><span class="line">dr[<span class="number">0</span>] = <span class="string">"张三"</span>;<span class="comment">//通过索引赋值</span></span><br><span class="line">dr[<span class="string">"column1"</span>] = DateTime.Now; <span class="comment">//通过名称赋值</span></span><br><span class="line"><span class="comment">//对表已有行进行赋值</span></span><br><span class="line">dt.Rows[<span class="number">0</span>][<span class="number">0</span>] = <span class="string">"张三"</span>; <span class="comment">//通过索引赋值</span></span><br><span class="line">dt.Rows[<span class="number">0</span>][<span class="string">"column1"</span>] = DateTime.Now;<span class="comment">//通过名称赋值</span></span><br><span class="line"><span class="comment">//取值</span></span><br><span class="line"><span class="built_in">string</span> name=dt.Rows[<span class="number">0</span>][<span class="number">0</span>].ToString();</span><br><span class="line"><span class="built_in">string</span> time=dt.Rows[<span class="number">0</span>][<span class="string">"column1"</span>].ToString();</span><br><span class="line">从datatable中取值的时候一般用到的是rows属性。</span><br><span class="line">如遍历某一行的值。</span><br><span class="line"> <span class="keyword">foreach</span>(DataColumn col <span class="keyword">in</span> tbl.Columns) </span><br><span class="line"> Console.WriteLine(row[col]); </span><br><span class="line"> <span class="comment">//row是一个datarow的实例,指特定的一行。</span></span><br><span class="line"> 你也可以这么写可能容易理解</span><br><span class="line"> <span class="keyword">foreach</span>(DataColumn col <span class="keyword">in</span> tbl.Columns) </span><br><span class="line"> Console.WriteLine(tbl.rows.[<span class="number">0</span>][col]); </span><br><span class="line"> 关于datarow</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="筛选行"><a href="#筛选行" class="headerlink" title="筛选行"></a>筛选行</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//选择column1列值为空的行的集合</span></span><br><span class="line">DataRow[] drs = dt.Select(<span class="string">"column1 is null"</span>);</span><br><span class="line"><span class="comment">//选择column0列值为"李四"的行的集合</span></span><br><span class="line">DataRow[] drs = dt.Select(<span class="string">"column0 = '李四'"</span>);</span><br><span class="line"><span class="comment">//筛选column0列值中有"张"的行的集合(模糊查询)</span></span><br><span class="line">DataRow[] drs = dt.Select(<span class="string">"column0 like '张%'"</span>);<span class="comment">//如果的多条件筛选,可以加 and 或 or</span></span><br><span class="line"><span class="comment">//筛选column0列值中有"张"的行的集合并按column1降序排序</span></span><br><span class="line">DataRow[] drs = dt.Select(<span class="string">"column0 like '张%'"</span>, <span class="string">"column1 DESC"</span>);</span><br><span class="line"><span class="comment">//dt.Select() 获取所有行</span></span><br><span class="line">Datarow[] drs=dt.Select();</span><br><span class="line"><span class="comment">//此时drs为dt数据表中所有的行。</span></span><br><span class="line"><span class="comment">//dt.Select(sting) 获取与筛选条件相匹配的行,按照主键顺序(如果没有主键,则按照添加顺序)</span></span><br><span class="line">Datarow[] drs=dt.Select(<span class="string">"A='bbc'"</span>);</span><br><span class="line"><span class="comment">//此时drs为dt数据表中所有列A的值为“”bbc“”的行数。</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="筛选行-1"><a href="#筛选行-1" class="headerlink" title="筛选行"></a>筛选行</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//使用DataTable.Rows.Remove(DataRow)方法</span></span><br><span class="line">dt.Rows.Remove(dt.Rows[<span class="number">0</span>]);</span><br><span class="line"><span class="comment">//使用DataTable.Rows.RemoveAt(index)方法</span></span><br><span class="line">dt.Rows.RemoveAt(<span class="number">0</span>);</span><br><span class="line"><span class="comment">//使用DataRow.Delete()方法</span></span><br><span class="line">dt.Row[<span class="number">0</span>].Delete();</span><br><span class="line">dt.AcceptChanges();</span><br><span class="line"><span class="comment">//-----区别和注意点-----</span></span><br><span class="line"><span class="comment">//Remove()和RemoveAt()方法是直接删除</span></span><br><span class="line"><span class="comment">//Delete()方法只是将该行标记为deleted,但是还存在,还可DataTable.RejectChanges()回滚,使该行取消删除。</span></span><br><span class="line"><span class="comment">//用Rows.Count来获取行数时,还是删除之前的行数,需要使用DataTable.AcceptChanges()方法来提交修改。</span></span><br><span class="line"><span class="comment">//如果要删除DataTable中的多行,应该采用倒序循环DataTable.Rows,而且不能用foreach进行循环删除,因为正序删除时索引会发生变化,程式发生异常,很难预料后果。</span></span><br><span class="line"><span class="keyword">for</span> (<span class="built_in">int</span> i = dt.Rows.Count - <span class="number">1</span>; i >= <span class="number">0</span>; i--)</span><br><span class="line">{</span><br><span class="line"> dt.Rows.RemoveAt(i);</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="复制行"><a href="#复制行" class="headerlink" title="复制行"></a>复制行</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//复制表,同时复制了表结构和表中的数据</span></span><br><span class="line">DataTable dtNew = <span class="keyword">new</span> DataTable();</span><br><span class="line">dtNew = dt.Copy();</span><br><span class="line"><span class="comment">//复制表</span></span><br><span class="line">DataTable dtNew = dt.Copy(); <span class="comment">//复制dt表数据结构</span></span><br><span class="line">dtNew.Clear() <span class="comment">//清空数据</span></span><br><span class="line"><span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < dt.Rows.Count; i++)</span><br><span class="line">{</span><br><span class="line"> <span class="keyword">if</span> (条件语句)</span><br><span class="line"> {</span><br><span class="line"> dtNew.Rows.Add(dt.Rows[i].ItemArray); <span class="comment">//添加数据行</span></span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="comment">//克隆表,只是复制了表结构,不包括数据</span></span><br><span class="line">DataTable dtNew = <span class="keyword">new</span> DataTable();</span><br><span class="line">dtNew = dt.Clone();</span><br><span class="line"><span class="comment">//如果只需要某个表中的某一行</span></span><br><span class="line">DataTable dtNew = <span class="keyword">new</span> DataTable();</span><br><span class="line">dtNew = dt.Copy();</span><br><span class="line">dtNew.Rows.Clear();<span class="comment">//清空表数据</span></span><br><span class="line">dtNew.ImportRow(dt.Rows[<span class="number">0</span>]);<span class="comment">//这是加入的是第一行</span></span><br></pre></td></tr></table></figure><h3 id="DataGridView-只显示-DataTable中的指定列"><a href="#DataGridView-只显示-DataTable中的指定列" class="headerlink" title="DataGridView 只显示 DataTable中的指定列"></a>DataGridView 只显示 DataTable中的指定列</h3><ul><li><p>在DataGridView的属性中Columns属性中添加绑定列,将指定的列属性中的DataPropertyName设置为DataTable中对应的列名。</p></li><li><p>然后将DataGridView的AutoGenerateColumns属性设置为false。</p><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DataGridView1.AutoGenerateColumns = <span class="literal">false</span>;</span><br></pre></td></tr></table></figure></li></ul><h3 id="表排序"><a href="#表排序" class="headerlink" title="表排序"></a>表排序</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">DataTable dt = <span class="keyword">new</span> DataTable();<span class="comment">//创建表</span></span><br><span class="line">dt.Columns.Add(<span class="string">"ID"</span>, <span class="keyword">typeof</span>(Int32));<span class="comment">//添加列</span></span><br><span class="line">dt.Columns.Add(<span class="string">"Name"</span>, <span class="keyword">typeof</span>(String));</span><br><span class="line">dt.Columns.Add(<span class="string">"Age"</span>, <span class="keyword">typeof</span>(Int32));</span><br><span class="line">dt.Rows.Add(<span class="keyword">new</span> <span class="built_in">object</span>[] { <span class="number">1</span>, <span class="string">"张三"</span> ,<span class="number">20</span>});<span class="comment">//添加行</span></span><br><span class="line">dt.Rows.Add(<span class="keyword">new</span> <span class="built_in">object</span>[] { <span class="number">2</span>, <span class="string">"李四"</span> ,<span class="number">25</span>});</span><br><span class="line">dt.Rows.Add(<span class="keyword">new</span> <span class="built_in">object</span>[] { <span class="number">3</span>, <span class="string">"王五"</span> ,<span class="number">30</span>});</span><br><span class="line">DataView dv = dt.DefaultView;<span class="comment">//获取表视图</span></span><br><span class="line">dv.Sort = <span class="string">"ID DESC"</span>;<span class="comment">//按照ID倒序排序</span></span><br><span class="line">dv.ToTable();<span class="comment">//转为表</span></span><br></pre></td></tr></table></figure><h3 id="如果你看完了上面所有内容,请你务必看完下面所有内容"><a href="#如果你看完了上面所有内容,请你务必看完下面所有内容" class="headerlink" title="如果你看完了上面所有内容,请你务必看完下面所有内容"></a>如果你看完了上面所有内容,请你务必看完下面所有内容</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">CreateNewDataRow</span>()</span></span><br><span class="line">{</span><br><span class="line"> <span class="comment">// Use the MakeTable function below to create a new table.</span></span><br><span class="line"> DataTable table;</span><br><span class="line"> table = MakeNamesTable();</span><br><span class="line"> <span class="comment">// Once a table has been created, use the </span></span><br><span class="line"> <span class="comment">// NewRow to create a DataRow.</span></span><br><span class="line"> DataRow row;</span><br><span class="line"> row = table.NewRow();</span><br><span class="line"> <span class="comment">// Then add the new row to the collection.</span></span><br><span class="line"> row[<span class="string">"fName"</span>] = <span class="string">"John"</span>;</span><br><span class="line"> row[<span class="string">"lName"</span>] = <span class="string">"Smith"</span>;</span><br><span class="line"> table.Rows.Add(row);</span><br><span class="line"> <span class="keyword">foreach</span>(DataColumn column <span class="keyword">in</span> table.Columns)</span><br><span class="line"> Console.WriteLine(column.ColumnName);</span><br><span class="line"> dataGrid1.DataSource=table;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">private</span> DataTable <span class="title">MakeNamesTable</span>()</span></span><br><span class="line">{</span><br><span class="line"> <span class="comment">// Create a new DataTable titled 'Names.'</span></span><br><span class="line"> DataTable namesTable = <span class="keyword">new</span> DataTable(<span class="string">"Names"</span>); </span><br><span class="line"> <span class="comment">// Add three column objects to the table.</span></span><br><span class="line"> DataColumn idColumn = <span class="keyword">new</span> DataColumn();</span><br><span class="line"> idColumn.DataType = System.Type.GetType(<span class="string">"System.Int32"</span>);</span><br><span class="line"> idColumn.ColumnName = <span class="string">"id"</span>;</span><br><span class="line"> idColumn.AutoIncrement = <span class="literal">true</span>;</span><br><span class="line"> namesTable.Columns.Add(idColumn);</span><br><span class="line"> DataColumn fNameColumn = <span class="keyword">new</span> DataColumn();</span><br><span class="line"> fNameColumn.DataType = System.Type.GetType(<span class="string">"System.String"</span>);</span><br><span class="line"> fNameColumn.ColumnName = <span class="string">"Fname"</span>;</span><br><span class="line"> fNameColumn.DefaultValue = <span class="string">"Fname"</span>;</span><br><span class="line"> namesTable.Columns.Add(fNameColumn);</span><br><span class="line"> DataColumn lNameColumn = <span class="keyword">new</span> DataColumn();</span><br><span class="line"> lNameColumn.DataType = System.Type.GetType(<span class="string">"System.String"</span>);</span><br><span class="line"> lNameColumn.ColumnName = <span class="string">"LName"</span>;</span><br><span class="line"> namesTable.Columns.Add(lNameColumn);</span><br><span class="line"> <span class="comment">// Create an array for DataColumn objects.</span></span><br><span class="line"> DataColumn [] keys = <span class="keyword">new</span> DataColumn [<span class="number">1</span>];</span><br><span class="line"> keys[<span class="number">0</span>] = idColumn;</span><br><span class="line"> namesTable.PrimaryKey = keys;</span><br><span class="line"> <span class="comment">// Return the new DataTable.</span></span><br><span class="line"> <span class="keyword">return</span> namesTable;</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">DemonstrateAcceptChanges</span>()</span></span><br><span class="line">{</span><br><span class="line"> <span class="comment">//Run a function to create a DataTable with one column.</span></span><br><span class="line"> DataTable table = MakeTable();</span><br><span class="line"> DataRow row;</span><br><span class="line"> <span class="comment">// Create a new DataRow.</span></span><br><span class="line"> row = table.NewRow();</span><br><span class="line"> <span class="comment">// Detached row.</span></span><br><span class="line"> Console.WriteLine(<span class="string">"New Row "</span> + row.RowState);</span><br><span class="line"> table.Rows.Add(row);</span><br><span class="line"> <span class="comment">// New row.</span></span><br><span class="line"> Console.WriteLine(<span class="string">"AddRow "</span> + row.RowState);</span><br><span class="line"> table.AcceptChanges();</span><br><span class="line"> <span class="comment">// Unchanged row.</span></span><br><span class="line"> Console.WriteLine(<span class="string">"AcceptChanges "</span> + row.RowState);</span><br><span class="line"> row[<span class="string">"FirstName"</span>] = <span class="string">"Scott"</span>;</span><br><span class="line"> <span class="comment">// Modified row.</span></span><br><span class="line"> Console.WriteLine(<span class="string">"Modified "</span> + row.RowState);</span><br><span class="line"> row.Delete();</span><br><span class="line"> <span class="comment">// Deleted row.</span></span><br><span class="line"> Console.WriteLine(<span class="string">"Deleted "</span> + row.RowState);</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">private</span> DataTable <span class="title">MakeTable</span>()</span></span><br><span class="line">{</span><br><span class="line"> <span class="comment">// Make a simple table with one column.</span></span><br><span class="line"> DataTable table = <span class="keyword">new</span> DataTable(<span class="string">"table"</span>);</span><br><span class="line"> DataColumn fnameColumn = <span class="keyword">new</span> DataColumn(</span><br><span class="line"> <span class="string">"FirstName"</span>, Type.GetType(<span class="string">"System.String"</span>));</span><br><span class="line"> table.Columns.Add(fnameColumn);</span><br><span class="line"> <span class="keyword">return</span> table;</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="下面介绍一下和datatable联系紧密的dataset"><a href="#下面介绍一下和datatable联系紧密的dataset" class="headerlink" title="下面介绍一下和datatable联系紧密的dataset"></a>下面介绍一下和datatable联系紧密的dataset</h3><blockquote><p>DataSet 是数据的一种内存驻留表示形式,无论它包含的数据来自什么数据源,都会提供一致的关系编程模型。 DataSet 表示整个数据集,其中包含对数据进行包含、排序和约束的表以及表间的关系。</p><p>使用 DataSet 的方法有若干种,这些方法可以单独应用,也可以结合应用。 你可以:</p><p>以编程方式在 DataTable 中创建 DataRelation、Constraint 和 DataSet,并使用数据填充表。</p><p>通过 DataSet 用现有关系数据源中的数据表填充 DataAdapter。</p><p>datatable只能赋值给一个dataset,如果想要赋值给多个dataset,请copy出多个datatable;</p><p>dataset是一个数据集,可以存放多个datatable。</p><p>dataset中的数据也可以转化到datatable中。</p></blockquote><p><strong>补充:C# dataTable常用处理</strong></p><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> l2 = dt.AsEnumerable().ToList().Select(x => x.Field(“ID”)).ToList();</span><br><span class="line">DataTable <span class="keyword">new</span> dt = <span class="keyword">new</span> DataTable();</span><br><span class="line">newdt = dt.Clone(); <span class="comment">// 克隆dt 的结构,包括所有 dt 架构和约束,并无数据;</span></span><br><span class="line">DataRow[] rows = dt.Select(conditions); <span class="comment">// 从dt 中查询符合条件的记录;</span></span><br><span class="line">DataTable.Select(“City Like ‘B%<span class="string">'”);</span></span><br><span class="line"><span class="string">DataTable.Select(“name='</span>” + a +<span class="string">"'"</span>);</span><br><span class="line"><span class="keyword">foreach</span> (DataRow row <span class="keyword">in</span> rows) <span class="comment">// 将查询的结果添加到dt中;</span></span><br><span class="line">{</span><br><span class="line">newdt.Rows.Add(row.ItemArray);</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="DataGridView部分内容"><a href="#DataGridView部分内容" class="headerlink" title="DataGridView部分内容"></a>DataGridView部分内容</h2><h3 id="单元格按钮功能"><a href="#单元格按钮功能" class="headerlink" title="单元格按钮功能"></a>单元格按钮功能</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">dataGridView1_CellContentClick</span>(<span class="params"><span class="built_in">object</span> sender, DataGridViewCellEventArgs e</span>)</span></span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">int</span> Index = <span class="keyword">this</span>.dataGridView1.CurrentRow.Index;<span class="comment">//获取当前选中行的索引</span></span><br><span class="line"> <span class="keyword">if</span> (Index<<span class="keyword">this</span>.dataGridView1.Rows.Count<span class="number">-1</span> && <span class="keyword">this</span>.dataGridView1.CurrentCell.Value.ToString()== <span class="string">"点击这里"</span>)<span class="comment">//"点击这里是之前设置按钮列的文本", //this.dataGridView1.CurrentCell.Value.ToString()== "点击这里";的用意是判断选中单元格是不是按钮单元格</span></span><br><span class="line"> { </span><br><span class="line"> MessageBox.Show(<span class="string">"在这个if面写事件"</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h3 id="查询功能以及默认视图"><a href="#查询功能以及默认视图" class="headerlink" title="查询功能以及默认视图"></a>查询功能以及默认视图</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 查询功能</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">uiSySearch_Click</span>(<span class="params"><span class="built_in">object</span> sender, EventArgs e</span>)</span></span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">string</span> txtSerach = <span class="keyword">this</span>.txtSerach.Text.ToString().Trim();</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (txtSerach.Length > <span class="number">0</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">string</span> strWhere = <span class="string">" GDGSI like '%"</span> + txtSerach + <span class="string">"%' Or BDZHANG like '%"</span> + txtSerach + <span class="string">"%'"</span>;</span><br><span class="line"> DataTable dt_Search = CreateNewDataTable(dt_Excele, strWhere);</span><br><span class="line"></span><br><span class="line"> DataTable dt_New = dt_Search.DefaultView.ToTable(<span class="literal">false</span>, <span class="keyword">new</span> <span class="built_in">string</span>[] { <span class="string">"XHAO"</span>, <span class="string">"GDGSI"</span>, <span class="string">"BDZHANG"</span>, <span class="string">"YXBHAO"</span>, <span class="string">"SBXHAO"</span>, <span class="string">"CHPTHAO"</span>, <span class="string">"CHPXHAO"</span>, <span class="string">"RLIANG"</span>, <span class="string">"EDDYA"</span>, <span class="string">"EDDLIU"</span>, <span class="string">"DLZKANG-H-M"</span>, <span class="string">"DLZKANG-H-L"</span>, <span class="string">"DLZKANG-M-L"</span>, <span class="string">"BYQXSHU"</span>, <span class="string">"PLV"</span>, <span class="string">"TXZHSHU"</span> });</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (dt_New.Rows.Count > <span class="number">0</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < dt_New.Rows.Count; i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (dt_New.Rows[i][<span class="string">"EDDLIU"</span>].ToString().Trim().Length > <span class="number">0</span>)<span class="comment">//额定电流</span></span><br><span class="line"> {</span><br><span class="line"> dt_New.Rows[i][<span class="string">"EDDLIU"</span>] = <span class="built_in">float</span>.Parse(dt_New.Rows[i][<span class="string">"EDDLIU"</span>].ToString()).ToString(<span class="string">"F2"</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">this</span>.gvShow.DataSource = dt_New;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//搜索内容不匹配时,清空数据,不改变表结构</span></span><br><span class="line"> DataTable table = dt_Excele.Clone();</span><br><span class="line"> table.NewRow();</span><br><span class="line"> table = table.DefaultView.ToTable(<span class="literal">false</span>, <span class="keyword">new</span> <span class="built_in">string</span>[] { <span class="string">"XHAO"</span>, <span class="string">"GDGSI"</span>, <span class="string">"BDZHANG"</span>, <span class="string">"YXBHAO"</span>, <span class="string">"SBXHAO"</span>, <span class="string">"CHPTHAO"</span>, <span class="string">"CHPXHAO"</span>, <span class="string">"RLIANG"</span>, <span class="string">"EDDYA"</span>, <span class="string">"EDDLIU"</span>, <span class="string">"DLZKANG-H-M"</span>, <span class="string">"DLZKANG-H-L"</span>, <span class="string">"DLZKANG-M-L"</span>, <span class="string">"BYQXSHU"</span>, <span class="string">"PLV"</span>, <span class="string">"TXZHSHU"</span> });</span><br><span class="line"> gvShow.DataSource = table;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> {</span><br><span class="line"> DataBind();</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 数据绑定</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">DataBind</span>()</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (dt_Excele.Rows.Count > <span class="number">0</span>)</span><br><span class="line"> {</span><br><span class="line"> DataTable dt_New = dt_Excele.DefaultView.ToTable(<span class="literal">false</span>, <span class="keyword">new</span> <span class="built_in">string</span>[] { <span class="string">"XHAO"</span>, <span class="string">"GDGSI"</span>, <span class="string">"BDZHANG"</span>, <span class="string">"YXBHAO"</span>, <span class="string">"SBXHAO"</span>, <span class="string">"CHPTHAO"</span>, <span class="string">"CHPXHAO"</span>, <span class="string">"RLIANG"</span>, <span class="string">"EDDYA"</span>, <span class="string">"EDDLIU"</span>, <span class="string">"DLZKANG-H-M"</span>, <span class="string">"DLZKANG-H-L"</span>, <span class="string">"DLZKANG-M-L"</span>, <span class="string">"BYQXSHU"</span>, <span class="string">"PLV"</span>, <span class="string">"TXZHSHU"</span> });</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (dt_New.Rows.Count > <span class="number">0</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < dt_New.Rows.Count; i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (dt_New.Rows[i][<span class="string">"EDDLIU"</span>].ToString().Trim().Length > <span class="number">0</span>)<span class="comment">//额定电流</span></span><br><span class="line"> {</span><br><span class="line"> dt_New.Rows[i][<span class="string">"EDDLIU"</span>] = <span class="built_in">float</span>.Parse(dt_New.Rows[i][<span class="string">"EDDLIU"</span>].ToString()).ToString(<span class="string">"F2"</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">this</span>.gvShow.DataSource = dt_New;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">this</span>.gvShow.DataSource = <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h4 id="同时处理多组数据"><a href="#同时处理多组数据" class="headerlink" title="同时处理多组数据"></a>同时处理多组数据</h4><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 报告信息Excel文件绑定</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">DataBind</span>()</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (<span class="keyword">this</span>.lblSerialNumber.Text.ToString().Trim().Contains(<span class="string">";"</span>))</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">string</span>[] strArr = <span class="keyword">this</span>.lblSerialNumber.Text.ToString().Trim().Split(<span class="string">';'</span>);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (strArr.Length > <span class="number">0</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">string</span> strConnect = <span class="built_in">string</span>.Empty;</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < strArr.Length; i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">string</span> strSerialNumber = strArr[i].ToString();</span><br><span class="line"> strConnect += <span class="string">"'"</span> + strSerialNumber + <span class="string">"',"</span>;</span><br><span class="line"> }</span><br><span class="line"> strConnect = strConnect.Substring(<span class="number">0</span>, strConnect.Length - <span class="number">1</span>);</span><br><span class="line"></span><br><span class="line"> <span class="built_in">string</span> strWhere = <span class="string">"XHAO In ("</span> + strConnect + <span class="string">")"</span>;</span><br><span class="line"> dt_Temp = CreateNewDataTable(dt_Excel, strWhere);</span><br><span class="line"> dt = dt_Temp.DefaultView.ToTable(<span class="literal">false</span>, <span class="keyword">new</span> <span class="built_in">string</span>[] { <span class="string">"XHAO"</span>, <span class="string">"GDGSI"</span>, <span class="string">"BDZHANG"</span>, <span class="string">"YXBHAO"</span>, <span class="string">"SBXHAO"</span>, <span class="string">"DLWTDLIU"</span>, <span class="string">"DLFZHDLIU"</span>, <span class="string">"ZYDMGXBPJYSHFXDDLI"</span>, <span class="string">"NXQFXSHWPJLJQDU"</span>, <span class="string">"AQXSHU"</span>, <span class="string">"DLCSHU"</span> });</span><br><span class="line"> dt.Columns.Add(<span class="string">"FXWDAQXSHXZHZHI"</span>);</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < dt.Rows.Count; i++)</span><br><span class="line"> {</span><br><span class="line"> dt.Rows[i][<span class="string">"FXWDAQXSHXZHZHI"</span>] = (<span class="built_in">float</span>.Parse(dt.Rows[i][<span class="string">"NXQFXSHWPJLJQDU"</span>].ToString()) * <span class="built_in">float</span>.Parse(dt.Rows[i][<span class="string">"AQXSHU"</span>].ToString())).ToString();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">this</span>.gvShow.DataSource = dt;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (<span class="keyword">this</span>.lblSerialNumber.Text.ToString().Trim().Length > <span class="number">0</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">string</span> strWhere = <span class="string">"XHAO='"</span> + <span class="keyword">this</span>.lblSerialNumber.Text.ToString().Trim() + <span class="string">"'"</span>;</span><br><span class="line"> dt_Temp = CreateNewDataTable(dt_Excel, strWhere);</span><br><span class="line"> dt = dt_Temp.DefaultView.ToTable(<span class="literal">false</span>, <span class="keyword">new</span> <span class="built_in">string</span>[] { <span class="string">"XHAO"</span>, <span class="string">"GDGSI"</span>, <span class="string">"BDZHANG"</span>, <span class="string">"YXBHAO"</span>, <span class="string">"SBXHAO"</span>, <span class="string">"DLWTDLIU"</span>, <span class="string">"DLFZHDLIU"</span>, <span class="string">"ZYDMGXBPJYSHFXDDLI"</span>, <span class="string">"NXQFXSHWPJLJQDU"</span>, <span class="string">"AQXSHU"</span>, <span class="string">"DLCSHU"</span> });</span><br><span class="line"> dt.Columns.Add(<span class="string">"FXWDAQXSHXZHZHI"</span>);</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < dt.Rows.Count; i++)</span><br><span class="line"> {</span><br><span class="line"> dt.Rows[i][<span class="string">"FXWDAQXSHXZHZHI"</span>] = (<span class="built_in">float</span>.Parse(dt.Rows[i][<span class="string">"NXQFXSHWPJLJQDU"</span>].ToString()) * <span class="built_in">float</span>.Parse(dt.Rows[i][<span class="string">"AQXSHU"</span>].ToString())).ToString();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">this</span>.gvShow.DataSource = dt;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="获取DatagridView数据到DataTable"><a href="#获取DatagridView数据到DataTable" class="headerlink" title="获取DatagridView数据到DataTable"></a>获取DatagridView数据到DataTable</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//方法一:</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 获取DataGridView数据到DataTable中</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="dgv"></span><span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><returns></span><span class="doctag"></returns></span></span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> DataTable <span class="title">GetDgvToTable</span>(<span class="params">DataGridView dgv</span>)</span></span><br><span class="line"> {</span><br><span class="line"> DataTable dt = <span class="keyword">new</span> DataTable();</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 列强制转换</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> count = <span class="number">0</span>; count < dgv.Columns.Count; count++)</span><br><span class="line"> {</span><br><span class="line"> DataColumn dc = <span class="keyword">new</span> DataColumn(dgv.Columns[count].Name.ToString());</span><br><span class="line"> dt.Columns.Add(dc);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 循环行</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> count = <span class="number">0</span>; count < dgv.Rows.Count; count++)</span><br><span class="line"> {</span><br><span class="line"> DataRow dr = dt.NewRow();</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> countsub = <span class="number">0</span>; countsub < dgv.Columns.Count; countsub++)</span><br><span class="line"> {</span><br><span class="line"> dr[countsub] = Convert.ToString(dgv.Rows[count].Cells[countsub].Value);</span><br><span class="line"> }</span><br><span class="line"> dt.Rows.Add(dr);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> dt;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"><span class="comment">//方法二:</span></span><br><span class="line"> DataTable dt = <span class="keyword">new</span> DataTable();</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < <span class="keyword">this</span>.skgvShow.Columns.Count; i++)</span><br><span class="line"> {</span><br><span class="line"> DataColumn dc = <span class="keyword">new</span> DataColumn(skgvShow.Columns[i].Name.ToString());</span><br><span class="line"> dt.Columns.Add(dc);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i < <span class="keyword">this</span>.skgvShow.Rows.Count; i++)</span><br><span class="line"> {</span><br><span class="line"> DataRow dr = dt.NewRow();</span><br><span class="line"> <span class="keyword">for</span> (<span class="built_in">int</span> j = <span class="number">0</span>; j < skgvShow.Columns.Count; j++)</span><br><span class="line"> {</span><br><span class="line"> dr[j] = Convert.ToString(skgvShow.Rows[i].Cells[j].Value);</span><br><span class="line"> }</span><br><span class="line"> dt.Rows.Add(dr);</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h3 id="添加行号"><a href="#添加行号" class="headerlink" title="添加行号"></a>添加行号</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 添加行号</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">gvShow_RowStateChanged</span>(<span class="params"><span class="built_in">object</span> sender, DataGridViewRowStateChangedEventArgs e</span>)</span></span><br><span class="line"> {</span><br><span class="line"> e.Row.HeaderCell.Value = <span class="built_in">string</span>.Format(<span class="string">"{0}"</span>, e.Row.Index + <span class="number">1</span>);</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h2 id="弹窗选择文件"><a href="#弹窗选择文件" class="headerlink" title="弹窗选择文件"></a>弹窗选择文件</h2><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">OpenFileDialog openFileDialog = <span class="keyword">new</span> OpenFileDialog();</span><br><span class="line"> openFileDialog.Filter = <span class="string">"Files|*.xls;*.xlsx"</span>;<span class="comment">//设置选在文件格式</span></span><br><span class="line"></span><br><span class="line"> openFileDialog.InitialDirectory = Environment.CurrentDirectory;<span class="comment">//默认打开路径为当前目录</span></span><br><span class="line"></span><br><span class="line"> foldPath = <span class="built_in">string</span>.Empty;<span class="comment">//文件所在路径</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (openFileDialog.ShowDialog() == DialogResult.OK)</span><br><span class="line"> {</span><br><span class="line"> foldPath = openFileDialog.FileName;<span class="comment">//获取文件路径信息</span></span><br><span class="line"> <span class="keyword">if</span> (foldPath != <span class="built_in">string</span>.Empty)</span><br><span class="line"> {</span><br><span class="line"> txtFilePath.Text = foldPath;<span class="comment">//文本框显示选取文件所在路径</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><blockquote><p>部分内容非原创,若有雷同,请留言说明</p></blockquote>]]></content>
<categories>
<category> 编程语言 </category>
<category> C# </category>
</categories>
<tags>
<tag> Winform </tag>
<tag> DataTable </tag>
<tag> DataGridview </tag>
</tags>
</entry>
<entry>
<title>C#与SQL Server数据库</title>
<link href="/archives/bf624ee1.html"/>
<url>/archives/bf624ee1.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><blockquote><p>最近需要通过程序连接数据库使用,本篇作为数据库操作相关内容的第一篇,仅记录查资料以及自己尝试可行的笔记内容,具体关于在项目中的真实应用会在后续数据库内容中更新。</p></blockquote><h3 id="连接数据库"><a href="#连接数据库" class="headerlink" title="连接数据库"></a>连接数据库</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//SQL查询语句</span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> DataTable <span class="title">query</span>(<span class="params"><span class="built_in">string</span> sql</span>)</span></span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//server=127.0.0.1;</span></span><br><span class="line"> DataTable dt=<span class="keyword">new</span> DataTable();</span><br><span class="line"> <span class="comment">//DataRow dr;</span></span><br><span class="line"> <span class="built_in">string</span> connString = <span class="string">"server=127.0.0.1;uid=sa;pwd=;database=TJPTTC"</span>;</span><br><span class="line"> SqlConnection conn = <span class="keyword">new</span> SqlConnection(connString);</span><br><span class="line"> SqlDataAdapter adapter = <span class="keyword">new</span> SqlDataAdapter(sql,conn);</span><br><span class="line"> adapter.Fill(dt);</span><br><span class="line"> <span class="keyword">return</span> dt;</span><br><span class="line"> }</span><br><span class="line"><span class="comment">//SQL非查询语句</span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">noQuery</span>(<span class="params"><span class="built_in">string</span> sql</span>)</span></span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//server=127.0.0.1;</span></span><br><span class="line"> <span class="built_in">string</span> connString = <span class="string">"server=GLASSESONION;uid=sa;pwd=;database=TJPTTC"</span>;</span><br><span class="line"> SqlConnection conn = <span class="keyword">new</span> SqlConnection(connString);</span><br><span class="line"> SqlCommand cmd = <span class="keyword">new</span> SqlCommand(sql,conn);</span><br><span class="line"> conn.Open();</span><br><span class="line"> cmd.ExecuteNonQuery();</span><br><span class="line"> conn.Close(); </span><br><span class="line"> }</span><br></pre></td></tr></table></figure><blockquote><p>判断数据库是否存在,存在就删除:<a href="https://www.cnblogs.com/mq0036/p/14311664.html#:~:text=%E5%A6%82%E4%BD%95%E5%88%A4%E6%96%ADSQL%E4%B8%AD%E6%9F%90%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%BA%93%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%20%E5%9C%A8SQL%20Server%E6%95%B0%E6%8D%AE%20%E5%BA%93%E7%BC%96%20%E7%A8%8B%E6%97%B6%EF%BC%8C%E5%B8%B8%20%E6%8A%84%20%E5%B8%B8%E9%9C%80%20%E8%A2%AD,%EF%BC%9A%201.%20select%20%2A%20From%20master.dbo.sysdatabases%20where%20name%3D%27test_db%27">未细读</a></p></blockquote><h3 id="判断表是否存在"><a href="#判断表是否存在" class="headerlink" title="判断表是否存在"></a>判断表是否存在</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">IF Object_id (<span class="string">'xxxx'</span>,<span class="string">'xx'</span>) <span class="keyword">Is</span> <span class="keyword">Null</span> <span class="keyword">Select</span> <span class="number">0</span> <span class="keyword">Else</span> <span class="keyword">Select</span> <span class="number">1</span></span><br></pre></td></tr></table></figure><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">if object_id(<span class="string">'对象名'</span>) <span class="keyword">is</span> <span class="keyword">not</span> <span class="keyword">null</span> 执行语句</span><br><span class="line"><span class="comment">--尽量写上对象类型,避免因为同名现象,而查询出错</span></span><br><span class="line"><span class="comment">--或者</span></span><br><span class="line">if object_id(<span class="string">'对象名'</span>,<span class="string">'对象类型'</span>) <span class="keyword">is</span> <span class="keyword">not</span> <span class="keyword">null</span> 执行语句</span><br><span class="line"><span class="comment">--或者</span></span><br><span class="line">if object_id(N<span class="string">'对象名'</span>,N<span class="string">'对象类型'</span>) <span class="keyword">is</span> <span class="keyword">not</span> <span class="keyword">null</span> 执行语句</span><br><span class="line"><span class="comment">--等同于:select ID from sysobjects where name='对象名' and type='对象类型'</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><blockquote><p>type如下列表:</p></blockquote><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">AF <span class="operator">=</span> Aggregate <span class="keyword">function</span> (CLR)</span><br><span class="line">C <span class="operator">=</span> <span class="keyword">CHECK</span> <span class="keyword">constraint</span></span><br><span class="line">D <span class="operator">=</span> <span class="keyword">DEFAULT</span> (<span class="keyword">constraint</span> <span class="keyword">or</span> stand<span class="operator">-</span>alone)</span><br><span class="line">F <span class="operator">=</span> <span class="keyword">FOREIGN</span> KEY <span class="keyword">constraint</span></span><br><span class="line">FN <span class="operator">=</span> <span class="keyword">SQL</span> scalar <span class="keyword">function</span></span><br><span class="line">FS <span class="operator">=</span> Assembly (CLR) scalar<span class="operator">-</span><span class="keyword">function</span></span><br><span class="line">FT <span class="operator">=</span> Assembly (CLR) <span class="keyword">table</span><span class="operator">-</span>valued <span class="keyword">function</span></span><br><span class="line">IF <span class="operator">=</span> <span class="keyword">SQL</span> inline <span class="keyword">table</span><span class="operator">-</span>valued <span class="keyword">function</span></span><br><span class="line">IT <span class="operator">=</span> Internal <span class="keyword">table</span></span><br><span class="line">P <span class="operator">=</span> <span class="keyword">SQL</span> Stored <span class="keyword">Procedure</span></span><br><span class="line">PC <span class="operator">=</span> Assembly (CLR) stored<span class="operator">-</span><span class="keyword">procedure</span></span><br><span class="line">PG <span class="operator">=</span> Plan guide</span><br><span class="line">PK <span class="operator">=</span> <span class="keyword">PRIMARY</span> KEY <span class="keyword">constraint</span></span><br><span class="line">R <span class="operator">=</span> Rule (<span class="keyword">old</span><span class="operator">-</span>style, stand<span class="operator">-</span>alone)</span><br><span class="line">RF <span class="operator">=</span> Replication<span class="operator">-</span><span class="keyword">filter</span><span class="operator">-</span><span class="keyword">procedure</span></span><br><span class="line">S <span class="operator">=</span> <span class="keyword">System</span> base <span class="keyword">table</span></span><br><span class="line">SN <span class="operator">=</span> Synonym</span><br><span class="line">SQ <span class="operator">=</span> Service queue</span><br><span class="line">TA <span class="operator">=</span> Assembly (CLR) DML <span class="keyword">trigger</span></span><br><span class="line">TF <span class="operator">=</span> <span class="keyword">SQL</span> <span class="keyword">table</span><span class="operator">-</span>valued<span class="operator">-</span><span class="keyword">function</span></span><br><span class="line">TR <span class="operator">=</span> <span class="keyword">SQL</span> DML <span class="keyword">trigger</span></span><br><span class="line">U <span class="operator">=</span> <span class="keyword">Table</span> (<span class="keyword">user</span><span class="operator">-</span>defined)</span><br><span class="line">UQ <span class="operator">=</span> <span class="keyword">UNIQUE</span> <span class="keyword">constraint</span></span><br><span class="line">V <span class="operator">=</span> <span class="keyword">View</span></span><br><span class="line">X <span class="operator">=</span> Extended stored <span class="keyword">procedure</span></span><br></pre></td></tr></table></figure><blockquote><p>大家都知道在数据库中有一个系统表<code>sysobjects</code>,里面存储了数据库各个对象的信息。可以查询下看看结果。可以看出每个对象都有一个<code>ID</code>,这个表存储了表,存储过程,触发器,视图等相关信息。注意:字段没有。</p></blockquote><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">object_id 就是根据对象名称返回该对象的id.</span><br><span class="line">object_name 是根据对象id返回对象名称.</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">select</span> object_id(对象名)等同于:</span><br><span class="line"><span class="keyword">select</span> id <span class="keyword">from</span> sysobjects <span class="keyword">where</span> name<span class="operator">=</span>对象名</span><br><span class="line"></span><br><span class="line"><span class="keyword">select</span> object_name(id号)等同于:</span><br><span class="line"><span class="keyword">select</span> name <span class="keyword">from</span> sysobjects <span class="keyword">where</span> id<span class="operator">=</span>id号</span><br><span class="line"></span><br></pre></td></tr></table></figure><blockquote><p> SQL SERVER 2000以上版本都支持这个函数。</p></blockquote><h3 id="图形化数据库创建和文件存储路径"><a href="#图形化数据库创建和文件存储路径" class="headerlink" title="图形化数据库创建和文件存储路径"></a>图形化数据库创建和文件存储路径</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">partial</span> <span class="keyword">class</span> <span class="title">Form1</span> : <span class="title">Form</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">public</span> <span class="built_in">string</span> strDatabaseName = <span class="built_in">string</span>.Empty;<span class="comment">//创建数据库时数据库名称</span></span><br><span class="line"> <span class="keyword">public</span> <span class="built_in">string</span> strDataFilePath = <span class="built_in">string</span>.Empty;<span class="comment">//数据库文件、日志存储位置</span></span><br><span class="line"> SqlConnection conn = <span class="keyword">new</span> SqlConnection(<span class="string">"Server=localhost;User ID=sa;pwd=0123456789"</span>);</span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="title">Form1</span>()</span></span><br><span class="line"> {</span><br><span class="line"> InitializeComponent();</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">btnCreateDatabase_Click</span>(<span class="params"><span class="built_in">object</span> sender, EventArgs e</span>)</span></span><br><span class="line"> {</span><br><span class="line"> strDatabaseName = <span class="keyword">this</span>.TextDatabaseName.Text;</span><br><span class="line"> strDataFilePath = <span class="keyword">this</span>.TextFileStoragePath.Text;</span><br><span class="line"> DataBaseOperate.CreateDatabase(strDatabaseName, strDataFilePath);<span class="comment">//创建数据库</span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 图形化文件存储路径</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">BtnFileStroagePath_Click</span>(<span class="params"><span class="built_in">object</span> sender, EventArgs e</span>)</span></span><br><span class="line"> {</span><br><span class="line"> FolderBrowserDialog dialog = <span class="keyword">new</span> FolderBrowserDialog();</span><br><span class="line"> dialog.Description = <span class="string">"请选择文件路径"</span>;</span><br><span class="line"> <span class="built_in">string</span> foldPath = <span class="string">""</span>;</span><br><span class="line"> <span class="keyword">if</span> (dialog.ShowDialog() == DialogResult.OK)</span><br><span class="line"> {</span><br><span class="line"> foldPath = dialog.SelectedPath + <span class="string">@"\"</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (foldPath != <span class="built_in">string</span>.Empty)</span><br><span class="line"> {</span><br><span class="line"> TextFileStoragePath.Text = foldPath;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">TextDatabaseName_TextChanged</span>(<span class="params"><span class="built_in">object</span> sender, EventArgs e</span>)</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (TextDatabaseName.Text != <span class="built_in">string</span>.Empty)</span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//默认数据库文件存储位置</span></span><br><span class="line"> TextFileStoragePath.Text = <span class="string">"C:\\Program Files\\Microsoft SQL Server\\MSSQL10_50.MSSQLSERVER\\MSSQL\\DATA\\"</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br></pre></td></tr></table></figure><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> 动态生成数据库</span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="strDatabaseName"></span>创建的数据库名称|逻辑名称<span class="doctag"></param></span></span></span><br><span class="line"> <span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="strDataFilePath"></span>文件存储路径<span class="doctag"></param></span></span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">CreateDatabase</span>(<span class="params"><span class="built_in">string</span> strDatabaseName, <span class="built_in">string</span> strDataFilePath</span>)</span></span><br><span class="line"> {</span><br><span class="line"> SqlConnection conn= <span class="keyword">new</span> SqlConnection(<span class="string">"Server=localhost;User ID=sa;pwd=0123456789"</span>);<span class="comment">//连接本地服务器</span></span><br><span class="line"> conn.Open();</span><br><span class="line"> StringBuilder Sql_Command = <span class="keyword">new</span> StringBuilder();</span><br><span class="line"> Sql_Command.Append(<span class="string">"If Not Exists "</span>);</span><br><span class="line"> Sql_Command.Append(<span class="string">"("</span>);</span><br><span class="line"> Sql_Command.Append(<span class="string">"Select * "</span>);</span><br><span class="line"> Sql_Command.Append(<span class="string">"From "</span>);</span><br><span class="line"> Sql_Command.Append(<span class="string">"master.dbo.sysdatabases "</span>);</span><br><span class="line"> Sql_Command.Append(<span class="string">"where "</span>);</span><br><span class="line"> Sql_Command.Append(<span class="string">"name = '"</span> + strDatabaseName + <span class="string">"'"</span>);</span><br><span class="line"> Sql_Command.Append(<span class="string">") "</span>);</span><br><span class="line"></span><br><span class="line"> <span class="built_in">string</span> strSQLCmd = Sql_Command.ToString() + <span class="string">"CREATE DATABASE "</span></span><br><span class="line"> + strDatabaseName + <span class="string">" ON PRIMARY "</span> +<span class="comment">//数据库名称</span></span><br><span class="line"> <span class="string">"(NAME = "</span> + strDatabaseName + <span class="string">"_Data, "</span> +<span class="comment">//逻辑名称</span></span><br><span class="line"> <span class="string">"FILENAME = '"</span> + strDataFilePath + strDatabaseName + <span class="string">"Data.mdf')"</span> +<span class="comment">//文件存储路径</span></span><br><span class="line"> <span class="string">"LOG ON (NAME = "</span> + strDatabaseName + <span class="string">"_Log, "</span> +<span class="comment">//数据库日志文件</span></span><br><span class="line"> <span class="string">"FILENAME = '"</span> + strDataFilePath + strDatabaseName + <span class="string">"Log.ldf')"</span>;<span class="comment">//日志文件路径 </span></span><br><span class="line"> </span><br><span class="line"> SqlCommand myCommand = <span class="keyword">new</span> SqlCommand(strSQLCmd, conn);</span><br><span class="line"> <span class="keyword">try</span></span><br><span class="line"> {</span><br><span class="line"> Conn.Open();</span><br><span class="line"> myCommand.ExecuteNonQuery();</span><br><span class="line"> MessageBox.Show(<span class="string">"DataBase is Created Successfully"</span>, <span class="string">"MyProgram"</span>, MessageBoxButtons.OK, MessageBoxIcon.Information);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">catch</span> (SqlException ex)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">string</span> strDataInfo = <span class="string">"数据库创建失败。"</span> + DateTime.Now + <span class="string">"\r\n"</span>;</span><br><span class="line"> <span class="built_in">string</span> strException = <span class="built_in">string</span>.Format(strDataInfo + <span class="string">"异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n"</span>, ex.GetType().Name, ex.Message, ex.StackTrace);</span><br><span class="line"> MessageBox.Show(<span class="string">"数据库创建失败。"</span> + ex.Message.ToString());</span><br><span class="line"> FileOperate.WriteLog(strException);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">finally</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (Conn.State == ConnectionState.Open)</span><br><span class="line"> {</span><br><span class="line"> Conn.Close();</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="向表中添加数据"><a href="#向表中添加数据" class="headerlink" title="向表中添加数据"></a>向表中添加数据</h3><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 向表中添加记录 </span></span><br><span class="line"><span class="comment">// string sql = "INSERT INTO myTable(myId, myName, myAddress, myBalance) " +</span></span><br><span class="line"><span class="comment">// "VALUES (1001, 'Puneet Nehra', 'A 449 Sect 19, DELHI', 23.98 ) ";</span></span><br><span class="line"><span class="comment">// cmd = new SqlCommand(sql, Conn);</span></span><br><span class="line"><span class="comment">// cmd.ExecuteNonQuery();</span></span><br></pre></td></tr></table></figure><h3 id="清除表中数据"><a href="#清除表中数据" class="headerlink" title="清除表中数据"></a>清除表中数据</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">truncate</span> Tbale T_CHData<span class="operator">/</span><span class="operator">/</span>清楚表中数据,不影响表内结构,无法撤销还原</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 编程语言 </category>
<category> 数据库操作 </category>
</categories>
<tags>
<tag> C# </tag>
<tag> Winform </tag>
<tag> SQL Server </tag>
<tag> 数据库操作 </tag>
</tags>
</entry>
<entry>
<title>C#-XML文件读写</title>
<link href="/archives/abc2fd82.html"/>
<url>/archives/abc2fd82.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="XML文件基本概念"><a href="#XML文件基本概念" class="headerlink" title="XML文件基本概念"></a>XML文件基本概念</h3><blockquote><p>可扩展标记语言(英语:Extensible Markup Language,简称:XML),是一种标记语言。标记指计算机所能理解的信息符号,通过此种标记,计算机之间可以处理包含各种信息的文章等。如何定义这些标记,既可以选择国际通用的标记语言,比如HTML,也可以使用像XML这样由相关人士自由决定的标记语言,这就是语言的可扩展性。XML是从标准通用标记语言(SGML)中简化修改出来的,可以在不同语言或者平台进行数据传输。</p></blockquote><h3 id="基本要素"><a href="#基本要素" class="headerlink" title="基本要素"></a>基本要素</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><?xml version=<span class="string">"1.0"</span> encoding=<span class="string">"utf-8"</span>?></span> <span class="comment"><!-- 文档声明 --></span></span><br><span class="line"><span class="tag"><<span class="name">students</span>></span> <span class="comment"><!-- 元素=标签 students为根标签 ,或者称之为根元素,程序处理时称之为节点--></span></span><br><span class="line"> <span class="tag"><<span class="name">student</span> <span class="attr">name</span>=<span class="string">"xiaoming"</span>></span><span class="tag"></<span class="name">student</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">student</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">name</span>></span>xaiohong<span class="tag"></<span class="name">name</span>></span></span><br><span class="line"> <span class="comment"><!--特殊字符--></span></span><br><span class="line"> <span class="tag"><<span class="name">read</span>></span><span class="symbol">&lt;</span>三个火枪手<span class="symbol">&gt;</span><span class="tag"></<span class="name">read</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">student</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">student</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">name</span>></span>xiaoming<span class="tag"></<span class="name">name</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">student</span>></span></span><br><span class="line"> <span class="comment"><!--![CDATA[不想解析的内容,浏览器会直接输出内容]]>--></span></span><br><span class="line"> <![CDATA[</span><br><span class="line"> <student></span><br><span class="line"> <name>xaiodong</name></span><br><span class="line"> </student></span><br><span class="line"> ]]></span><br><span class="line"> </span><br><span class="line"><span class="tag"></<span class="name">students</span>></span></span><br></pre></td></tr></table></figure><p>内容预览:<br><img src="https://s.imgkb.xyz/abcdocker/2022/09/12/de782fc50c597/de782fc50c597.png"></p><h3 id="C-读写XML文档"><a href="#C-读写XML文档" class="headerlink" title="C#读写XML文档"></a>C#读写XML文档</h3><blockquote><p>引用命名空间<br><code>using System.Xml;</code></p></blockquote><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><summary></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 写入XML端口号默认index</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"></summary></span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag"><param name="COMIndex"></span>端口号Index<span class="doctag"></param></span></span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">WriteXML</span>(<span class="params"><span class="built_in">string</span> COMIndex</span>)</span></span><br><span class="line">{</span><br><span class="line"> XmlDocument xmlDoc = <span class="keyword">new</span> XmlDocument();</span><br><span class="line"> xmlDoc.Load(<span class="string">@"SysConfig.xml"</span>);</span><br><span class="line"> <span class="comment">//获取根节点</span></span><br><span class="line"> XmlNode node = xmlDoc.SelectSingleN(<span class="string">"configuration"</span>);</span><br><span class="line"> XmlNodeList nodeList = node.ChildNodes;</span><br><span class="line"> <span class="keyword">foreach</span> (XmlNode xn <span class="keyword">in</span> nodeList)</span><br><span class="line"> {</span><br><span class="line"> XmlNodeList childList =xn.ChildNodes;</span><br><span class="line"> <span class="keyword">foreach</span> (XmlNode node1 <span class="keyword">in</span> childList)</span><br><span class="line"> {</span><br><span class="line"> node1.InnerText = COMIndex;<span class="comment">//修改端口号配置</span></span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> xmlDoc.Save(<span class="string">"SysConfig.xml"</span>);</span><br><span class="line">}</span><br></pre></td></tr></table></figure><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System.Data;</span><br><span class="line"><span class="keyword">using</span> System.IO;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> <span class="title">Serialport.Operate</span></span><br><span class="line">{</span><br><span class="line"> <span class="keyword">class</span> <span class="title">ReadSysConfig</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="built_in">string</span> _strcomIndex = <span class="built_in">string</span>.Empty;</span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="built_in">string</span> _strchannelColor = <span class="built_in">string</span>.Empty;</span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="built_in">string</span> _strtrendTime = <span class="built_in">string</span>.Empty;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="built_in">string</span> _strmaxAmplitude = <span class="built_in">string</span>.Empty;</span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="built_in">string</span> _strminAmplitude = <span class="built_in">string</span>.Empty;</span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="built_in">string</span> _strinterval = <span class="built_in">string</span>.Empty;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">LoadConfig</span>()</span></span><br><span class="line"> {</span><br><span class="line"> DataTable m_dtSysConfig = <span class="keyword">new</span> DataTable();</span><br><span class="line"> <span class="comment">//加载系统配置参数</span></span><br><span class="line"> m_dtSysConfig.Columns.Add(FileNameSysConfig.comIndex, <span class="keyword">typeof</span>(<span class="built_in">string</span>));</span><br><span class="line"> m_dtSysConfig.Columns.Add(FileNameSysConfig.channelColor, <span class="keyword">typeof</span>(<span class="built_in">string</span>));</span><br><span class="line"> m_dtSysConfig.Columns.Add(FileNameSysConfig.trendTime, <span class="keyword">typeof</span>(<span class="built_in">string</span>));</span><br><span class="line"> m_dtSysConfig.Columns.Add(FileNameSysConfig.maxAmplitude, <span class="keyword">typeof</span>(<span class="built_in">string</span>));</span><br><span class="line"> m_dtSysConfig.Columns.Add(FileNameSysConfig.minAmplitude, <span class="keyword">typeof</span>(<span class="built_in">string</span>));</span><br><span class="line"> NewMethod(m_dtSysConfig);</span><br><span class="line"> m_dtSysConfig.TableName = <span class="string">"Sysconfig"</span>;</span><br><span class="line"> <span class="keyword">if</span> (File.Exists(FilePathSysConfig.configXmlPath))</span><br><span class="line"> {</span><br><span class="line"> m_dtSysConfig.ReadXml(FilePathSysConfig.configXmlPath);</span><br><span class="line"></span><br><span class="line"> _strcomIndex = m_dtSysConfig.Rows[<span class="number">0</span>][FileNameSysConfig.comIndex].ToString().Trim();</span><br><span class="line"> _strchannelColor = m_dtSysConfig.Rows[<span class="number">0</span>][FileNameSysConfig.channelColor].ToString().Trim();</span><br><span class="line"> _strtrendTime = m_dtSysConfig.Rows[<span class="number">0</span>][FileNameSysConfig.trendTime].ToString().Trim();</span><br><span class="line"> _strmaxAmplitude = m_dtSysConfig.Rows[<span class="number">0</span>][FileNameSysConfig.maxAmplitude].ToString().Trim();</span><br><span class="line"> _strminAmplitude = m_dtSysConfig.Rows[<span class="number">0</span>][FileNameSysConfig.minAmplitude].ToString().Trim();</span><br><span class="line"> _strinterval = m_dtSysConfig.Rows[<span class="number">0</span>][FileNameSysConfig.interval].ToString().Trim();</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">NewMethod</span>(<span class="params">DataTable m_dtSysConfig</span>)</span></span><br><span class="line"> {</span><br><span class="line"> m_dtSysConfig.Columns.Add(FileNameSysConfig.interval, <span class="keyword">typeof</span>(<span class="built_in">string</span>));</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="built_in">string</span> StrcomIndex { <span class="keyword">get</span> => _strcomIndex; <span class="keyword">set</span> => _strcomIndex = <span class="keyword">value</span>; }</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="built_in">string</span> StrchannelColor { <span class="keyword">get</span> => _strchannelColor; <span class="keyword">set</span> => _strchannelColor = <span class="keyword">value</span>; }</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="built_in">string</span> StrtrendTime { <span class="keyword">get</span> => _strtrendTime; <span class="keyword">set</span> => _strtrendTime = <span class="keyword">value</span>; }</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="built_in">string</span> StrmaxAmplitude { <span class="keyword">get</span> => _strmaxAmplitude; <span class="keyword">set</span> => _strmaxAmplitude = <span class="keyword">value</span>; }</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="built_in">string</span> StrminAmplitude { <span class="keyword">get</span> => _strminAmplitude; <span class="keyword">set</span> => _strminAmplitude = <span class="keyword">value</span>; }</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="built_in">string</span> Strinterval { <span class="keyword">get</span> => _strinterval; <span class="keyword">set</span> => _strinterval = <span class="keyword">value</span>; }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">class</span> <span class="title">FileNameSysConfig</span><span class="comment">//初始化</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="built_in">string</span> comIndex = <span class="string">"comIndex"</span>;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="built_in">string</span> channelColor = <span class="string">"channelColor"</span>;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="built_in">string</span> trendTime = <span class="string">"trendTime"</span>;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="built_in">string</span> minAmplitude = <span class="string">"minAmplitude"</span>;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="built_in">string</span> maxAmplitude = <span class="string">"maxAmplitude"</span>;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="built_in">string</span> interval = <span class="string">"interval"</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">class</span> <span class="title">FilePathSysConfig</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="built_in">string</span> configXmlPath = <span class="string">@"SysConfig.xml"</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="写在后面"><a href="#写在后面" class="headerlink" title="写在后面"></a>写在后面</h3><p>读写内容写的比较简单,因为目前还没有涉及太复杂的东西,后续有其他内容需要用到会一并在这篇文章中更新😅。</p>]]></content>
<categories>
<category> 编程语言 </category>
</categories>
<tags>
<tag> C# </tag>
<tag> XML文件 </tag>
<tag> Winform </tag>
</tags>
</entry>
<entry>
<title>Echarts图表速记</title>
<link href="/archives/ecd4b633.html"/>
<url>/archives/ecd4b633.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><p><a href="https://www.jianshu.com/p/75c2beb20968">还没看</a></p><h3 id="Echarts"><a href="#Echarts" class="headerlink" title="Echarts"></a>Echarts</h3><h4 id="基础配置"><a href="#基础配置" class="headerlink" title="基础配置"></a>基础配置</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span> /></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>ECharts<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"> <span class="comment"><!-- 引入刚刚下载的 ECharts 文件 --></span></span><br><span class="line"> <span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"echarts.js"</span>></span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="comment"><!-- 为 ECharts 准备一个定义了宽高的 DOM --></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"main"</span> <span class="attr">style</span>=<span class="string">"width: 600px;height:400px;"</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>></span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// 基于准备好的dom,初始化echarts实例</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> myChart = echarts.<span class="title function_">init</span>(<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">'main'</span>));</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// 指定图表的配置项和数据</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> option = {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">title</span>: {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">text</span>: <span class="string">'ECharts 入门示例'</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">tooltip</span>: {},<span class="comment">//提示框</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//标识</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">legend</span>: {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">data</span>: [<span class="string">'销量'</span>]</span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//水平轴配置</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">xAxis</span>: {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">data</span>: [<span class="string">'衬衫'</span>, <span class="string">'羊毛衫'</span>, <span class="string">'雪纺衫'</span>, <span class="string">'裤子'</span>, <span class="string">'高跟鞋'</span>, <span class="string">'袜子'</span>]</span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">yAxis</span>: {},<span class="comment">//默认显示数据</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">series</span>: [</span></span><br><span class="line"><span class="language-javascript"> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">name</span>: <span class="string">'销量'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">type</span>: <span class="string">'bar'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">data</span>: [<span class="number">5</span>, <span class="number">20</span>, <span class="number">36</span>, <span class="number">10</span>, <span class="number">10</span>, <span class="number">20</span>]</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> ]</span></span><br><span class="line"><span class="language-javascript"> };</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// 使用刚指定的配置项和数据显示图表。</span></span></span><br><span class="line"><span class="language-javascript"> myChart.<span class="title function_">setOption</span>(option);</span></span><br><span class="line"><span class="language-javascript"> </span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><h4 id="速记内容"><a href="#速记内容" class="headerlink" title="速记内容"></a>速记内容</h4><p>基本样式<br><img src="https://s.imgkb.xyz/abcdocker/2022/09/06/207fc12380d72/207fc12380d72.png"><br>出发类型:鼠标放上去,后面再写</p><h4 id="异步数据加载"><a href="#异步数据加载" class="headerlink" title="异步数据加载"></a>异步数据加载</h4><p>通常我们图表显示的数据都是从后台加载上来的,上面的配置信息就是写死的数据。</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">series:[</span><br><span class="line"> {</span><br><span class="line"> data:nums</span><br><span class="line"> }</span><br><span class="line">]</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> Echarts </category>
</categories>
<tags>
<tag> C# </tag>
<tag> 波形显示 </tag>
<tag> 笔记便签 </tag>
</tags>
</entry>
<entry>
<title>C#WinForm应用之timer定时器</title>
<link href="/archives/221c258.html"/>
<url>/archives/221c258.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="写在开头"><a href="#写在开头" class="headerlink" title="写在开头"></a>写在开头</h3><blockquote><p>C#Winform窗体应用timer定时器开发记录。</p></blockquote><h3 id="timer事件函数"><a href="#timer事件函数" class="headerlink" title="timer事件函数"></a>timer事件函数</h3><p>timer控件默认是关闭的,我们在点击按钮是开始timer事件</p><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//定义全局变量用来接收计时变量以及停止时间</span></span><br><span class="line"><span class="built_in">int</span> count , time;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> ...</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">timer1_Tick</span>(<span class="params"><span class="built_in">object</span> sender, EventArgs e</span>)</span></span><br><span class="line">{</span><br><span class="line"> count++;<span class="comment">//记录当前秒</span></span><br><span class="line"> progressBar1.Value = count;<span class="comment">//设置进度条进度</span></span><br><span class="line"> label3.Text = (timer -count).Tostring() + <span class="string">"秒"</span> ;<span class="comment">//动态显示计时</span></span><br><span class="line"> <span class="keyword">if</span>(count == time)</span><br><span class="line"> {</span><br><span class="line"> timer1.Stop();</span><br><span class="line"> MessageBox.Show(<span class="string">"时间到了!"</span>,<span class="string">"提示"</span>);<span class="comment">//弹窗提示</span></span><br><span class="line"> Sysetem.Media.SystemSounds.Asterisk.Play();<span class="comment">//系统提示音</span></span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">Button1_click</span>(<span class="params"><span class="built_in">object</span> sender, EventArgs e</span>)</span></span><br><span class="line">{</span><br><span class="line"> <span class="built_in">string</span> str = comBox1.Text;</span><br><span class="line"> progressBar1.Maximum = time ;<span class="comment">//进度条最大值</span></span><br><span class="line"> time = Convert.toInt32(str.Substring(<span class="number">0</span>,<span class="number">2</span>)) ;</span><br><span class="line"> timer1.start();</span><br><span class="line">}</span><br></pre></td></tr></table></figure><blockquote><p>参考串口关闭<br>涉及到的控件、需要注意的东西</p></blockquote>]]></content>
<categories>
<category> 编程语言 </category>
</categories>
<tags>
<tag> C# </tag>
<tag> Winform </tag>
</tags>
</entry>
<entry>
<title>评论系统更改:Valine配置教程</title>
<link href="/archives/2ad55243.html"/>
<url>/archives/2ad55243.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="写在开头"><a href="#写在开头" class="headerlink" title="写在开头"></a>写在开头</h3><p>前不久才将评论从livere换到Twikoo就收到了腾讯云函数收费的通知😵,尝试换用MangoDB+Vercel一直失败,我又没有私人服务器,只能换其他的评论系统了。<br><img src="https://img1.imgtp.com/2022/08/07/bzjbcAUd.png"></p><h3 id="关于Valine"><a href="#关于Valine" class="headerlink" title="关于Valine"></a>关于Valine</h3><p><code>Valine </code>诞生于2017年8月7日,是一款基于<code>LeanCloud</code>的快速、简洁且高效的无后端评论系统。</p><ul><li>官网:<a href="https://valine.js.org/">https://valine.js.org/</a></li><li>Github: <a href="https://github.com/xCss/Valine">https://github.com/xCss/Valine</a></li></ul><h3 id="接入Hexo—-获取APP-ID-和-APP-Key"><a href="#接入Hexo—-获取APP-ID-和-APP-Key" class="headerlink" title="接入Hexo—-获取APP ID 和 APP Key"></a>接入Hexo—-获取<code>APP ID</code> 和 <code>APP Key</code></h3><p>请<a href="https://leancloud.cn/dashboard/login.html#/signin">登录</a>或者<a href="https://leancloud.cn/dashboard/login.html#/signup">注册</a><code>LeanCloud</code>,进入控制台创建应用:<br><img src="https://img1.imgtp.com/2022/08/07/ONgzfvTg.png">你们的页面可能跟我的有出入,因为之前创建的时候,没有验证邮箱。。。。。。创建成功可以直接看到我们创建的应用,点击小齿轮:<br><img src="https://img1.imgtp.com/2022/08/07/Gf9knlei.png"><br>进入设置,基于可以获得需要的<code>APP ID</code> 和 <code>APP Key</code>了。<br><img src="https://img1.imgtp.com/2022/08/07/gO3AU8pX.png"></p><h3 id="修改-config-butterfly-yml文件"><a href="#修改-config-butterfly-yml文件" class="headerlink" title="修改_config.butterfly.yml文件"></a>修改<code>_config.butterfly.yml</code>文件</h3><p><img src="https://img1.imgtp.com/2022/08/07/phEl60Qu.png"><br>然后修改<code>comment</code>值,更多的配置项,请查阅:<a href="https://valine.js.org/configuration.html">配置项 | Valine 一款快速、简洁且高效的无后端评论系统</a>。</p>]]></content>
<categories>
<category> 主题美化 </category>
</categories>
<tags>
<tag> 主题配置 </tag>
</tags>
</entry>
<entry>
<title>Twikoo 评论系统</title>
<link href="/archives/6f83f598.html"/>
<url>/archives/6f83f598.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><div class="note danger simple"><p>文章参考:</p><ul><li><a href="https://twikoo.js.org/">Twikoo官方文档</a></li><li><a href="https://butterfly.js.org/posts/ceeb73f/#%E8%A9%95%E8%AB%96">Butterfly官方配置文档</a></li><li><a href="https://www.nickxu.top/2022/02/19/Hexo-Butterfly-%E5%BB%BA%E7%AB%99%E6%8C%87%E5%8D%97%EF%BC%88%E5%9B%9B%EF%BC%89Twikoo-%E8%AF%84%E8%AE%BA%E7%B3%BB%E7%BB%9F/">Hexo + Butterfly 建站指南(四)Twikoo 评论系统</a></li></ul></div><h3 id="MongoDB"><a href="#MongoDB" class="headerlink" title="MongoDB"></a>MongoDB</h3><p>使用<code>MongoDB数据库</code>来存储数据,注册 <code>MongoDB</code> 账号,创建免费数据库,类型选择<code>Shared</code>,区域选择 <code>AWS / N. Virginia (us-east-1)</code><br><img src="https://img1.imgtp.com/2022/07/31/Ho1PvV8O.png"><br><img src="https://img1.imgtp.com/2022/07/31/nM7ANFzR.png"><br><img src="https://img1.imgtp.com/2022/07/31/psNyhwEl.png"><br>点击<code>Connect</code>按钮, 键入 <code>0.0.0.0/0</code> 以允许所有 IP 地址的连接,并创建数据库用户 ,连接方式选择中间的<code>Connect your application</code><br><img src="https://img1.imgtp.com/2022/07/31/dfjaIL6b.png"><br>复制文中字符串,使用过程中需要将字符串中的<code>password</code>修改为刚才的密码。<br>#Vercle</p><ul><li>注册账号</li><li>点击<a href="https://vercel.com/new/clone?repository-url=https://github.com/imaegoo/twikoo/tree/dev/src/vercel-min">此链接</a>将项目代码部署到你的代码托管网站上去,一般直接选<code>GitHub</code>,新建存储库。<br><img src="https://img1.imgtp.com/2022/07/31/FSPfOK0y.png"></li><li>完成后,在导航栏选择<code>Setting</code>,在左侧选择<code>Environment Variables</code>,添加变量<code>MONGODB_URI</code>,值输入刚才的连接字符串,记得修改<code><password></code>为数据库用户密码<br><img src="https://img1.imgtp.com/2022/07/31/vrDAdb8j.png"><br>因为Vercel没办法从将Twikoo导入到github仓库,等过几天再尝试。</li></ul><h3 id="改用腾讯云函数配置"><a href="#改用腾讯云函数配置" class="headerlink" title="改用腾讯云函数配置"></a>改用腾讯云函数配置</h3><ul><li>参阅官方文档<a href="https://twikoo.js.org/quick-start.html#%E6%89%8B%E5%8A%A8%E9%83%A8%E7%BD%B2">手动部署</a><br>按照教程进行即可配置完全,不再赘述</li><li>环境id在云开发主页可找到</li><li><img src="https://img1.imgtp.com/2022/07/31/KdOkhnxm.png"></li><li>复制环境id,修改butterfly_config.yml文件相关内容即可</li><li><img src="https://img1.imgtp.com/2022/07/31/jMXjw6PO.png"></li><li><img src="https://img1.imgtp.com/2022/07/31/r3oxfZxI.png"></li></ul>]]></content>
<categories>
<category> 主题美化 </category>
</categories>
<tags>
<tag> 主题配置 </tag>
</tags>
</entry>
<entry>
<title>个人图床含泪优化</title>
<link href="/archives/9c513fe1.html"/>
<url>/archives/9c513fe1.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="写在开头"><a href="#写在开头" class="headerlink" title="写在开头"></a>写在开头</h3><p>本篇仅作为个人图传服务器迁移备份的吐槽篇,此外别无他用。想查看图床搭建过程,可以参阅<a href="https://boiledyakult.top/archives/8cf30b70.html">使用Github+PicGo搭建个人图床</a>。额,大抵是这样了。</p><h3 id="图床更换历程"><a href="#图床更换历程" class="headerlink" title="图床更换历程"></a>图床更换历程</h3><p>Github+PicGO &rArr; 国内不挂梯子无法正常加载图片&rArr;七牛云免费存储空间&rArr;七牛云存储空间需要个人域名,因此才注册了自己域名地址&rArr;博客服务器在海外,国内无法备案,而七牛云需要有自己的备案域名&rArr;七牛云提供的一个月默认域名由于域名污染实际访问过程中也无法加载&rArr;尝试国内其他的图床服务:路过图床(加载速度较慢)、免费图床网(偶然点了进去发现可以通过配置PicGO上传图片,除了上传速度略慢一点,但是网站正常显示加载很给力)</p><h3 id="关于七牛云"><a href="#关于七牛云" class="headerlink" title="关于七牛云"></a>关于七牛云</h3><p>关于更换图床地址的想法一直有的,但是因为确实没有目标明确的更换方案,而且更改图传的工程量较大,因为工作的原因,迟迟没有实操。偶然间在Bilili就看有位UP主将Gitee存储的图片转移到七牛云,所以也就试了试。更改过程极为难受,大致流程为将原服务器上的文件下载到本地&rArr;将图片上传到目标服务器上&rArr;然后挨个修改博客中用到的图片地址【我是这样弄得,因为vscode的替换我不知道为什么不能批量替换】&rArr;大概持续了一周多(因为域名注册用了好几天的时间)&rArr;换好链接发现没有备案的域名没办法在七牛云绑定&rArr;寄了</p><h3 id="免费图床网"><a href="#免费图床网" class="headerlink" title="免费图床网"></a><a href="https://www.imgtp.com/">免费图床网</a></h3><p>大概很长一阵子没有维护过博客,因为看到加载不出来的图片着实难受,,,,。逛知乎看到路过图传的推荐,才知道国内也是有提供免费图床存储的,于是开始尝试各类的免费图传,我发现他们大部分界面风格都是差不多的,嘿嘿😅。因为之前一直用PicGO上传图片,用习惯了,所以对于不能使用PicGo的图传我是直接排在第二梯队的,而且每次都需要打开网站上传也太费劲了。不知道怎么点到免费图床网的,好像是因为路过图传上传速度太慢了,远不如之前PicGo上传Github。后面看设置有<code>token</code>,嘿嘿。<br>然后又是换链接,七万五千里长征······<br>用了大概半个多月了,图片加载在我看来还是可以的,虽然首次访问还不能做到秒加载吗,不过也可以了,哈哈哈。<br>至此,图床告一段落。</p>]]></content>
<categories>
<category> 图床搭建 </category>
<category> 主题升级 </category>
</categories>
<tags>
<tag> 个人图床 </tag>
<tag> 主题优化 </tag>
</tags>
</entry>
<entry>
<title>Rainmeter桌面</title>
<link href="/archives/3af72432.html"/>
<url>/archives/3af72432.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h2 id="什么是Rainmeter"><a href="#什么是Rainmeter" class="headerlink" title="什么是Rainmeter"></a>什么是Rainmeter</h2><p>&ensp; &ensp; <a href="https://tieba.baidu.com/p/6729434390#">基本内容和常见问题贴</a><br>&ensp; &ensp; 简单的说,Rainmeter是一款可以让您在桌面上放置类似 “Windows 7桌面小工具”一样的组件的桌面美化软件。不过,相比于数量少、功能单一,已被微软放弃维护的Windows 7桌面小工具,Rainmeter的可玩性极高。<br>&ensp; &ensp; Rainmeter能做什么?它的全部功能,就是布置装饰桌面的组件,这一个个的组件在Rainmeter中被称为“皮肤”。不过这些皮肤能做什么呢?除了单纯的装饰的皮肤外,有的可以调用显示系统信息,有的可以打开或者控制其它应用程序,有的可以展示系统目录结构和信息,有的可以捕获网页的信息……<br>&ensp; &ensp; Rainmeter不能做什么?Rainmeter只能在现有系统外观基础上加以修饰,而不能更改。因此Rainmeter不能改变系统的主题,不能改变开始菜单样式,不能改变任务栏样式,不能改变开机动画,不能额外增加受它控制应用的功能等等。因此如果有类似这样的需求,您还需要其他软件帮助。</p><h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><p>&ensp; &ensp; Rainmeter是一款开源软件。其官网可以获取到最新的Rainmeter软件。您可以根据自己偏好选择正式版(Final Release)或者测试版(Beta Release)。</p><h2 id="资源文件"><a href="#资源文件" class="headerlink" title="资源文件"></a>资源文件</h2><p>链接:<a href="https://pan.baidu.com/s/1EXJt7GEOlgcbcNaR9EowOQ?pwd=6g2n">https://pan.baidu.com/s/1EXJt7GEOlgcbcNaR9EowOQ?pwd=6g2n</a><br>提取码:6g2n</p><h2 id="桌面预览"><a href="#桌面预览" class="headerlink" title="桌面预览"></a>桌面预览</h2><p>![](<a href="https://img1.imgtp.com/2022/07/20/hLjIxuPR.png">https://img1.imgtp.com/2022/07/20/hLjIxuPR.png</a></p>]]></content>
<categories>
<category> 随机日记 </category>
</categories>
<tags>
<tag> 桌面美化 </tag>
<tag> 好物推荐 </tag>
</tags>
</entry>
<entry>
<title>SEO优化以及站点收录</title>
<link href="/archives/60822be1.html"/>
<url>/archives/60822be1.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>博客网站的各大搜索引擎(百度、必应、谷歌)推送已基本完成,因为之前的笔记本没带这,所以过阵子更新教程。</p><blockquote><p>来咧,本篇记录一下收集整理关于博客被百度、谷歌等搜索引擎收录的过程,至于一些Hexo的知识操作,请自己百度,主要涉及sitemap自动提交和npm安装。<br>SEO(search engine optimization),搜索引擎优化,是一种通过了解搜索引擎的运作规则来调整网站,以及提高目的网站在有关搜索引擎内排名的方式。<br>先给大家看一下效果:<br><img src="https://s.imgkb.xyz/abcdocker/2022/08/14/3247b4a54c505/3247b4a54c505.png"></p></blockquote><h3 id="安装sitemap"><a href="#安装sitemap" class="headerlink" title="安装sitemap"></a>安装sitemap</h3><p>Google:<br><code> hexo-generator-sitemap --save</code><br>Baidu:<br><code> hexo-generator-baidu-sitemap --save</code></p><blockquote><p>sitemap:一种文件,通过改文件列出网站上的网页,将网站的内容框架告知Google等搜索引擎,Googlebot等抓取工具会读取此文件,以便更智能地抓取网站。</p></blockquote><h3 id="hexo配置文件"><a href="#hexo配置文件" class="headerlink" title="hexo配置文件"></a>hexo配置文件</h3><ol><li>修改博客根目录<code>_config.yml</code>,修改以下配置以生成相应的xml文件: <figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 站点地图</span></span><br><span class="line"><span class="attr">sitemap:</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">sitemap.xml</span></span><br><span class="line"><span class="attr">baidusitemap:</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">baidusitemap.xml</span></span><br></pre></td></tr></table></figure></li><li>修改文章链接,找到<code>permalink</code>配置项,优化链接形式<br> hexo默认的文章链接规则是按照年月日、标题来生成地。一旦文章标题或者发布时间被作者修改,对应页面地URL也会发生变化,那之前的文章地址就变成了404,而且URL层级很深,不太适合提交引擎收录。而且,如果页面的标题是中文地话,转码会很长很长(特别长地那种😅)。<br> 2.1 Hexo-abbrlink<ul><li>链接优化的教程很多,这里给出我自用的一种。</li></ul><p> <code>npm install hexo-abbrlink --save</code></p><ul><li>修改<code>permalink</code>:<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">url:</span> <span class="string">https://boiledyakult.top</span></span><br><span class="line"><span class="attr">permalink:</span> <span class="string">archives/:abbrlink.html</span></span><br><span class="line"><span class="attr">abbrlink:</span></span><br><span class="line"> <span class="attr">alg:</span> <span class="string">crc32</span> <span class="comment"># 算法:crc16(default) and crc32</span></span><br><span class="line"> <span class="attr">rep:</span> <span class="string">hex</span> <span class="comment"># 进制:dec(default) and hex</span></span><br><span class="line"><span class="attr">permalink_defaults:</span></span><br><span class="line"><span class="attr">pretty_urls:</span></span><br><span class="line"> <span class="attr">trailing_index:</span> <span class="literal">true</span> <span class="comment"># Set to false to remove trailing 'index.html' from permalinks</span></span><br><span class="line"> <span class="attr">trailing_html:</span> <span class="literal">true</span> <span class="comment"># Set to false to remove trailing '.html' from permalinks</span></span><br></pre></td></tr></table></figure>不同算法和进制会生成不同的格式:<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">crc16</span> <span class="string">&</span> <span class="string">hex</span></span><br><span class="line"><span class="string">https://post.zz173.com/posts/66c8.html</span></span><br><span class="line"><span class="string">crc16</span> <span class="string">&</span> <span class="string">dec</span></span><br><span class="line"><span class="string">https://post.zz173.com/posts/65535.html</span></span><br><span class="line"></span><br><span class="line"><span class="string">crc32</span> <span class="string">&</span> <span class="string">hex</span></span><br><span class="line"><span class="string">https://post.zz173.com/posts/8ddf18fb.html</span></span><br><span class="line"><span class="string">crc32</span> <span class="string">&</span> <span class="string">dec</span></span><br><span class="line"><span class="string">https://post.zz173.com/posts/1690090958.html</span></span><br></pre></td></tr></table></figure></li><li>然后hexo三件套,clean—-generate—-serve,在每篇文章中fonter添加一条命令:<figure class="highlight plaintext"><figcaption><span>8da2c4c2```建议添加在post配置里面。这个值我记不清楚是自动生成的还是每个人都不一样,建议自己查查资料哈。</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">3. 添加蜘蛛协议"robots.txt"</span><br><span class="line"> 在博客根目录```source```,添加协议文件,自己新建一个就可以</span><br><span class="line"> ```yml</span><br><span class="line"> User-agent: *</span><br><span class="line"> Allow: /</span><br><span class="line"> Allow: /categories/</span><br><span class="line"> Allow: /tags/</span><br><span class="line"> Allow: /archives/</span><br><span class="line"> Allow: /about/</span><br><span class="line"></span><br><span class="line"> Disallow: /vendors/</span><br><span class="line"> Disallow: /js/</span><br><span class="line"> Disallow: /css/</span><br><span class="line"> Disallow: /fonts/</span><br><span class="line"> Disallow: /vendors/</span><br><span class="line"> Disallow: /fancybox/</span><br><span class="line"></span><br><span class="line"> # 记得替换成你的域名</span><br><span class="line"> Sitemap: https://boiledyakult.top/sitemap.xml</span><br><span class="line"> Sitemap: https://boiledyakult.top/baidusitemap.xml</span><br></pre></td></tr></table></figure><img src="https://s.imgkb.xyz/abcdocker/2022/08/14/b11bfde8069f5/b11bfde8069f5.png"></li></ul></li></ol><h3 id="主动推送"><a href="#主动推送" class="headerlink" title="主动推送"></a>主动推送</h3><p>新链接主动推送给百度,需要注册百度账号在百度站长工具拿到权限token</p><ol><li>安装插件:<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment"># 会生成baidu_urls.txt目录</span></span><br><span class="line">npm install hexo-baidu-url-submit --save</span><br></pre></td></tr></table></figure></li><li>在根目录<code>_config.yml</code>添加以下内容:<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment"># 主动推送百度,被百度收录</span></span><br><span class="line"><span class="attr">baidu_url_submit:</span></span><br><span class="line"> <span class="attr">count:</span> <span class="number">100</span> <span class="comment"># 提交最新的10个链接</span></span><br><span class="line"> <span class="attr">host:</span> <span class="string">https://boiledyakult.top</span> <span class="comment"># 百度站长平台中注册的域名</span></span><br><span class="line"> <span class="attr">token:</span> <span class="string">8c..............GA</span> <span class="comment"># 秘钥,百度站长平台 > 推送接口 > 接口调用地址中token字段</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">baidu_urls.txt</span> <span class="comment"># 文本文档的地址, 新链接会保存在此文本文档里,不用改</span></span><br></pre></td></tr></table></figure></li><li>域名和token都可以在站长工具平台找到,<a href="https://ziyuan.baidu.com/dashboard/">站点信息</a><br> <img src="https://s.imgkb.xyz/abcdocker/2022/08/14/ebdafa4afc91e/ebdafa4afc91e.png"></li></ol><h3 id="百度收录"><a href="#百度收录" class="headerlink" title="百度收录"></a>百度收录</h3><blockquote><p>站点管理——-> 添加网站———>属性———->认证<br><img src="https://s.imgkb.xyz/abcdocker/2022/08/14/7c9033ec04dc4/7c9033ec04dc4.png"><br><img src="https://s.imgkb.xyz/abcdocker/2022/08/14/fab5d39fa297b/fab5d39fa297b.png"></p></blockquote><ul><li>CNAME验证:在DNS添加一条解析记录<table><thead><tr><th align="left">主机记录</th><th align="center">记录内容</th><th align="right">记录值</th></tr></thead><tbody><tr><td align="left">www</td><td align="center">CNAME</td><td align="right">CNAME验证值</td></tr></tbody></table></li><li>文件验证:下载认证文件,放在根目录,然后<code>hexo d</code>上传到服务器上,这里需要注意的是需要在文件中添加<code>layout: false</code>防止被转换。</li><li>HTML验证:</li><li><img src="https://s.imgkb.xyz/abcdocker/2022/08/14/cbe8bec78e761/cbe8bec78e761.png"><br>最后在<code>config_yml``````deploy:</code>上添加以下内容:<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="bullet">-</span> <span class="attr">type:</span> <span class="string">baidu_url_submitter</span></span><br></pre></td></tr></table></figure></li></ul><h3 id="Googles收录"><a href="#Googles收录" class="headerlink" title="Googles收录"></a>Googles收录</h3><p>和百度大差不差,安装sitemap,生成sitemap.xml,在谷歌站长平台验证抓取域名,见上图HTML验证<br><img src="https://s.imgkb.xyz/abcdocker/2022/08/14/307fe67937bf2/307fe67937bf2.png"><br><img src="https://s.imgkb.xyz/abcdocker/2022/08/14/851b8601a3aa4/851b8601a3aa4.png"></p><h3 id="Biying收录"><a href="#Biying收录" class="headerlink" title="Biying收录"></a>Biying收录</h3><p>可以先设置号谷歌配置之后,直接选Google验证链接:<img src="https://s.imgkb.xyz/abcdocker/2022/08/14/530254888b812/530254888b812.png"><br>也可以跟谷歌一样再走一遍。</p><h3 id="Baidu-Done-、Biying-Done、Google-Done"><a href="#Baidu-Done-、Biying-Done、Google-Done" class="headerlink" title="Baidu Done 、Biying Done、Google Done"></a>Baidu Done 、Biying Done、Google Done</h3><p>差不多这里就已经配置好了,谷歌大概两三周就可以搜到自己的文章了,必应也是,百度就不好说了。</p><blockquote><p>添加完成以后建议手动去各大搜索引擎提交一下站点地图<br><img src="https://s.imgkb.xyz/abcdocker/2022/08/14/29fbfe7fa87e2/29fbfe7fa87e2.png"></p></blockquote>]]></content>
<categories>
<category> HEXO </category>
<category> SEO优化 </category>
</categories>
<tags>
<tag> Hexo设置 </tag>
<tag> 搜索引擎收录 </tag>
</tags>
</entry>
<entry>
<title>C#入门基础知识</title>
<link href="/archives/6ad93d68.html"/>
<url>/archives/6ad93d68.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>如题,对博主学习C#编程语言做个笔记,因为大学期间学习过C#,本篇只做简单记录。</p><h1 id="开发环境"><a href="#开发环境" class="headerlink" title="开发环境"></a>开发环境</h1><p>vs2017</p><h1 id="计算机结构"><a href="#计算机结构" class="headerlink" title="计算机结构"></a>计算机结构</h1><p>可以简单理解为</p><ul><li>输入设备</li><li>控制器:控制程序执行</li><li>运算器</li><li>存储器</li><li>输出设备<br><img src="http://reuvza1fi.hb-bkt.clouddn.com/img/20220625221359.png"></li></ul><h1 id="Hello-World"><a href="#Hello-World" class="headerlink" title="Hello World"></a>Hello World</h1><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">namespace</span> <span class="title">Examples</span></span><br><span class="line">{</span><br><span class="line"> <span class="keyword">class</span> <span class="title">Program</span></span><br><span class="line"> {</span><br><span class="line"> <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">Main</span>(<span class="params"><span class="built_in">string</span>[] args</span>)<span class="comment">//程序开始执行的地方</span></span></span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">string</span> inputStr = <span class="literal">null</span>;<span class="comment">//定义变量并赋值,告诉计算机分配多大的存储空间</span></span><br><span class="line"> inputStr = Console.ReadLine();<span class="comment">//ReadLine()读取数据</span></span><br><span class="line"> <span class="built_in">string</span> outputStr = <span class="string">"Hi,"</span> + inputStr;</span><br><span class="line"> Console.WriteLine(outputStr);</span><br><span class="line"> Console.ReadKey();<span class="comment">//让DOS窗口接收一个字符才会退出。</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h1 id="关键字、命名规则"><a href="#关键字、命名规则" class="headerlink" title="关键字、命名规则"></a>关键字、命名规则</h1><p><a href="https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/">C#关键字</a><br>命名规则:</p><ul><li>不能使用关键字</li><li>开头第一个字母只能是字母或者_,后面可以跟数字、字母、_,不能出现空格、运算符、标点符号等</li><li>区分大小写</li><li>不能与关键字相同<br><a href="https://www.jianshu.com/p/dc26cb8ffcb9">具体命名规范</a></li></ul><h1 id="存储单位"><a href="#存储单位" class="headerlink" title="存储单位"></a>存储单位</h1><ul><li>1 Bit(位)表示0或1 (对应计算机硬件的基础存储单位)</li><li>1 Byte(字节)=8 Bit (2^8=256)</li><li>1 B =8 b</li><li>1024 = 2^10</li><li>1KB(Kilobyte,千字节)=1024B</li><li>1MB(Megabyte,兆字节)=1024KB</li><li>1GB(Gigabyte,吉字节,千兆)=1024MB</li><li>1TB(Trillionbyte,万亿字节,太字节)=1024GB</li></ul><h2 id="各类型变量字节大小"><a href="#各类型变量字节大小" class="headerlink" title="各类型变量字节大小"></a>各类型变量字节大小</h2><ul><li><code>int</code> 4字节(Byte)32位 有符号整数,可以定义为负数 -2147483648到2147483647</li><li><code>uint</code> 4字节 0-4294967295 0和整数,不能表示负数</li><li><code>float</code> 4字节</li><li><code>double</code> 8字节</li><li><code>bool</code> 由编译器决定</li><li>其他 <code>sbyte,short,long,ushort,ulong</code> <code>8,16,64,64</code></li><li><code>char</code> 2字节 ‘a’,’急’;<code>char valChar = 'z' ;</code></li><li><code>string</code> 由多个char组成,<code>string valString = "要吃就莱。";</code><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"> <span class="built_in">string</span> valStr = <span class="string">"Hello,BoiledYakult"</span>;</span><br><span class="line"><span class="comment">// 0123456789...下标从0开始</span></span><br><span class="line"> <span class="built_in">int</span> length = valStr.Length;<span class="comment">//字符串长度lengeh=18</span></span><br><span class="line"> <span class="built_in">int</span> index = valStr.IndexOf(<span class="string">"Boiled"</span>);<span class="comment">//查找字符串中第一个匹配项的从零开始的索引,index=6</span></span><br><span class="line"> <span class="built_in">string</span> strResult = valStr.Replace(<span class="string">"hello"</span>, <span class="string">"Preditor"</span>);<span class="comment">//替换字符串</span></span><br><span class="line"> <span class="built_in">string</span> subStr = valStr.Substring(<span class="number">7</span>, <span class="number">2</span>);<span class="comment">//截取BoiledYakult</span></span><br></pre></td></tr></table></figure></li><li><code>M[]</code>数组,存储多个M类型数据,eg:<code>int[] ary=new int[10];</code><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ary[<span class="number">0</span>]=<span class="number">3</span>;</span><br><span class="line"><span class="built_in">int</span> intVal=ary[<span class="number">3</span>];</span><br><span class="line"><span class="comment">//长度ary.Length</span></span><br></pre></td></tr></table></figure></li></ul><h2 id="类型转换"><a href="#类型转换" class="headerlink" title="类型转换"></a>类型转换</h2><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">double</span> valDoule = <span class="number">6.28</span>;</span><br><span class="line"><span class="built_in">float</span> valFloat = (<span class="built_in">float</span>)valDoule;<span class="comment">//显式类型转换【高精度转换为低精度-强制类型转换】</span></span><br><span class="line"><span class="built_in">double</span> valDouble2 = valFloat;<span class="comment">//隐式类型转换</span></span><br><span class="line"><span class="built_in">int</span> valInt = (<span class="built_in">int</span>)valFloat;<span class="comment">//valInt=6</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//数值类型和string类型转换</span></span><br><span class="line"><span class="built_in">string</span> valStr2 = <span class="string">"5"</span>;</span><br><span class="line"><span class="built_in">int</span> valInt2 = <span class="built_in">int</span>.Parse(valStr2);</span><br><span class="line"><span class="built_in">long</span> valLong = <span class="built_in">long</span>.Parse(valStr2);</span><br><span class="line"><span class="built_in">string</span> valStr3 = valLong.ToString();</span><br><span class="line">Console.WriteLine(subStr);</span><br></pre></td></tr></table></figure><h1 id="自增-amp-amp-字符串格式化"><a href="#自增-amp-amp-字符串格式化" class="headerlink" title="自增&&字符串格式化"></a>自增&&字符串格式化</h1><ul><li>自增自减<ul><li>++i // i=i+1;return i;</li><li>i++ // int r=1; i=i+1; return r;<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">int</span> valInt = <span class="number">4</span>;</span><br><span class="line"><span class="built_in">int</span> postInt = valInt++;<span class="comment">// postInt = 4; valInt = 5;</span></span><br><span class="line">valInt = <span class="number">4</span>;</span><br><span class="line"><span class="built_in">int</span> perInt = ++valInt;<span class="comment">// PostInt =5;valInt = 5;</span></span><br><span class="line"></span><br><span class="line">valInt = <span class="number">4</span>;</span><br><span class="line"><span class="built_in">int</span> postDec = valInt--;<span class="comment">// postDec = 4; valInt = 3;</span></span><br><span class="line">valInt = <span class="number">4</span>;</span><br><span class="line"><span class="built_in">int</span> perDec = --valInt;<span class="comment">// PostInt =3;valInt = 3;</span></span><br></pre></td></tr></table></figure></li></ul></li><li>+= -=<ul><li>a += b; == a = a+b;</li><li>a -= b; == a = a-b;</li></ul></li><li>字符串内插$”info = {a}”<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">int</span> result =<span class="number">3</span>;</span><br><span class="line"><span class="built_in">string</span> inputStr = <span class="string">"val"</span>;</span><br><span class="line"><span class="built_in">string</span> str1 = intputStr+ <span class="string">"的计算结果为:"</span> + result;</span><br><span class="line"><span class="built_in">string</span> str2 = <span class="string">$"<span class="subst">{inputStr}</span>的计算结果为:<span class="subst">{result}</span>"</span>;</span><br></pre></td></tr></table></figure></li></ul><h1 id="函数"><a href="#函数" class="headerlink" title="函数"></a>函数</h1><ul><li>返回值类型 函数名(参数列表){任意条指令;return 返回值;}<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">PrintHelloworld</span>()</span></span><br><span class="line">{</span><br><span class="line"> Console.Write(<span class="string">"HelloWorld!"</span>);</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">PrintValue</span>(<span class="params"><span class="built_in">string</span> val</span>)</span></span><br><span class="line">{</span><br><span class="line"> Console.Write(val);</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="built_in">float</span> <span class="title">MulAdd</span>(<span class="params"><span class="built_in">float</span> val1,<span class="built_in">float</span> val2,<span class="built_in">float</span> addNum</span>)</span></span><br><span class="line">{</span><br><span class="line"> <span class="keyword">return</span> val1*val2+addNum;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="built_in">float</span> mul1 = <span class="number">3</span>;</span><br><span class="line"><span class="built_in">float</span> mul2 = <span class="number">100.5f</span>;</span><br><span class="line"><span class="built_in">float</span> add1= <span class="number">32</span>;</span><br><span class="line"><span class="built_in">float</span> result = MulAdd(mul1,mul2,add1);</span><br><span class="line">PrintValue(<span class="string">"Result: "</span>);</span><br></pre></td></tr></table></figure><img src="https://img1.imgtp.com/2022/07/20/F01poCqX.png"></li><li>减少重复代码</li><li>封装实现细节</li></ul><h1 id="简单案例"><a href="#简单案例" class="headerlink" title="简单案例"></a>简单案例</h1><ul><li>加法计算器:从控制台输入你想计算的公式3+5.要求中间不能有空格<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">Console.WriteLine(<span class="string">"请输入加法算术题,按回车结束"</span>);</span><br><span class="line"><span class="comment">//52+468</span></span><br><span class="line"><span class="comment">//012345</span></span><br><span class="line"><span class="built_in">string</span> inputStr = Console.ReadLine();</span><br><span class="line"><span class="built_in">int</span> plusIdx = inputStr.IndexOf(<span class="string">"+"</span>);<span class="comment">//查找加号运算符位置</span></span><br><span class="line"><span class="built_in">string</span> numStr1 = inputStr.Substring(<span class="number">0</span>, plusIdx);<span class="comment">//截取从位置0到加号运算符之间的第一个加数</span></span><br><span class="line"><span class="built_in">int</span> strLen = inputStr.Count();<span class="comment">//计算输入字符串的长度</span></span><br><span class="line"><span class="built_in">string</span> numStr2 = inputStr.Substring(plusIdx + <span class="number">1</span>, strLen - plusIdx - <span class="number">1</span>);<span class="comment">//截取加号运算符后面的被加数</span></span><br><span class="line"><span class="built_in">float</span> num1 = <span class="built_in">float</span>.Parse(numStr1);<span class="comment">//强制类型转换,将获取的加数和被加数字符串转换成浮点类型</span></span><br><span class="line"><span class="built_in">float</span> num2 = <span class="built_in">float</span>.Parse(numStr2);</span><br><span class="line"><span class="built_in">float</span> sum = num1 + num2;</span><br><span class="line">Console.WriteLine(inputStr + <span class="string">" = "</span> + sum);</span><br></pre></td></tr></table></figure></li></ul><h1 id="Bool-比较"><a href="#Bool-比较" class="headerlink" title="Bool 比较"></a>Bool 比较</h1><p><code>< > <= >= == !=</code></p><h1 id="Bool-组合"><a href="#Bool-组合" class="headerlink" title="Bool 组合"></a>Bool 组合</h1><ul><li>非<ul><li>!对一个值取反,<code>!true==false</code> <code>!!false=false</code></li></ul></li><li>且<ul><li><code>a && b</code> 仅在两边都为true时返回值为true</li></ul></li><li>或<ul><li><code>a || b</code>有一个true就返回true,都为false时返回false</li></ul></li></ul><h1 id="条件语句"><a href="#条件语句" class="headerlink" title="条件语句"></a>条件语句</h1><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">tring title = <span class="string">""</span>;</span><br><span class="line"><span class="built_in">string</span> gender = Console.ReadLine();</span><br><span class="line"><span class="keyword">if</span> (gender==<span class="string">"男"</span>)</span><br><span class="line">{</span><br><span class="line"> title = <span class="string">"帅哥"</span>;</span><br><span class="line">}</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">{</span><br><span class="line"> itle = <span class="string">"女"</span>;</span><br><span class="line">}</span><br><span class="line">Console.WriteLine(<span class="string">$"这位<span class="subst">{title}</span>,要吃就莱!"</span>);</span><br><span class="line"><span class="comment">//$ 特殊字符将字符串文本标识为内插字符串 。 </span></span><br><span class="line"><span class="comment">//内插字符串是可能包含内插表达式的字符串文本 。 </span></span><br><span class="line"><span class="comment">//将内插字符串解析为结果字符串时,带有内插表达式的项会替换为表达式结果的字符串表示形式。</span></span><br><span class="line"><span class="comment">// 从 C# 6 开始可以使exit用此功能。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//字符串内插为格式化字符串提供了一种可读性和便捷性更高的方式。 它比字符串复合格式设置更容易阅读。 </span></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 编程语言 </category>
</categories>
<tags>
<tag> C# </tag>
</tags>
</entry>
<entry>
<title>嵌入式开发面试</title>
<link href="/archives/14a0773e.html"/>
<url>/archives/14a0773e.html</url>
<content type="html"><![CDATA[<div class="hbe hbe-container" id="hexo-blog-encrypt" data-wpm="Oh, this is an invalid password. Check and try again, please." data-whm="OOPS, these decrypted content may changed, but you can still have a look."> <script id="hbeData" type="hbeData" data-hmacdigest="851e0d4b07ff4fdb719369e587a571699254fc5c602ee461728342ecbe883fa1">cf51ec27e5a5bc23be1ea42d8109209592644360151afa57f1cacbebd07e64a58f4759db489eb2759dd8a049b977d55e7ba446a3713bb018c88df5b0499fcd3ade6e6b3fda238aa197f3c42ac93adeb4e59a55c0fb9822a80b803043e3b1b0bbf2ae3151c6d11e4428e5a40e36e6710bf302c8e1d59fd799901f587a5c07fd12d6de08ae9e129cb3a20dcb6f3c8799d2421e91ba57ec3ebcf86328cac691cc2ffc26891ab28f8a51ea07d2814cd10484d7552fc2a534e6a1f1802d0689c9359a8d8305aa81ff91410c3618c0af630153ad826fb14bc9516fa940ee6d2beb0bba764182e9fbb7800ee0995f3e1a5eb72233a602515613bd32fb72bf00d694814deeff9a6f176c62360fe6b77f439b5e2ea197bfaebe33a9f524d9b92f758051f860e7634e65c6acf557da26e500b80d565bfb574441da683306cb41a81171f1d28792d23cec1593d367b346a3f870036add24b4853da8fb12bdaf248822589c9559f837d8862b6706fd76152a6d691da4bed4b04e6fdc3b6db9da174aecf7ec77159615e1430fcd4255a0884087c21afebd6ab996464a29dd5226a260da9729635a04208e23a1e521ec656eaa4cdfa89a780b7c356a23442ecd5ea54cfefc4ff772744029201c7ffa1d0a7ec1c3cb74e332211a5c7028401944a634e96ebdd6c088e01dfd8de367cc03a27d61e4e7c5d5d0c6ee3505ee2e31dcf0eefabcf6fba40673a5afb747836c105a810de359dbf6aa0904d312f0d2a0101c630645d7e8d8e0b6052b17cd0136e8519270245094b7ed5a2845edbe7132052aba68543d1a67e858ff61441a552f93cea72bb59cc98e6aa22596f39cdc24ec01a2dc24a5e0f56c990951d3844d9e18ae6d45839d3a1ddcc46ef85596ac6ad7a5d557e4517727c97e7090a4440d3269b1c2a0da9345ce7c17cadf347b9ae5491a7bb0417c25cdea8661ad990afa3eb8ce1f7ec375c0ce661fd4bb09a31216a69c05bc213109cab66a7bdcbf9dbc337817b4b707ac8a8a2ec51cbbeb68aa44b68394eba572a0e45e08c05aa838347e19f279667d9b5d45760ed8b60c68502fe262c21d7276c2c00699c2b362aacdd562fab604f22b4fcd732bfff749559a777c76cfbb856c7d473b052442bdc5e4cb672b89f752f2d9eca9ee6836351077e6836cbde36866d826d762604750665b7ca708c329c50ea3ae37469b5277225208d969b4731ab43cd26c3d28b03ec3660d51b23544718ccf46ac6b4d93f63e2ff4bb80b435a3e6893265141444c22e544be3380f4177be9fd4214e5f59a10ace550f5526fabf22efff674a70a9438e403791e9857152161cba7809bccd570e9514cbc123adf9057eb8f0228bd476005e1ab7b9c7a405cdb8d612d49256f0e2c6cc99d0de571767e7ab8d98209ae1b102209bca39035a28d78872f01e6a02de4740b23587b048457d8e1504adb1a11ef5625823de48b92d06371ac8dc53e49a02dcd8efa725bc22806356776fdd3d7e40bd5ef6e46d4754cf6565395693af9083b9ffa1d8e824d80a69bc1acb48056bc8f148ff3a4bd7f9cf14764e63c4f48b6b9ef6ded1793c8f3510a2751b626236e05480fe44f5d9822a8d135900ede246a6d1c578ff3d1422681361d2556ca9690ab31e91a9c43c6b908098c9d7084793aa2e1d0bf38a6f79bff8e9c1f71fbc603d55992dbdd98e230ce71215a4771082c37ab924ba39ece5257201f2843b825b36bd6b2407b98d4ad446cff50be8574eb5e94313e48247897c274c2df4c76a9ff691f7747692ebf6b949bb7790ffb6c1a8e1f689c9639fd1059708c559063784f0fdbf187e3277eb2adbae5f39155bd6ae1194579046e8af973b2121d7124147c300be2ea1f7a91241f7b6b56a44e98144d2c91f25f18721949bb43d6f09c85133d593b7d91ac7e714544685c48d44a89908878c8ed36dfb3ef39333f301eea098a96f26ab1ee8af4cdb63ab66f5ef9d3fd9a26e0b8e2b0795a96d56775fcdf797e0f5010150a3170bcee8b6cafd97d07c03acd3de786deea2936090f5d22f258b516cb700c42527261fe0e6cc17c0551e983fb2683d9001aa33999936e0fc0baade66868087ce2c4e1da7f972152fef176d9c9c1536c28fbfe1d197a0efc999bdf04fef9090d2b6917d2f64f5a8304c2498b42a68d60bad93fdd9c65e308504ef266081798d87030760684e6eaf3d240a7147165c044a8de34f6df65476a4e4321e4394a757d54735a210c0265578574718f56327cc73870ec27b9b01652210281426d440bd88e5711fa9b4ca776646c3d4447d0d8e60c79aedcf45db4f123026e1fbd08cec9df86ae2fed5ded8a2762fe8b213c8f82e7a3279b0da902cf96ebaa2294bb9608fae05feef03b1808c87d117b7b2df1f039b6c552af4c9781ee46669289f312b626d724abacaea92ed18a9a6c6aafd28a03719aba390989ecca4e87e8ef30552830585c06cac70f89a2097a7505112d65e377c572c80177214ddd056417e2888e3c79063fae4e54bdc7b5aead2ee3dff7b06207aeca5530cb58ca01f2fa0302757fb93dfe36f9e8c6aa5ea2efa57fcec459eb5dd3389f9c2bd7be2b258a881ed54d33bae50ddc58fe16cb90d53fe6cbc710b0d41cec8b0488dac907f924fe3ebbefff7320673b990e23085a968fbb8321541d49c917a7badd1fe7cc2df38dc7e9df1871b903956a37007c17ae61389162b008eb57b434da9d64e358373d947533e3464b81ea069c806045e835ec10e2379e82e8c454ce9ae59c9943a38d705f2405810fb238a1d9088dadced5dcde2ae10169b29ee2f745abb29fe52d76a7739f3345d1c528490de4aaf1bd07ca0cefc35f15316327add1afa51d7c1d1a6e55696821751296f59b6e07e3f5800d0a7c94a0b6751f00aa209fc34a3293bce3844363e51b2d3dd339eeeefbf2c45354557b67b5de04900c08d06f9235f6f4d47a3c0e10fa05008db69320404be1cd415175ad04171c083f5a110b4ffe4d8997452786ec4b1e9f261c4ab582f72e70cc9269c809694222d2192de0c929bca82d5309e68e8a75516212fc9ba09a79ae03162c618a149fb0154a1efb8ac15634941685d30c20b1d28e2fe88097dce615d8b6ea9c097d64d78ad4b397d5d5a4bd2f478f74035a9709e533652f6e0e71af6a74cf61b9f1fea3a64098a6bbf99b63096b7f7b9ab31b5eb7cfc92b8152a9127286977331dd7c89acd5271fad4b3200be4c685a6e8b234ad6aeba75eb957499c7de9d19552c1276cdbb364950c6ee0c594332b0d7e7cb206d7071f46fdba2dba8ce189118d8af376b1d4a4d7d5736e8197a2315d36ab0f9a9eb3cd069065fcb98f5e8a9b9c46263485f4ab6be8a531b6617dde0738ce8f13f46767f74a081fcd276fd9d5ace290e410239ada6c819466d4f69f4f44e7eb206b70ce4d202b9c0810cb2514b67cadaedcfc5b87f6954ae5b5ba1210a5e97789624a0197d38ca0c8a001ee062062063377a850bd46e0c0009d1ce017b52148e9015086fc7f6a4a4c93ac235afc6c50ca714d10f5f59f7110b25f114673ed0ab247bcc52fc0745a792b370095d1bd7e5fd9c5fb28503d8f95c2ea237ae99f5fa600e1a2a5a7aa9e337732dbfe99dd363b50a1eb9574ef26764d3563c0802e8972853b8e33d886d10f565eb9b73e618051e546c41222ce79e18383bcd1ee1df3cd16835ecae4ede2e0c86bc732a2e7187b7dca68dab10188e0d55935e98f52317a29b6406c93b1253d6d13bb0f9e55f646bb5cf47b91216952378947d31b56141fee2f77bf489ad9bcdc48cc9b5834cb77080ccf6235cbea6fdf1f740fbc3de6c31103ef2ddc14eb2a911dd39057d5f4c07346996ad2ece1bfb9f76f84de88e9ecebf5b7f4042a2f0a8708e54c04db05049bdcf12ba6d8c37ed70e112be937ac0c0975ac75dafc41cfa65227740db0dd15476d4c77870ad49f39537407c7fe07f927b8d289bb6e76069cc9c08eef09035fc08421ab72668b6ca1ef6b5a7c1045ea7952b93cfe7df142ed946917aef2134091ad78771070806cc938c5c7b7d86de7dda44c45b9993ba1b29ad7377518e2e0ab4384cc7b585c895192dcaeaaa0daad0be659994365e519d9a10d01b912aef8c001899671b1f2fe3bf95cab9f10d4bb9469a740cd6d2bc15e0f92286f1b00954ddf6c088bf8294e7e80dfe287c35ee4479327aa7e2c19ddc61b7dd3acf530a1af065abfaed99429cde3d122e10995ac5830b5931b9cc0b08117604accbe99d792de5e5bb27518809c3ba565f63bd8b486e2a56f9496352cb542556fa1b98f256a225fe382bac405de9746a1d38ace9662288775e0644f798af449785ddd3f08caa431c5b34fb34750dbdcf2afa38177484eb38170f2a0be5a84cbf952fbc21b6f45dda600dd4e4795285e1513835fe320cf8534316469668e89015bf74c495fd0da8472fe7ef1e11b8d40860975def84d2867efb8d62d0a885339f8f1a511603f83fddd286a4bef7ee9f9cdbca01565a545e4eaf7222244c9aa2b8893cec119351be39f1b1aca4b4b66489c50fc739455954be29157037e93a20a38b73eeadbcb6554641cd8a4ea7da567a6b8d201badb0312c4b0a3ca7468c6041091170de8cb0bab9cb06f499ce05548c788be8caadcb72cfbe5030c2e409230a51f04d632f0560695330f6d16ed95526ff125ae0d891c07582dde83f0ed11a28e3ce39e7199d34b514401daa61f5b025d41d93b5fb470908fe128dff2fa44916701468cbc70f8af653effe6e82ab2ec6003004af5193b495780f2d0d4f18f636089957a8d32a1dc8d264c2507c9aa02ba5bc656344c2430e81777dda7fd5f218888eb5fa246b763a3ddd26200ce9703ed475a0676dda28bdeda55a2780bcf36c7c954ac9f640d52d45f747d11b4107841181251dc9162a74e5e8b112b8d073a3869f849ab250746701dd7c73a77d5f795e9d752036c2b953f88a86cf014bdf3681a40323651f9ca02421d747db562625d4c5a88960fc7784b5121a91750d76abade84d6c9640abf2c289d8afd6ad14093deef17110298041fec8c940d0b65a26c27c661fa79b329f2db6e0989ec2fb2416e2a99f53b7bd49229e3bff53b7957472250e79a8b1235b5cbab1642f069c04b5fa5c2361f23fa8f3adcb1d2c362d1acb295f506f753c718cf7f05f0feb94aeb6edfc573e1e7172fbeb2fea344ca381885898f0771d1076f42961fbdb551693e1b5e35376749546bab1103edce1c4baa09ea50d9599d86636806630ced47e6ade966723ea61f3a6852878829c95c92bd4e9be8ae409c224bc279c77d1e2a2d0426995684d55b291d47d922e9efb45d5d3f84a63eb8c4e285ff2ff4da1bc9578b6b93cc73048b8e3db5c8dd662b54c96518752a8c4db88a628192f90eed0273807830f7ca1e9ff1d5109664bad1e1743acdd14265039703fdde5c9cbd0b35024df0628e37907632be8a927b4b516ac74e4f1b5d472ad5bde7a305de5d8278d288f85f5e6fcaa28d515f5cd8e3774a8275a08412603689358bbc3007d6eafdf3ca264f2c182e2ea2e6dbbd7eb31099737fcf2ede376e073ac18839c989306e11f0fb5179cd7cd8ff264ff95dc083d6e11a2072db86dbf39299c44d6fb7c8b8bb8ca2e0b69e667a2906df2f3ae39eb0270e374bc1f487f2540ad5fbaccecb286ccd83a8a53fad4cf7c1df051d111a89151fe854bb0007be0ca5318fd2a533ec0f8075b5f76b6c5a4b617c7ccd409ac3749db5f2f63a01a3dfebbf0cb8016a89835ed78bca2a32361564ec74ffb210ae8254b87e8196a01927d6b1316f96e102a2329364cd514c846ca40174d0c156c60cf0d8f4a19d85d1f36c85a62e668824a6b5f127c295c8b7437f03873e24c615a9d6bc493feb47d1ae3311cb4eba79f68e58b27fa348f6f1c5cebb19457a2eaff045abcbbada9c3ce95613d55c6e3c7f2a76d553c2905940c8f9fadae7cc05706f9e5af2c69101f5abf7d8163f5f07daa1cde289bf037f7bebf5586fa3a7d501ec08207c8902e4fb82b37cbc3ae7c32c7856e0167b9c7baf6f11d7fdfc99e931c2d1bf2a9e149a488de7508fe4699dca8c3b0cd8adb9e891bb5c11b5749ad3100d4a40d111faf4a4ea83799c81d8a3cb223c34361c3806e2e5ca954fac903d300512c4974a6530cd84d9a1968487a0969c12281dba4031eccca962e31d8ea3e589d85392785ced03168c8f58e159c23b6fb71d2bac96ffed631e61cc4d457a792f13c95d86023d01886219dcc800eba219cd20ad65ec20fd36a6d9d74f2a06e33a4d985c058f6059295f5439c46d6c77ceb21c98896af1e997dc10b5c53d6b3559814f1b45a3c281dc21b2bc99b957c0bfd13d8e1173b91d2a6cfd776ff07b64b7a8de40d7ab19a885d5aef47d9bcc85dc84615486126fe965266cc334b045190213427a3029a3e65a3acdc6dc04506256274568865ce27769d47d512d55977b0fc689c8a07d8950a42defb54d998f1bedbe1eb70a83f4ebeafade8e85e9867603a41de5469b251e5c052f20cd499b1fabbe9272fa1b1b638d34a7863768449e01779c92bbc1cf2bfd24c386da1eddde340749e4d71c17f4068ddb1b7c0f0f0fdc5a685ed7d38b793101ad652694ad3249935884801647b0d2d5a5332d2a548a6ef86a7fb75959f6495fb3b62d5a17db19174505c73610835aa40ce39f88ce45082af87a3cb80e84a4d1006271c46e025536ce2e6d5e1866e41af230c61bf715eb97a271a3cb2a7c1623387037fb4ec519517b1d243f0885c529cf89bd959df2dcfe98c820b326e53c468d7f6460717f604e95a903ce15da83ad81ecf1b39ab0293589aa8171d881f2bb5105f3d350c4fe1f5728d38bd4ea08e43961ea93e2a670ddc1b01cdd60bce08cd6d7f5d506bdcc5b68533786ed9b88f2e19668e3b512fcf4313ef3d5f900194e0f43819cc851651ad9cc9911d66ec2b1c76bec370a95420115c47cd0ce8296cec8ccedb5644890f602185d4e62672ec7670f3da85d5e41e157ce9d30f4afef5c47acf7e287f88c97203c3e73ef36e16213e37eeab08f75adc6f5c493609db9bfc83df64c2dba0dabf874f39f388cefa7a9f306c20f359ec900e67a971be80aa8acf746b59a65415f386f0bf5a0e7be3def08df1728eb89368f3cf5777cd3bd0ae3210fb829e0ce891a4de349317fcbd1200db469aeff95828b6155b9ef4c54daf01db17eccaea1f815fbb597c75b1ebeff20c9878faae85508d12cd4ecb7cb3a6e2b7202e52a9ab0aaeb3144601ee8fa09d399c51a2620536dcf8de068100469ae172bc0ff6dc525054e1be39e06e9ce08bc6ff60b44665cb4808a0d5b1dc77b39cf03cc4d4003a5bb8be337bb0917e64e731aef6e09bf711bb43ece1c1eb0a90edfb6617e8f912dfe9209056cf91414f7a8787209be8ac3c169b9a7b96f544be72ea5027b5b95d28bb7f68711349bf8ee2dd6e8dc639043c34a434fab7516358e1f59efad93dcb8a1cd8b28e86cce4be34133d82241793cc4614bf73720e98edd8e9708ec64b93b851a166f20abddc7da5ee3312b27cd11a2f6d10a0fdd9854a4a7b767b2c99e7eceaf3ec4277115b5ae409de70d932506a5b69b9fc4a9dfd82977f54e4309fe23ad0e3f7917b03761e496a18fda511c865fe2457040912624e86e7f1e9d681c3569de5442da4d70aaf3ab3a1f8b3d834bd9745a7542b9b31596ec16e8a53d3832be6723a0d4e46526378c2fd80c09e1bf194c7add86db130752f2fc04bbb4eb25f03c8ae2712b8ca6df8d3e85c862489afd65f68b42057db5fa9c9b5580eec7dcd28c225f65ea10dc8d98fb1bfc78fd45d0c5ea42389501dc8d6fbfbb1f10d1be0f029e00159d8831d465f21f6d785556f3e85327c14f473c957903c39b8785b60bb2ccdc35bb55274ea6e87501fbde43888dc510556fad08d80290af8007fd67c19ad3e8e4763204734e2b6c3a661154b231fecb0c833a2e6eaaae76eeadb0de1a48b5ba4f9214b803df74327c8d320c98fa3c237910ea7bab9e074a44094e54ae0671d5b0dfe74d4e86efeadae6a6f7afbaea2c72ab02a2931ee5065088bd9902576ca9895c8f360923b8af8c9f9746b8291dd17411296d8bcb6220872b9299bc35a16b7d1b265d999b91c393e033c6bdb0a2df42013c2372b6cd1decf63e23ea7a960cbeba78e84948a7b61171f29b733998587c3b2a6cae64929b4f49ecfabeff90215fbe3c3addaab887d56e32a7379be5dfa86168240625c137c25dc2cc6dd810f8977d9ddaeb1b804fc17b285598544ed447dd7b3a507623214f19beed61708522d5a7eec37bddf4a6812d7d41c1f12334f01a276ba298a42dd0c3133b0538694154cda8794d41093229c7ba78b7df227992b7f847ee94ea52548ded2cafc4872677ff8674823799de063aea5a728a28b08744231aa27e1f3b4cc8ba4b921c213e01a3ad461028cb840cacced8bf3e99d8f949dbaa14837c6eff8a3ce88f9d7b5c8285c0c940c14f444dcf67322590568bac18005125a09855a1bc5dd4367e7668dfd9e68525638360103b948f200538976077916e3c80222a0f559fa08968f31c79b4c1f58eb0cdde8050e8edc1dd560a2206f5ca39f276d5a32b373955f96e5ca514665c6fe29244dc7b7cf0252eba3dcc671c1d4f4a9001da42323b09ddcd99b67ff2fc9afd46a1e896ffca17252abc6b9129056e4699bb482fbd38988f07185b500d06ee005b4d19a8e366dbc479217a707ff9f4ee07664d008f519c9010b65f7e6e30b6f231023886e6d2d94d9b0702dca17ba3aa593b8df484f362fe35bf70825595e7eba7264edfd990fddd71aceb92abca80d0bcf342217cd8e6110d8dce5dcc5eb63479432adbf07192f6e017ce91de71ceef7ed6e93d6d3fe8905602904687a4b04fdcf67fa5c9396a0699509cfd596b352e96a4be04970e633fd818ac226e04a7d1503ace9f0478244e94ba872e32141bc58355387036c7906bb6ccbe19c6391af9e8e9d9d369df0533ca61b0ec56d208a9bddd34c4c807f8c197d764d87e5f52fb0d8d13beb12e6e0e0a2a87b4f216aba498e6371b6dcd3b2e11f6e4600e113952ba5a0311884100b9a5a2b5c6d3c15bbb2225f5b1cd4152a28584ce7a91948b338200f9a322f5ef008a6194bab21ec928898f6c1681822a96d0b4f7f9a216ae93b6ef6753059335fa0b7c1ec41445978170305b7d682898dd95a67d7f2cc5ae248a56635cfa7635c797da44c644b90230fb3669fc0b0d568b1dffa32733360989a3d1b2e4e7496757d8764dfa289068bcffb24724ee40d864769f6aabc1bdaaff941f8ce0284f8f5be1725a69da740c704115cba6a4f6ffe5d8081d6e97532904b446f1eb3a7e76bd3e9a415b978a0437136bb91f46cdaf03374d7585024edffaacc2599f510cb1a448ab8f5a63e7896bc2d92345cec321ef6efdca80d6a8960c58307946e401d72f6336759e8ef8540fbf57278f74a00164430ed76c15dce6ba60eca12e0ff54895f7b3389fa10fa80b414e454b6ec8bbc5bfe6ebd429deb24f53af2ae4c88a930100595eb6cb348155ceb1f615a22a79bb5b6509cd548f393c8bf5944a22b18babfdf2d69e08b95ac1a7ea8d51b67a2374c52117c22f9c5abbd80ca849a81e595a31f8e7f884283b7c0bf9930a08d40038908c24729aa467fee9fdf181060cb39929d03f6386521b21ee22a61f29ba72851b27f76c1d63f4ed9422b99f123c477220c296763e530f0ad3f97a8ebaefe7eac80bfb699926a17a670bd4a49357f1efaa8e53b44acb882b7704240f7dc666cd31b3cf8361b852afd8d647abc1e23e08eb5b325fcce27baae2501d4fe0b62fb9e2ce60f25ccc2d534c123212f52a0aa76e4f6703bdc1c2dff03cd8d794c0dd2702b784373adc1f9e87672314beee185b12d3671b08ea5703b60b6d652a5fd21b15080094a296cfde1f57867ed2f5a68a2d75860113e2ca76623c991d29924310ba94e87d867dc3088d0b131f4fc0bc1944620ae766479415aee4e995faaeabfdeefe8425fcae615874cfce44ed9b140fcf23efd30a48530bc87501754223ba256d324475cefe5d330536f8e664189e31c42d01f4f1fae883fe5fdc219c9c1513e00afed088918686a6dfdadb0743d43197e1e9250493eeb2b1f85bcc585c6443e22e9e5bf0db0558a584eb01110caf55d3941dbea7a6eabd657440ccbb8083cab648293f4ac48ef07d42c0b5e32ac72ad47f63ac1ec6f9ff436187e3d8a4278b689a81b031cfc5b8c082f5f83d83f258c4d198b77ca1d512bd1ee2a1056bec388a07d4331fa88f97c6af5cbb354761a5aa99fd5ca3f1cee63e328827a7b35dac9231247d264f16945d48e084ab309950b0d831e6cbfee044f41624c6880a5cc631b9082d409cb469893c9d93465f6d49d213834772781607d398724de5043b9bc01d0bbb9ace40cc9cdab57a8541d8a0b3f21ecd13de0d3f4ae60ddbb505bafcc2ce15b5bad11f3a6ed2b20f23b3076f39be7674ff296788c8a6c2ada7d75eb34d4fac225685ec6cc785b8fe4e97e8a0c5b088f325b6f5432f942a31e4ac798906fe70d667562954099aafa42de78a109494788094f1efe8c4931bea482cc24f040c6a1bc9f809d6576a2907318337845cc5213f54252e7495d07e1bfb9add79a782952cb0cae4c6271d299ed3ef694329e6bfe122eb5c735f4a1d86fe4aebe71b72e6d222f20bfa899b348c63b69216b47279760b67c38f85f60e75985844e7d736681d000a1594deda5d81f8c70f7e999dff482f8d5f8d8e1da29cc651370126ffa684d24ccb2a6d0750da29c0db200b96a1661a1e282f829529d09377951eed7a7c4d3bdc48b9f8d137b3a4e12d9c5a7678a09032dea687d4464f45cc3bbc2405e453aa2ebbd5b9733279d542441864bf014a537fc55eb720118932b29fe1ed88a125b728c469a51eddaef8d3eaf24f2b758b1ea6957fb01252e98551368b114628bfe52b2db8f6671b1cc3c9174fe4249eda18fa9cfc9346d55242d9575b7cff4bc8c05e7fec89f4b493587add2985e31cff93e835bf1c3aa2501e85d8e770af9f483ab30a711d0be91c19dc9b6d1ee58459244a14c0b004d9bf2efb73142ba13310823e0baad03bf68bc7bc72b843c769cf266b93bbb5f2c8871634b3284b5b74892d3f63bb9e9e4bf3967764db73f852b46485eced005524b567b7ba0330841118f19dfce07996d2e07d8701d548b24da3ded04582177ee1fe2aa5667eeed5f499cbd630ed55e1aa276c4454f97d2f2661cb7ea3af30f7044daee42be74ee9566cc1fa3ba85f7f3ffddddc1824d30b7d08a9aa0e3b7470c388223e26bfae135ab0895865231c6c312bf3d4c68af4182441eabc803ba0fe62fc7dfb07aa3ab805e1633c91de050539c620a4d07e30c77c1308949d19b3ccaf09a81ad6507c12f199a61bd2ec4b9f6a336f86c9fd2c34e02fa6ed4e79f17819eefdcbde2109f31bd890e623b7981b6daa6530224c13e5915ad938aafc2023bcbcac228564abc0078bbc7c1941e5eaa22b55cb035872757e6bf69d3d9daf889dff14882bfe4d9ff68a8851e7fc7e4a274f77ce7c59f602e4892ccdaf0f06d6033298fb0d2d6d512cae416e4ad7d588e3dd44d58572d689fceb99542de40be73385bbd5b17d3efefd4c6525e99427ecbe4e6f163e042dfda67ebbe18e3b115cb40ed1b2350799605d195682575c74734e3b7cb419e37c4c795d81b9804320fb306e7d324c27c804b9daf10565c80865330188bdebe53a750441d9fa802569db04ede1244dda9321d09e858016ea9cbe71a82f62942f599883d4d53d5d0748d2d95f31714b9a7793c7b60513c2bde95bd74b05bda0965174dc7653bded9af80194fdc66b2090602a5085dddd85db0e51fb2a53a67f49e3df1d98e7727eed077bbc77dbddfa14d8529779cce5d12f21ba0a36201ce71a70ebafcc4c742d9c56c82f73788680ea54b8daaba017c0def9fe3fd0872f24f793daeae2660f16187ded1b61ef2eb9a3102f48a916e28771995719e31f0c426dd886be46be7c40cabc07e97d314ad53cd21191256b54daf7caf82d7f3239add94beddfe3e60d040508373699e5ec16bb5293715dcfef01291b15f08fee0d43bf41ab906af4e5b0a261415fcbd4503b687ec22c1f7fd50f3763b370ec0befb981715728dd10c5fb2ccbed40deca04c42f268e38b4ed3d7048011238d65cc178d5e29e8c63c21b873556b3fb136c471df4d346bfeeb086f3379282453038102052995c44f67d5f979a15bea08f114a64120e022e5adbf7ccaea8a83904ff0b38f44a0284daf7ee2f180a1c937c5bf7086688a5a0846d60955d7882c424dca427d45b29954b00873c717587fcb933319b0fc34516229bbf11574854dc64f277ddd8e303ccb6ba48378fe41298aa6d7fcf7252ec4c257909869db344c7ecd791fc57abe9f47fad5198487e9bbe4d8fa67b81f0b77a14538d91d3c3842261b2d27890ef12d9b15bc78dfbdc325bfc535565e035a51c3e5b38005c409919be69f55304cc1725501e74daa592c1b65d6a704ef1cab00a179126a404ad934e118bcaced76212f59ff32286c3ce134d047cc9fa4f5b45607bb9c3a7d35b4ee19f947c529230c9dda96a04a9a262a3023a58971264f89cf37570c1067d0983c6b46b3adcb0ffd7fb84d608a6b401c0ce2c41fd26f129800d5880d7730444bd4570581c2b1088f2fab7ff6c20a7d3f43ac711f7cd367464f3dd15e0f38ede3e9df16cc841a5956eb4ea85e27c9c9533461185bf2fc299ce55329b19f997cfc475f976dce56bacdb6ec39096d1aa916cef64d5dac9a97f076633dc2267b56ae0980c83e3bdc93914f9caa9199ea1ce2170c94c07d655fd74daa34496bc3202478c6240000527120fba174fcf8d3c69c5410b54569ea0e7e333bd2aefce9705440a0b608bfda1b9880c3318177e7cc69b5283182904ad9f1182498f599074a1287cea2393a903d8caa1535731358f68418234c1e6b9d97b760befbca49df5338fe526e052adc2ae1a439ea485fddf4f6a540d0508014af95ed3b16ed41e344040427ad6665f92ac99a53d276e9b53a550a151c1d800ef2d9a9b793372ced0c0703196f88b905ce76347bf02825c31927f66fdc66b1241e2b6316491f862b579befc2b7f7f531f33a37703e8fe994ccc9c87fd5d90974e17aa5fdf9143d43bb2d833260b707429c0dce9195280c159d7f3dde26b0a5103d11fe63d27632bd7efb30bbcf39107a947ba74c7e11beeecc2baa6ae3b57d9c59a6135959930c813779f527142009e02029cce47c686367cdbae8a0c323b2a6b12b1808c3f0c5e1a30b28288c7e9189d6ca4065a1d618761ebc281b3d5bc018e34174d457c128f0e24c661a471cf12468bd4665544bb3d6bd0fb4440ac511e797c5773fc6754991f62e02b86660f4434d9a1be0a45e2d6f25e5b2e336f392395a4204bb36d6b5de6c341eeff8fb327d6792827f823ec24344bf6c88d053798a5de2b75adf23ed1ae588cb7f53a4a5b748b459f83d03f6e0a628031f6a5e888a881cc050dc3915146067c53c1e134a83fe3a0b75c62f7e8e00a10002ec1b945001eeb1f8b73849d5b38f27095f1f9fa1d4e1b92be8809834480d1fa4ab53ea8a4beb56cfb540fa82a12e6c926019c0db17dcdaed4ce8346f4805acdf57037e50a4f5bf831d8df3c21a0bac07994b06afa5b161c6de9f6daef088f87b64be695c234f88aefbd72346691cfbfd7d96a466b8ed8918f59490b4ef1635798c92096df8bab90848d895bbb32b22df2e22bf62723cca670d35d54650e29c456f52f7cef99bc48fd480397c0ab20bb697b240e751433b2dc1b6e3680d38e3b4661147280c8ca98d396a3050a972f297073c3ec20b492e09c82a8c5160516d31e90d2dcd57da896bf598c84bf3ff29c9115e1fbf2188e5ffeb1c0951b277cbd047706977c7ef61b119eb15afc6be41132a9b7661b444ef26e92eb5d70307d3cbfd4c2d9006591322991ce21ee10e50fa6dccfb23d80200a89879135ab56f278ea1140c10c8e7f96d16ca7636d0a2caa7e31b8ceb9baa5f5f6474d9dd7d97c78ba0c259679f8ed41d380a807fa7fe3cec9aca3e5dd83fc03ac1a64e7a6562c853031849fed106f47931367cbf9a0c3b8910f6fff67adb644bcaaa8cf12e712a03da10f4fb29ee98d6adea4d9de9b6a2ff293c01c7a0b00a0a76332f5669c5012c796f05de906b29369762c638819e860623d996789bc8bf3f621ce04a6ac756f3b265740b4178b440a6b7b4ca4f9b0012a71a23586909e3afa7972c0cb231f19e0c22661b9da1d7b0b12a75fc6b45f3b7e3174f1c435306c4f4b8ec590c9960307b9525ef46f23597d4aed8a6a90a73a6ac06f0e25cd075e2d424fc67d6b048df9f114e73349f32777f6adb277560729229216cd4806fbdc384024cb77080f52856593470e3f96fdd31d82a4fdbfbd139fb50e599cd74d0c9ebe30994611d7089b684f51efa3d45c91a0e0cc1d8010323e7ee9bec6c7918b41618cf687945d3d851bef90a647ce90b3377eaf53e91ccdee301ebe01e986fa1e418bc78a016bc8902b612b33b5d8f19a1e816c04635989d320c6b3d6844037666c05c25f853b08366261e9bfb1ad0a80a7b8d52e5ffd907be1cb90aee634be48e30fd8b0e6efc55e68251e3d776a67b7e19239a519321f0134d9771f1d16215705e8c57218d2760047b5d7ff9b609c03f49f1c3eddd6f8f0d8832113dbc88d63a032efc40df0dc39bf6c702777d1badaeccc680cdbcb5dcd81c8be589d4b3e33a6fc2930e3626f05c23ae0cc8f535d3d63b29f61d14a4dcac074cd6a5f476fc736445c1d49a282c0fb6a05c5a3c3196af0f4a2fa0e89b61ee654b8f5ac4542038daf04e870f991a03549bc7de45c19ae131cc34117910fb83bcfcb9c63c3afd2df5aaa6ccd5d9287baf4757526bcb7f24805ebdf2a180a5fdd5baa39ea2dec0f6eb17210b84cac0376963ee47b8154e08a640bb9ae45b31723fb7a6f3ee8b1ac3122009186412f4dc49071fa99b10d22faa1a16f0fb82928e7666270664c12ba81beaa13bb0dadc780abe2b65ed812b4ce4a964dd837db13fed35919315443ebbc149e3a73132d658d9de08269442cdef283e3a1b975f8bbf8e60737ab26fe03303d1e83cb9ca49d7c299eeb33abc169e7869e40920c46ae75c95159b058ae070ec02bd8f8d3e330bda3b2134a992c7560a9b7da70c323411ba0457b02d1b2e77693f75b386d261f17f8cd7a7788253e320a72d50cddf2c07c7fc6e55e1bea1479221f20f3f93016f92acd6806b7143c623ea542890643f8d671e3171d5905e32d8ff190b1a29096a2d737abe98447f9999af5e196e26389ddc923d20ba49f8a50890048a6c24fcbbab1898c7fd963676a88304bfc209d684e5bc58d7cc8e7c5166a090fc4777d649f934ac3ecd91e830c8cb507a3cb44a7b3aa8f44e8a52430268e794120d7b16d4c32befc428a660d103661220aa321b51ddc923287c388c1704b805d6c1894f4fe9c56d103f172e76f58e2b13790549ec75e09c9e0723c7c8720acfed900925269bd77a2bcb6cb8b2675a9af8bb9abe5de49c8bd947c17851e6aa1f4b5001f86ee0ee1b13657b849f9028be87bc90365cbb6411eb535595e0a30a5c1d9669328188c5b555f32af907fefcb1ad5687b958c1dd2a792949e9a018fff90fe481a481d30a7a55a8d9b96ddddfaae9c09738b6b2253ef0fd417e6f9fcd2cd9a54e45cac4ef2b11679926bae2851466f372eeadbe7241faf71792c96c128b42ebd5880470e199571deb7d981d78ea19cd261666872b6521abbfffad4b8ea7a43cda4ce16805a2d622b8b4d41af6a69d658cd6c2c44ddde6caad1e7709f138ea32079bfa45fe16eefb320573cbb94cd1889612edaecb9aba8c7c9cb4bae2ccfb5d6647027d117cef7f2a6c129e7a48b037a1558934aa7b9fb0e5a31b082180b01412e98bcc6f6f61260227aa6d79e958f1f9a0024166d7129e624bee51a835be16ff4e937d6dbcb5a0ab4c5620da95141f3be7bfbc47e7127351195d506387954fbd3804e4759e8fc11834474d97d2627f8e489045dc264e90c6f42e1c7af5f117124f6918eff4c1d989c86a0072b29ab14efd6983f40cf7625302f9728f3745b588e2c389e3a1985815aacffeb7f2a0546aaadd4d3046629e58218a0594b17ccd3fca9144601f54e754d631d957fc339351b3482a2913f416acd59b69476efddb3bc80ccd688967950a9fbd791e9765beaffe6b6df04e8a67fd43152cbb83c387f0162f71a4b537bcaaa8e3ab943654adf0b2ac54820d365e52a907770670852f3ad1e5097654e0d633594ecdabce7cf004255a165f6700f09d58d5a7b9787fda3241e168e5b942fb86d1145964c9219580973c1c2bd9613e2e70cae3c2fd5629a2ae454e8aa9b3207473ebeb463d835164176a89d91e61e50c1efacd51fa026314641f2b0f4798333c96759a50b4d5685c098b917b49b6d44acaf418fd469b85b0ac67880702f227421d014cfe295dd729d23a60585688d46b32ff2d82bf4368c6b09c557fd29cfb0770cbf1eaa66d60a028a00aad94f7b06f94fc8709a64a1acc6e3b7872346266ab920ddbe560b4fc66da21fcb2c8734fd71362db6604cf0be9437659626f2a6b175fa3ce9c818c8f817575500f5397c72c46c51c5e9836fcee181c0197ba4300acacd7ed29f44ccb38e0eded5b848acb7d589c098ffdd374fad3bc1f2e426630ff354f4db53ead2cf3c27f4337e7dffd4feb38ce624408bba6898777ea6f4c6244444d11327697a7a10784a09c776e32f87b1cec26165fca82dbb90f61a03fa571b8be6441b7e29ddbddc42a68efacc2bd3636c91607d9201582c30d469d6e23d7260934c66df3d3b4b203f8b381354bc16c1c175cfb08f645b4fe7faf95a17d21b48b8e6c4112922f58bc2399e787e55a549ef975ab7193b7827b1cf4e267d022e83589fd5a233516c2852d0c39de760fe4630b48013d6fcd3cc0fa439d19c7e12c2167c7227cc3cb3b1994495b95c843f4e40a85c5ffa576ea977d6ed83c7a9b3b4c2d3d04462f785bb05e6fa6623e1f668e9b6d9c17b129afe6da2d279d0c673f894b3e762326617c1a70adf354f55ae1f326971f183739899be0fbbfe61495a21ce16e5eb8f4b217ec7e33e913b37e77d70a9ae3e2ce354544de42412eba12aecbd91e3bb21e84531407cb4e78cd9005b0d2377c80272ad08158e9ceb1eb6564d01590b2d6635082b24e5d127289bee2c0b4c6260996908069edddae09bc0b2a84ff1ed4828bc444bfdff0d181b87bd0a58806e36a491f40042ba6fb698cb70ecc7b1064ddfdbd50c2b0b081a2b0bbca37f5aaa0c73d90ed3388bd3997d239b4710e63b9eb71ff67fc12fb8301dba7a9853115d8610ced2d56704d55d196d9e9f91259540b80fc8793ffafa7549b0dbe569490f434c8f8f19a705fdcc23e80aacdb751350a4627144dab3b25432ecf94024853e8a8228e19ecaae11461f4f74b6ee82730c217d45c33226212673f1ac0f017a3baf6cc1d607bb9b520d970ae537baddee9e1bf9f052e17d67f63ad68ddb181a5cbb97cbb8ad7c8d0889475737d1e62daa645629554e4528375e53511e87bf1085be8e001684cf50f0024e5c80613c6e6a98b9f27f42b1ee2651d9fbaeae101cd99e7189422cfcd977d3530668400bf0e207ec4fe45557b297277f5be171cb6e43a40352c237f7f3104af5284c6276b949528a320af1aa94b1b522882edcf5ee8bf206b5b5b1353b45b3686204749e5b1e481368b08a8448283c2660c65f507f965646fc84313509a41e489dbd06a0ccdb09420bb15a3c9d8cad289daea36d0b66df7e5fc584405481549b830947d765e57c2670b4cda0d4006267f8fc4770155090d3055197680356a49f084c4026ba7c2848ac491aed91c7a96f82153d3a3d811e770b3829cb49ff54c48493c674f01d875c9e0ee3a31d8638a6921cff8a2cd7490bcbaa67c3870db9c1b20e751f71efcfbc0474aa7ee9ba5a8d27a05cfe6490c7bd3f05f0f1861587f424d0610c93bbab8b8eab2c5491fb861e33db7350034b0b647e8fc19f3ffdb50ada0b761cc6081a2d42a712e246df2d73c9c2f10400b8f14d6be0f3fffd36105961589c6a216cefc20061608a0e57d2dcaea3c130e3df3c65e2a89af0576ffd70e9373927a7857c23af2642637b59de986a1f0a6e53a7ba3a4f4b7e34e7e02adfe948b19431421ea8c04b971ba29d047dab0fd0e83d2b7c09ae21f271cefd7916e5a5ebcddf52228f5df46e1313f4afe5e66dbb44f85cec677721cec51d73bfd2d73217c893add07cd5b35669ba9f25fc58de242dfe0b32fe4dddbb409a208723f5d7f75b49b6d4affe7658f346247f4e4c2167ec884cd57e8bfe6e8c453f78381865d64f5ae707e1b09ca01bb0d86fd7b784e7f3ec67128fd98b26e400542a1d3fd86c1b07befb1c0109373f47a830b92cb742675a4881ef6e03aed2e95e105ada228ad5d488edc08b42cdb17185d0d0308d1c7e88d3e9ae964c7e273f585ee84ca2be868ebfaba5a824f960e79d8f57918acaa0e240c0c6670c06d906bead68147a5cc1b5ed2b97e8c50ea6a357b6fce9115f05f8bb67fbaea773a8ffa5d62ab6357a7bfe6bedd3566709a42af48f6c65c3b161bde3825b75fa585b51c93fce0ee8d912907d1aee5e868c3fae8fac</script> <div class="hbe hbe-content"> <div class="hbe hbe-input hbe-input-default"> <input class="hbe hbe-input-field hbe-input-field-default" type="password" id="hbePass"> <label class="hbe hbe-input-label hbe-input-label-default" for="hbePass"> <span class="hbe hbe-input-label-content hbe-input-label-content-default">Hey, password is required here.</span> </label> </div> </div></div><script data-pjax src="/lib/hbe.js"></script><link href="/css/hbe.style.css" rel="stylesheet" type="text/css">]]></content>
<categories>
<category> 面试 </category>
</categories>
<tags>
<tag> C语言基础 </tag>
<tag> 嵌入式 </tag>
</tags>
</entry>
<entry>
<title>Butterfly字体修改成鸿蒙OS字体</title>
<link href="/archives/5fc85bc.html"/>
<url>/archives/5fc85bc.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="写在开头"><a href="#写在开头" class="headerlink" title="写在开头"></a>写在开头</h3><p>最近美化主题的时候看到后多博主大佬们的字体都是自定义的,蛮好看的,正好华为放出了鸿蒙系统的字体,正好换上。</p><h3 id="显示预览"><a href="#显示预览" class="headerlink" title="显示预览"></a>显示预览</h3><p>华为鸿蒙字体 <a href="https://developer.harmonyos.com/cn/docs/design/des-guides/overview-0000001053563071">「HarmonyOS Sans」</a>是华为专为鸿蒙操作系统定制设计的一款全新中英文字体,特点是易读性强,字型简约富有科技感,在各种不同尺寸的屏幕上都能获得清晰的显示效果,既适合用于设计制作、平面印刷,也可用于阅读,显示大量文字也依然干净清爽。<br><img src="https://img1.imgtp.com/2022/07/20/ZenFqJUa.png"></p><h3 id="具体步骤"><a href="#具体步骤" class="headerlink" title="具体步骤"></a>具体步骤</h3><ul><li>在butterfly主题source文件夹下新建文件夹font,将下载好的字体文件放到font文件夹里。<br><img src="https://img1.imgtp.com/2022/07/20/nZS27JE7.png"></li><li>在source/css文件夹里面新建font.css文件,写入字体文件内容:<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">@font-face</span>{</span><br><span class="line"> <span class="attribute">font-family</span>: <span class="string">'HarmonyOS_Sans_Regular'</span>;</span><br><span class="line"> <span class="attribute">font-display</span>: swap;</span><br><span class="line"> <span class="attribute">src</span>: <span class="built_in">url</span>(<span class="string">'../font/HarmonyOS_Sans_Regular.ttf'</span>) <span class="built_in">format</span>(<span class="string">"truetype"</span>); </span><br><span class="line">}</span><br><span class="line"><span class="selector-tag">body</span> {</span><br><span class="line"> <span class="attribute">font-family</span>: <span class="string">'HarmonyOS_Sans_Regular'</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li>在主题配置文件里inject处添加引用信息:<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="bullet">-</span> <span class="string"><link</span> <span class="string">rel="stylesheet"</span> <span class="string">href="/css/font.css"></span></span><br></pre></td></tr></table></figure></li><li>修改配置文件中关于字体的设置:<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">font:</span></span><br><span class="line"><span class="attr">global-font-size:</span></span><br><span class="line"><span class="attr">code-font-size:</span></span><br><span class="line"><span class="attr">font-family:</span> <span class="string">HarmonyOS_Sans_Regular</span></span><br><span class="line"><span class="attr">code-font-family:</span> <span class="string">HarmonyOS_Sans_Regular</span></span><br></pre></td></tr></table></figure></li><li>可以在font文件夹里面放多个字体,分别应用即可。</li></ul>]]></content>
<categories>
<category> 主题美化 </category>
</categories>
<tags>
<tag> 主题配置 </tag>
<tag> 字体修改 </tag>
</tags>
</entry>
<entry>
<title>Vscode终端调用GitBush</title>
<link href="/archives/88595fc7.html"/>
<url>/archives/88595fc7.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="写在开头"><a href="#写在开头" class="headerlink" title="写在开头"></a>写在开头</h3><p>在哔哩哔哩刷到一位博主展示自己的博客,看到他直接在VS里面调用GitBush的终端,省去了来回切换窗口的麻烦,便去查了一下修改方法,留个记录。</p><h3 id="启用Bush"><a href="#启用Bush" class="headerlink" title="启用Bush"></a>启用Bush</h3><ul><li>看文档好像如果你安装git的时候是安装在默认路径时在vs里面好像是可以直接调用的。</li><li>没装在默认路径的把自己git的路径告诉vs就可以了。</li><li><code>Visual Studio Code</code> > <code>设置</code> ><code>在settings.json中编辑</code><br><a href="https://imgse.com/i/zYY8Mt"><img src="https://s1.ax1x.com/2022/11/25/zYY8Mt.png" alt="zYY8Mt.png"></a></li><li>加入以下内容:<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">"terminal.integrated.profiles.windows"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"gitBash"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"path"</span><span class="punctuation">:</span> <span class="string">"D:\\Program Files\\Git\\bin\\bash.exe"</span><span class="punctuation">,</span><span class="comment">//这里是的的bash路径</span></span><br><span class="line"> <span class="punctuation">}</span></span><br></pre></td></tr></table></figure></li><li>然后重启vs即可,<code>Ctrl+~</code>打开终端,在右侧选择<code>bash</code>就可以了</li></ul><h3 id="终端字体美化"><a href="#终端字体美化" class="headerlink" title="终端字体美化"></a>终端字体美化</h3><ul><li>默认的字体太小了,而且也不美观,vs自带等宽字体<code>monospace</code>,不想折腾的下伙伴可以在设置里面直接调用。<br><code>设置</code>><code>Font Family</code>><code>终端</code><br>上面改成monospace即可,字体大小怎么合适怎么来<br><a href="https://imgse.com/i/zYYUIg"><img src="https://s1.ax1x.com/2022/11/25/zYYUIg.png" alt="zYYUIg.png"></a></li><li>觉得还是不太满意的可以自己去找一下适合的字体安装在系统里然后自己选,我使用的是menlo for powerline字体,在任意目录下载字体<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">git</span> <span class="string">clone</span> <span class="string">https://github.com/abertsch/Menlo-for-Powerline.git</span></span><br></pre></td></tr></table></figure>下载好之后安装,然后去到vs设置里,把第一个改成<code>Menlo for Powerline</code>就可以了.</li><li>也可以去到<code>settings.json</code>里面给不同的终端配置不同的字体: <figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">"terminal.integrated.defaultProfile.windows"</span><span class="punctuation">:</span> <span class="string">"gitBash"</span><span class="punctuation">,</span></span><br><span class="line"><span class="attr">"terminal.integrated.fontFamily"</span><span class="punctuation">:</span> <span class="string">"Menlo for Powerline"</span><span class="punctuation">,</span></span><br><span class="line"><span class="attr">"terminal.integrated.fontSize"</span><span class="punctuation">:</span> <span class="number">16</span><span class="punctuation">,</span></span><br></pre></td></tr></table></figure></li></ul>]]></content>
<categories>
<category> VsCode </category>
</categories>
<tags>
<tag> VsCode </tag>
<tag> 终端美化 </tag>
</tags>
</entry>
<entry>
<title>Hypertension</title>
<link href="/archives/d6e2db9e.html"/>
<url>/archives/d6e2db9e.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="Mydockfinder!!!"><a href="#Mydockfinder!!!" class="headerlink" title="Mydockfinder!!!"></a>Mydockfinder!!!</h3><p>2022.05.11 20:50 多云<br>论文ing……<br>【在中间的省略号怎么打来着🥲】<br><img src="https://img1.imgtp.com/2022/07/20/hwzHGl25.png"></p>]]></content>
<categories>
<category> 随机日记 </category>
</categories>
<tags>
<tag> 桌面美化 </tag>
<tag> 好物推荐 </tag>
</tags>
</entry>
<entry>
<title>CS:GO调机器</title>
<link href="/archives/a99aefff.html"/>
<url>/archives/a99aefff.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="一键大跳"><a href="#一键大跳" class="headerlink" title="一键大跳"></a>一键大跳</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">alias +cjump "+jump; +duck"</span><br><span class="line"></span><br><span class="line">alias -cjump "-jump; -duck"</span><br><span class="line"></span><br><span class="line">bind "你要绑定的键位" "+cjump"</span><br></pre></td></tr></table></figure><h3 id="Nvidia滤镜"><a href="#Nvidia滤镜" class="headerlink" title="Nvidia滤镜"></a>Nvidia滤镜</h3><ul><li><p><del>国服启动项</del><br><del><code>-allow_third_party_software</code></del></p><ul><li><p><del>添加第一个过滤器,选择夜间模式,拉到3%</del></p></li><li><p><del>添加第二个过滤器,选择曝光/对比度</del></p></li><li><p><del>曝光0%、对比度60%、亮点-100%、阴影0%、灰度51%</del></p></li></ul></li><li><p><del>最后添加第三个过滤器,选择颜色</del></p></li><li><p><del>色调和色调强度0%、温度10左右、亮丽20左右即可</del></p></li><li><p><del>效果预览</del></p></li><li><p>新一版<br><img src="https://img1.imgtp.com/2022/07/20/rW7v6Roz.jpg"></p></li></ul>]]></content>
<categories>
<category> 游戏设置 </category>
</categories>
<tags>
<tag> CSGO </tag>
</tags>
</entry>
<entry>
<title>Apex画质设置</title>
<link href="/archives/2bedf69.html"/>
<url>/archives/2bedf69.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="Videoconfig"><a href="#Videoconfig" class="headerlink" title="Videoconfig"></a>Videoconfig</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">"VideoConfig"</span><br><span class="line">{</span><br><span class="line">"setting.cl_gib_allow""0"</span><br><span class="line">"setting.cl_particle_fallback_base""3"</span><br><span class="line">"setting.cl_particle_fallback_multiplier""2"</span><br><span class="line">"setting.cl_ragdoll_maxcount""0"</span><br><span class="line">"setting.cl_ragdoll_self_collision""1"</span><br><span class="line">"setting.mat_forceaniso""1"</span><br><span class="line">"setting.mat_mip_linear""0"</span><br><span class="line">"setting.stream_memory""300000"</span><br><span class="line">"setting.mat_picmip""0"</span><br><span class="line">"setting.particle_cpu_level""0"</span><br><span class="line">"setting.r_createmodeldecals""0"</span><br><span class="line">"setting.r_decals""0"</span><br><span class="line">"setting.r_lod_switch_scale""0.6"</span><br><span class="line">"setting.shadow_enable""0"</span><br><span class="line">"setting.shadow_depth_dimen_min""0"</span><br><span class="line">"setting.shadow_depth_upres_factor_max""0"</span><br><span class="line">"setting.shadow_maxdynamic""0"</span><br><span class="line">"setting.ssao_enabled""0"</span><br><span class="line">"setting.ssao_downsample""3"</span><br><span class="line">"setting.dvs_enable""0"</span><br><span class="line">"setting.dvs_gpuframetime_min""15000"</span><br><span class="line">"setting.dvs_gpuframetime_max""16500"</span><br><span class="line">"setting.defaultres""1920"</span><br><span class="line">"setting.defaultresheight""1080"</span><br><span class="line">"setting.fullscreen""1"</span><br><span class="line">"setting.nowindowborder""0"</span><br><span class="line">"setting.volumetric_lighting""0"</span><br><span class="line">"setting.mat_vsync_mode""0"</span><br><span class="line">"setting.mat_backbuffer_count""1"</span><br><span class="line">"setting.mat_antialias_mode""0"</span><br><span class="line">"setting.csm_enabled""1"</span><br><span class="line">"setting.csm_coverage""1"</span><br><span class="line">"setting.csm_cascade_res""512"</span><br><span class="line">"setting.fadeDistScale""1.000000"</span><br><span class="line">"setting.dvs_supersample_enable""0"</span><br><span class="line">"setting.gamma""0.855357"</span><br><span class="line">"setting.configversion""7"</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="游戏内设置"><a href="#游戏内设置" class="headerlink" title="游戏内设置"></a>游戏内设置</h3><p><img src="https://img1.imgtp.com/2022/07/20/VvA8x92r.jpg"><br><img src="https://img1.imgtp.com/2022/07/20/TJ5wNqgz.jpg"><br><img src="https://img1.imgtp.com/2022/07/20/FWbEWtqa.jpg"><br><img src="https://img1.imgtp.com/2022/07/20/KuIqq1WP.jpg"><br><img src="https://img1.imgtp.com/2022/07/20/RQle2a0w.jpg"></p>]]></content>
<categories>
<category> 游戏设置 </category>
</categories>
<tags>
<tag> Apex Legends </tag>
</tags>
</entry>
<entry>
<title>Butterfly自用手册</title>
<link href="/archives/8da2c4c2.html"/>
<url>/archives/8da2c4c2.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h2 id="浅浅记录一下主题的美化内容💀"><a href="#浅浅记录一下主题的美化内容💀" class="headerlink" title="浅浅记录一下主题的美化内容💀"></a>浅浅记录一下主题的美化内容💀</h2><ul><li>内容涉及到自定义css文件,这里记录一下,在<code>主题根目录\themes\butterfly\source\css</code>目录下新建自定义css文件,我这里是<code>self.css</code><br><img src="https://img1.imgtp.com/2022/07/20/G36Nh8Su.png"></li><li>之后在主题配置文件开启它:<br>在<code>_config.butterfly.yml</code>里搜索<code>inject</code><br>添加:<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="bullet">-</span> <span class="string"><link</span> <span class="string">rel="stylesheet"</span> <span class="string">href="/css/self.css"></span></span><br></pre></td></tr></table></figure><img src="https://img1.imgtp.com/2022/07/20/Yq1z52n2.png"></li></ul><h3 id="背景透明-渐变"><a href="#背景透明-渐变" class="headerlink" title="背景透明\渐变"></a>背景透明\渐变</h3><p><strong>背景透明</strong></p><ul><li>效果预览:<br><img src="https://img1.imgtp.com/2022/07/20/iStp8aFM.png"><br><img src="https://img1.imgtp.com/2022/07/20/iARFAfg3.png"></li><li>在self.css文件中写入:<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#footer</span> {</span><br><span class="line"> <span class="attribute">background</span>: transparent <span class="meta">!important</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li></ul><h3 id="背景渐变"><a href="#背景渐变" class="headerlink" title="背景渐变"></a><strong>背景渐变</strong></h3><ul><li>效果预览:<br><img src="https://img1.imgtp.com/2022/07/20/Z7DxH56r.png"></li><li>在新建的css文件中写入一下内容:<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#recent-posts</span>><span class="selector-class">.recent-post-item</span>,<span class="selector-class">.layout_page</span>><span class="selector-tag">div</span><span class="selector-pseudo">:first</span>-child<span class="selector-pseudo">:not</span>(<span class="selector-class">.recent-posts</span>),<span class="selector-class">.layout_post</span>><span class="selector-id">#page</span>,<span class="selector-class">.layout_post</span>><span class="selector-id">#post</span>,<span class="selector-class">.read-mode</span> <span class="selector-class">.layout_post</span>><span class="selector-id">#post</span> {</span><br><span class="line"> <span class="attribute">background</span>: <span class="built_in">var</span>(--light_bg_color)</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#aside-content</span> <span class="selector-class">.card-widget</span> {</span><br><span class="line"> <span class="attribute">background</span>: <span class="built_in">var</span>(--light_bg_color)</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#web_bg</span> {</span><br><span class="line"> <span class="attribute">background</span>: <span class="built_in">linear-gradient</span>(<span class="number">90deg</span>,<span class="built_in">rgba</span>(<span class="number">247</span>,<span class="number">149</span>,<span class="number">51</span>,.<span class="number">1</span>),<span class="built_in">rgba</span>(<span class="number">243</span>,<span class="number">112</span>,<span class="number">85</span>,.<span class="number">1</span>) <span class="number">15%</span>,<span class="built_in">rgba</span>(<span class="number">239</span>,<span class="number">78</span>,<span class="number">123</span>,.<span class="number">1</span>) <span class="number">30%</span>,<span class="built_in">rgba</span>(<span class="number">161</span>,<span class="number">102</span>,<span class="number">171</span>,.<span class="number">1</span>) <span class="number">44%</span>,<span class="built_in">rgba</span>(<span class="number">80</span>,<span class="number">115</span>,<span class="number">184</span>,.<span class="number">1</span>) <span class="number">58%</span>,<span class="built_in">rgba</span>(<span class="number">16</span>,<span class="number">152</span>,<span class="number">173</span>,.<span class="number">1</span>) <span class="number">72%</span>,<span class="built_in">rgba</span>(<span class="number">7</span>,<span class="number">179</span>,<span class="number">155</span>,.<span class="number">1</span>) <span class="number">86%</span>,<span class="built_in">rgba</span>(<span class="number">109</span>,<span class="number">186</span>,<span class="number">130</span>,.<span class="number">1</span>))</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li></ul><h3 id="页脚透明渐变"><a href="#页脚透明渐变" class="headerlink" title="页脚透明渐变"></a><strong>页脚透明渐变</strong></h3><ul><li>如果选择背景透明渐变,页脚的内容因为是白色容易跟背景混在一起导致看不太清楚<br><img src="https://img1.imgtp.com/2022/07/20/tJw9ceru.png"></li><li>一样在刚刚的self.css文件里写入一下内容:<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"> <span class="selector-id">#footer</span> {</span><br><span class="line"> <span class="attribute">background</span>: <span class="built_in">rgba</span>(<span class="number">255</span>,<span class="number">255</span>,<span class="number">255</span>,.<span class="number">15</span>); </span><br><span class="line"> <span class="attribute">color</span>: <span class="number">#000</span>;</span><br><span class="line"> <span class="attribute">border-top-right-radius</span>: <span class="number">20px</span>;</span><br><span class="line"> <span class="attribute">border-top-left-radius</span>: <span class="number">20px</span>;</span><br><span class="line"> backdrop-<span class="attribute">filter</span>: <span class="built_in">saturate</span>(<span class="number">100%</span>) <span class="built_in">blur</span>(<span class="number">5px</span>)</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#footer</span><span class="selector-pseudo">::before</span> {</span><br><span class="line"> <span class="attribute">background</span>: <span class="built_in">rgba</span>(<span class="number">255</span>,<span class="number">255</span>,<span class="number">255</span>,.<span class="number">15</span>)</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#footer</span> <span class="selector-id">#footer-wrap</span> {</span><br><span class="line"> <span class="attribute">color</span>: <span class="built_in">var</span>(--font-color)</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#footer</span> <span class="selector-id">#footer-wrap</span> <span class="selector-tag">a</span> {</span><br><span class="line"> <span class="attribute">color</span>: <span class="built_in">var</span>(--font-color)</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li><img src="https://img1.imgtp.com/2022/07/20/Z1n3aC5Y.png"></li></ul><h3 id="社交图标"><a href="#社交图标" class="headerlink" title="社交图标"></a>社交图标</h3><ul><li>推荐使用<a href="https://www.iconfont.cn/">阿里巴巴矢量图标库</a>,在搜索框输入想要的图标名称即可,选好后加入购物车,添加到项目中,没有项目的话新建一个就行。</li><li><img src="https://img1.imgtp.com/2022/07/20/mjy9np5j.png"></li><li>在我的项目里选择<code>Font class</code>,点击查看在线链接并在浏览器中打开,然后另存到本地,可以放到主题文件夹里面的<code>source\css</code>文件夹里,命名为icon.css方便调用。</li><li>在<code>_config.butterfly.yml</code>里搜索<code>inject</code>,引入刚刚的图标文件</li><li><img src="https://img1.imgtp.com/2022/07/20/x4vpTDyU.png"></li><li>还是在主题配置文件里,找到<code>social</code>社交图标配置图标</li><li>格式为:iconfont class 名: 链接 || 名称</li><li>iconfont是固定的格式,class名可以在刚刚保存的icon.css文件中找到</li><li><img src="https://img1.imgtp.com/2022/07/20/hR2IIqkD.png"></li><li><img src="https://img1.imgtp.com/2022/07/20/MVbOFlgj.png"></li><li><del>我自己试了没成功,不太懂这方面的东西,但是我看好多博主都是这样弄得,他们的图标都是彩色的,头大</del></li></ul><h2 id="持续更新。。。"><a href="#持续更新。。。" class="headerlink" title="持续更新。。。"></a>持续更新。。。</h2><p>文章主要参考<a href="https://blog.imzjw.cn/posts/b74f504f/">小嘉的部落格</a></p><h3 id="网站图标"><a href="#网站图标" class="headerlink" title="网站图标"></a><strong>网站图标</strong></h3><p>在_config.butterfly.yml中搜索:favicon,将其修改为自己图库的网站图标,或者是本地文件路径。<br>顺路,记录一下在找图标过程中发现的很使用的免费图标库:<a href="https://www.iconfinder.com/free_icons">Iconfinder</a><br><img src="https://img1.imgtp.com/2022/07/20/JCxSM78A.png"></p><h3 id="天气小组件"><a href="#天气小组件" class="headerlink" title="天气小组件"></a><strong>天气小组件</strong></h3><h4 id="写在开头"><a href="#写在开头" class="headerlink" title="写在开头"></a>写在开头</h4><p>逛CSDN看到一篇关于博客添加天气小组件的文章,蛮有意思,便动手试了试。<br>文章参考:<a href="https://sunguoqi.com/posts/32121.html#%E4%B8%80%E3%80%81%E5%89%8D%E8%A8%80">小孙同学</a></p><h4 id="显示效果"><a href="#显示效果" class="headerlink" title="显示效果"></a>显示效果</h4><p><img src="http://reuvza1fi.hb-bkt.clouddn.com/img/20220609102344.png"></p><h4 id="具体教程"><a href="#具体教程" class="headerlink" title="具体教程"></a>具体教程</h4><ul><li>申请API,创建小组件<br>采用<a href="https://id.qweather.com/#/register?redirect=https%3A%2F%2Fconsole.qweather.com">和风天气</a>提供的PAI,首先进去和风天气并注册一个账户。</li><li>进入和风天气开发平台,选择插件,然后选择一个自己喜欢的样式,创建。<br><img src="http://reuvza1fi.hb-bkt.clouddn.com/img/20220609102759.png"><br><img src="http://reuvza1fi.hb-bkt.clouddn.com/img/20220609102852.png"><br>插件名称随意发挥,建议选取固定位置。<br><img src="http://reuvza1fi.hb-bkt.clouddn.com/img/20220609103006.png"><br>设置完成后,复制上面的生成代码。<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">WIDGET = {</span><br><span class="line"> "CONFIG": {</span><br><span class="line"> "modules": "01234",</span><br><span class="line"> "background": "5",</span><br><span class="line"> "tmpColor": "4A86E8",</span><br><span class="line"> "tmpSize": "16",</span><br><span class="line"> "cityColor": "FF9900",</span><br><span class="line"> "citySize": "16",</span><br><span class="line"> "aqiColor": "4A86E8",</span><br><span class="line"> "aqiSize": "16",</span><br><span class="line"> "weatherIconSize": "24",</span><br><span class="line"> "alertIconSize": "18",</span><br><span class="line"> "padding": "0px 0px 0px 0px",</span><br><span class="line"> "shadow": "0",</span><br><span class="line"> "language": "auto",</span><br><span class="line"> "fixed": "true",</span><br><span class="line"> "vertical": "center",</span><br><span class="line"> "horizontal": "center",</span><br><span class="line"> "left": "165",</span><br><span class="line"> "top": "20",</span><br><span class="line"> "key": "4b8d61c416ac4c31a05a60e31d6e58b3"//这里换成你自己的key</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li>在<code>blog\themes\butterfly\layout\includes\headers</code>目录下的<code>nav.pug</code>文件中添加以下内容:<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><div id="he-plugin-simple"></div></span><br></pre></td></tr></table></figure></li><li>在<code>blog\themes\butterfly\source\js</code>目录下添加<code>weather.js</code>文件,并填入之前生成的插件信息内容。<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"> <span class="string">WIDGET</span> <span class="string">=</span> {</span><br><span class="line"> <span class="attr">"CONFIG":</span> {</span><br><span class="line"> <span class="attr">"modules":</span> <span class="string">"01234"</span>,</span><br><span class="line"> <span class="attr">"background":</span> <span class="string">"5"</span>,</span><br><span class="line"> <span class="attr">"tmpColor":</span> <span class="string">"4A86E8"</span>,</span><br><span class="line"> <span class="attr">"tmpSize":</span> <span class="string">"16"</span>,</span><br><span class="line"> <span class="attr">"cityColor":</span> <span class="string">"FF9900"</span>,</span><br><span class="line"> <span class="attr">"citySize":</span> <span class="string">"16"</span>,</span><br><span class="line"> <span class="attr">"aqiColor":</span> <span class="string">"4A86E8"</span>,</span><br><span class="line"> <span class="attr">"aqiSize":</span> <span class="string">"16"</span>,</span><br><span class="line"> <span class="attr">"weatherIconSize":</span> <span class="string">"24"</span>,</span><br><span class="line"> <span class="attr">"alertIconSize":</span> <span class="string">"18"</span>,</span><br><span class="line"> <span class="attr">"padding":</span> <span class="string">"0px 0px 0px 0px"</span>,</span><br><span class="line"> <span class="attr">"shadow":</span> <span class="string">"0"</span>,</span><br><span class="line"> <span class="attr">"language":</span> <span class="string">"auto"</span>,</span><br><span class="line"> <span class="attr">"fixed":</span> <span class="string">"true"</span>,</span><br><span class="line"> <span class="attr">"vertical":</span> <span class="string">"center"</span>,</span><br><span class="line"> <span class="attr">"horizontal":</span> <span class="string">"center"</span>,</span><br><span class="line"> <span class="attr">"left":</span> <span class="string">"165"</span>,</span><br><span class="line"> <span class="attr">"top":</span> <span class="string">"20"</span>,</span><br><span class="line"> <span class="attr">"key":</span> <span class="string">"4b8d61c416ac4c31a05a60e31d6e58b3"</span><span class="string">//这里换成你自己的key</span></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li>在配置文件_config.butterfly的inject属性中引入以下代码。<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="bullet">-</span> <span class="string"><script</span> <span class="string">src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script></span></span><br><span class="line"><span class="bullet">-</span> <span class="string"><script</span> <span class="string">async</span> <span class="string">src="/js/weather.js"></script></span></span><br></pre></td></tr></table></figure></li><li>之后就本地预览,调整位置,网页的东西我不太清楚,也找不到部件的源码在网页的哪里,位置调账全靠感觉😅</li></ul><h3 id="关于置顶文章的调整"><a href="#关于置顶文章的调整" class="headerlink" title="关于置顶文章的调整"></a>关于置顶文章的调整</h3><h4 id="写在开头-1"><a href="#写在开头-1" class="headerlink" title="写在开头"></a>写在开头</h4><ul><li>最近提交文章发现,设置了置顶的文章并没有真正意义上置顶,但是文章标签上会显示有置顶提示,也仅仅是显示置顶标签而已。<br><img src="http://reuvza1fi.hb-bkt.clouddn.com/img/20220609132122.png"></li></ul><h4 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h4><ul><li>本节内容参考<a href="https://akilar.top/posts/8e1264d1/">Akilarの糖果屋</a>作者大大的文章,整个轮播显示。<br>效果:<img src="http://reuvza1fi.hb-bkt.clouddn.com/img/20220609133320.png"></li></ul><h4 id="具体步骤"><a href="#具体步骤" class="headerlink" title="具体步骤"></a>具体步骤</h4><ol><li>在博客根目录运行<code>Git Bush</code>,:<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">npm</span> <span class="string">install</span> <span class="string">hexo-butterfly-swiper</span> <span class="string">--save</span></span><br></pre></td></tr></table></figure></li><li>添加配置信息:在站点配置文件<code>_config.yml</code>或者主题配置文件<code>_config.butterfly.yml</code>中添加: <figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># hexo-butterfly-swiper</span></span><br><span class="line"><span class="comment"># see https://akilar.top/posts/8e1264d1/</span></span><br><span class="line"><span class="attr">swiper:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span> <span class="comment"># 开关</span></span><br><span class="line"> <span class="attr">priority:</span> <span class="number">5</span> <span class="comment">#过滤器优先权</span></span><br><span class="line"> <span class="attr">enable_page:</span> <span class="string">all</span> <span class="comment"># 应用页面</span></span><br><span class="line"> <span class="attr">timemode:</span> <span class="string">date</span> <span class="comment">#date/updated</span></span><br><span class="line"> <span class="attr">layout:</span> <span class="comment"># 挂载容器类型</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">id</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">recent-posts</span></span><br><span class="line"> <span class="attr">index:</span> <span class="number">0</span></span><br><span class="line"> <span class="attr">default_descr:</span> <span class="string">再怎么看我也不知道怎么描述它的啦!</span></span><br><span class="line"> <span class="attr">swiper_css:</span> <span class="string">https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css</span> <span class="comment">#swiper css依赖</span></span><br><span class="line"> <span class="attr">swiper_js:</span> <span class="string">https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js</span> <span class="comment">#swiper js依赖</span></span><br><span class="line"> <span class="attr">custom_css:</span> <span class="string">https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiperstyle.css</span> <span class="comment"># 适配主题样式补丁</span></span><br><span class="line"> <span class="attr">custom_js:</span> <span class="string">https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper_init.js</span> <span class="comment"># swiper初始化方法</span></span><br></pre></td></tr></table></figure> 建议放在butterfly的配置文件里面,因为我一开始放在了hexo的配置文件里,只在主页显示轮播图,但是点击之后无法跳转,不知道是什么原因,换到主题配置里面,就可以正常跳转了。</li><li>具体参数配置请阅读原文章第三节。</li><li>使用过程中,在文章的<code>front_matter</code>中添加<code>swiper_index</code>配置项即可。 <figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">---</span></span><br><span class="line"><span class="attr">title:</span> <span class="string">文章标题</span></span><br><span class="line"><span class="attr">date:</span> <span class="string">创建日期</span></span><br><span class="line"><span class="attr">updated:</span> <span class="string">更新日期</span></span><br><span class="line"><span class="attr">cover:</span> <span class="string">文章封面</span></span><br><span class="line"><span class="attr">description:</span> <span class="string">文章描述</span></span><br><span class="line"><span class="attr">swiper_index:</span> <span class="number">1</span> <span class="comment">#置顶轮播图顺序,非负整数,数字越大越靠前</span></span><br><span class="line"><span class="meta">---</span></span><br></pre></td></tr></table></figure></li></ol><h3 id="文章加密"><a href="#文章加密" class="headerlink" title="文章加密"></a>文章加密</h3><p>可以通过一个小插件实现,在GitBush中执行以下命令:</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">npm</span> <span class="string">install</span> <span class="string">hexo-blog-encrypt</span> <span class="string">--save</span></span><br></pre></td></tr></table></figure><p>同时在文章头部加入以下字符:</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">password:</span> <span class="string">test</span></span><br><span class="line"><span class="attr">message:</span> <span class="string">测试加密,这里的密码是:test</span></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 主题美化 </category>
</categories>
<tags>
<tag> hexo </tag>
<tag> 主题配置 </tag>
</tags>
</entry>
<entry>
<title>使用Github+PicGo搭建个人图床</title>
<link href="/archives/8cf30b70.html"/>
<url>/archives/8cf30b70.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="写在开头"><a href="#写在开头" class="headerlink" title="写在开头"></a>写在开头</h3><p>每个人都需要一个自己的个人图床,什么是图床?</p><ul><li>图床就是把图片存到服务器上,通过一个公开的链接地址进行访问或者下载</li><li>平时我们将图片夹杂在文章、文档、公众号、博客当中,一般情况下这样似乎没有任何问题,可试想一下若我们需要同时维护多份,不停地在不同渠道重复上传、编辑,图片也会散落各地,难以维护管理,这时候若有个统一的存储地方就可以很轻松维护。</li><li>我们将图片直接放到在线静态页面当中的话,在访问时需要等待全部资源加载,然而一般页面都是图片较大。当我们将图片分离后异步加载,再通过CDN加速,能够大幅提升页面的访问速度。</li></ul><h3 id="Github-PicGo"><a href="#Github-PicGo" class="headerlink" title="Github+PicGo"></a>Github+PicGo</h3><p> 除此之外还有阿里云、腾讯云之类的,收不收费忘记了,反正Github又不收费😅</p><ul><li><strong>下载PicGo客户端</strong><br>在Github里搜索PicGO<br><img src="https://img1.imgtp.com/2022/07/20/n3RfD1g3.png"><br>PicGo的Github<a href="https://github.com/Molunerfinn/PicGo">仓库地址</a>🙋,直接点击访问也可以。<br>在右侧<a href="https://github.com/Molunerfinn/PicGo/releases">release</a>页面选择自己系统的版本下载安装即可。<br><img src="https://img1.imgtp.com/2022/07/20/bueNp9n9.png"><br>安装完成打开,软件页面大概就是这个样子:<br><img src="https://img1.imgtp.com/2022/07/20/8dPVYWxU.png"><br>在连接格式可以自由选择你想要的图片链接格式,也支持剪切板图片上传,搭配<code>Snipaste</code>用起来简直不要太棒🥂</li><li><strong>开始使用</strong><br><img src="https://img1.imgtp.com/2022/07/20/ZA7iJKfl.png"><br>支持很多图床,这里你需要哪个勾选哪个就可以,本文以Github为例。<ul><li>在Github新建一个仓库,存放图片资源,这个部分如果不会的话建议自行检索。</li><li>配置PicGO上Github仓库<br><img src="https://img1.imgtp.com/2022/07/20/IbV6NsQg.png"><ul><li>仓库名就直接复制粘贴刚才新建的仓库名就可以,复制下来把/符号两边的空格删掉</li><li><img src="https://img1.imgtp.com/2022/07/20/46Rx6wb1.png"></li><li>分支名:main</li><li>Token:setting—>开发者设置—>个人token—>创建新Token<br><img src="https://img1.imgtp.com/2022/07/20/mVTBWWDI.png"><br>把生成好的Token复制粘贴进来就可以</li><li>存储路径(这是图片在你Github仓库的位置):img/</li><li><del>jsDelivr充当CDN</del><br><a href="https://www.jsdelivr.com/?docs=gh">获取CDN地址</a><br><del>选取第一个地址规则,把user和后面的都删掉改成你的仓库名</del><br><em><strong>之前我没有配置过这个域名,图片传上去打开博客能正常显示,加上这个域名之后,挂梯子就打不开网页了,我删除规则之后能打开,但是之前用这个规则存储的图片所在的页面是无法访问的,所以😶🌫️</strong></em></li></ul></li></ul></li><li>2022.04.10纠正<br>关于CDN,之前我没有搞清楚是用来做什么的,今天专门去查了一下,直观上讲是用来提高加载速度,之前加上CDN的加速域名后无法访问是由于我在写这篇博客之前一直都是没有使用CDN加速的,配置了CDN之后图片的存储规则发生了更改,导致之前的文章也好,博客的配置文章也好,原来的存储的图片链接失效了,所以无法访问。今天晚上提溜着蒜瓣脑袋把所有图片改成了使用CDN加速之后的新地址,目前为止,本地预览正常。</li><li>所以,那个CDN规则看个人喜好吧,但是千万不要一开始没加,过了一阵子又加上,会秃头的😒😒😒</li></ul><h2 id="写在结尾"><a href="#写在结尾" class="headerlink" title="写在结尾"></a>写在结尾</h2><p>至此,我们已经完成整个图床的搭建,可以开始快乐地玩耍了,后续我会再介绍基于图床的其他用途(如有时间写的话…)。如在搭建过程中有如任何问题也可以在评论区评论与我沟通哦~</p><ul><li>2022.06.09<br>cdn更新,cdn.jsdelivr.net 改为 fastly.jsdelivr.net<br></li><li>2022.07.10<br>将PicGo图床服务器从Github转到七牛云因为国内访问Github实在是太慢了博主又是个有那么一点精神洁癖看着显示不出来的图片看这巨难受(主要是不会鼓捣CDN加速🥲)<br><a href="https://www.bilibili.com/video/BV1Ca411t7ZV?spm_id_from=333.337.search-card.all.click&vd_source=54a192b4e387f3c80648e8e085cb6cc9">参考教程地址</a><br>换地址还是蛮简单的。</li></ul>]]></content>
<categories>
<category> 图床搭建 </category>
</categories>
<tags>
<tag> 个人图床 </tag>
<tag> 教程 </tag>
</tags>
</entry>
<entry>
<title>使用vscode开始Markdown写作之旅</title>
<link href="/archives/62fc2fe9.html"/>
<url>/archives/62fc2fe9.html</url>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h2 id="插件推荐"><a href="#插件推荐" class="headerlink" title="插件推荐"></a>插件推荐</h2><p>vscode默认是支持Markdown的,但是我们还是需要一些额外的插件来辅助。如前文安装中文包一般,到vscode的插件市场中,搜索Markdown关键字,安装这几个插件<br><img src="https://img1.imgtp.com/2022/07/20/vacKmjZS.png"><br><img src="https://img1.imgtp.com/2022/07/20/UYR3HHhl.png"></p><h2 id="标题"><a href="#标题" class="headerlink" title="标题"></a>标题</h2><h3 id="二级标题"><a href="#二级标题" class="headerlink" title="二级标题"></a>二级标题</h3><h4 id="三级标题"><a href="#三级标题" class="headerlink" title="三级标题"></a>三级标题</h4><h5 id="四级标题"><a href="#四级标题" class="headerlink" title="四级标题"></a>四级标题</h5><h6 id="五级标题"><a href="#五级标题" class="headerlink" title="五级标题"></a>五级标题</h6><h2 id="代码块"><a href="#代码块" class="headerlink" title="代码块"></a>代码块</h2><p>代码块通过两行 ``` 符号框出,如果你写的代码是某种语言,那么可以在第一行末尾加上这个语言的名字,代码块内的代码就会执行对应的高亮语法,例如python</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">print</span>(<span class="number">1</span>+<span class="number">1</span>);</span><br></pre></td></tr></table></figure><h2 id="文章内代码行"><a href="#文章内代码行" class="headerlink" title="文章内代码行"></a>文章内代码行</h2><p>正文中的代码,则通过输入`` 框出<br>正文中的代码<code>hexo douban </code></p><h2 id="列表"><a href="#列表" class="headerlink" title="列表"></a>列表</h2><p>有序列表,输入数字,加一个句点,然后空格即可;可以缩进空置多级列表;</p><ol><li>123</li><li>456</li><li>789<ol><li>123<ol><li>123<ol><li>234</li></ol></li></ol></li></ol></li></ol><h2 id="无序列表"><a href="#无序列表" class="headerlink" title="无序列表"></a>无序列表</h2><ul><li>123<ul><li>123<ul><li>123</li></ul></li></ul></li></ul><h2 id="加粗和倾斜"><a href="#加粗和倾斜" class="headerlink" title="加粗和倾斜"></a>加粗和倾斜</h2><p><strong>加粗</strong><br><em>倾斜</em><br><em><strong>加粗和倾斜</strong></em></p><h2 id="插入网络图片"><a href="#插入网络图片" class="headerlink" title="插入网络图片"></a>插入网络图片</h2><p><img src="https://img1.imgtp.com/2022/07/18/NwdsX47W.jpg" alt="示例"></p>]]></content>
<categories>
<category> Markdown草稿 </category>
</categories>
<tags>
<tag> Markdown </tag>
<tag> vscode </tag>
</tags>
</entry>
</search>