免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
c#獲取txt,word,excel文檔內(nèi)容方法

  

     獲取txt文檔的內(nèi)容 

 

 

 1 public string ResumeTxt(string path)
 2 {
 3    string str = string.Empty;
 4        
 5    StreamReader reader = new StreamReader(path, System.Text.Encoding.Default);
 6    str = reader.ReadToEnd();
 7  
 8    //再通過查詢解析出來的的字符串有沒有GB2312 的字段,來判斷是否是GB2312格式的,如果是,則重新以GB2312的格式解析
 9    Regex reGB = new Regex("GB2312", RegexOptions.IgnoreCase);
10    Match mcGB = reGB.Match(str);
11    if (mcGB.Success)
12    {
13        StreamReader reader2 = new StreamReader(path, System.Text.Encoding.GetEncoding("GB2312"));
14        str = reader2.ReadToEnd();
15    }
16  
17    return str;
18 } 

 

 

    獲取word文檔的內(nèi)容

 

 1 private string ResumeWord(string path)
 2 {
 3    string str = string.Empty;
 4    Document myWordDoc; 
 5    Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
 6  
 7    object filepath = path;
 8    object oMissing = Missing.Value;
 9   
10    myWordDoc = myWordApp.Documents.Open(ref filepath, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
11          ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
12          ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
13    str = myWordDoc.Content.Text;
14  
15    return str;
16 } 

 

 

    獲取Excel文檔的內(nèi)容
 

 1 private string ResumeExcel(string path)
 2 {
 3    string str = string.Empty;
 4    //創(chuàng)建Application對(duì)象
 5     Microsoft.Office.Interop.Excel.Application xApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
 6    xApp.Visible = false;
 7  
 8  
 9    //得到WorkBook對(duì)象,
10    Microsoft.Office.Interop.Excel.Workbook xBook = xApp.Workbooks._Open(path,
11          Missing.Value, Missing.Value, Missing.Value, Missing.Value,
12          Missing.Value, Missing.Value, Missing.Value, Missing.Value,
13          Missing.Value, Missing.Value, Missing.Value, Missing.Value);
14  
15    //指定要操作的Sheet:
16    Microsoft.Office.Interop.Excel.Worksheet xSheet = (Microsoft.Office.Interop.Excel.Worksheet)xBook.Sheets[1];
17  
18    //讀取,通過Range對(duì)象,但使用不同的接口得到Range
19    for (int i = 1; i <= 100; i++)
20    {
21        for (int j = 1; j <= 100; j++)
22        {
23            Microsoft.Office.Interop.Excel.Range rng = (Microsoft.Office.Interop.Excel.Range)xSheet.Cells[i, j];
24            if (rng.Value2 != null)
25            {
26                str += rng.Value2.ToString();
27            }
28        }
29     }
30  
31      return str;
32 }

 

 

 

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
c# 讀取excel文件的三種方法
excel C# 報(bào)表制作匯總
Excel開發(fā)常用方法 - 槑槑 - 博客園
類似百度文庫(kù)在線預(yù)覽文檔flash版(支持word、excel、ppt、pdf)+在線預(yù)覽文檔html版
使用C#操作word模板
C#實(shí)現(xiàn)向已存在的Excel文件中寫入數(shù)據(jù)實(shí)例(可用兩種方法)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服