日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

c# 操作excle

發布時間:2023/12/9 C# 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c# 操作excle 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

添加引用 ?Microsoft.Office.Interop.Excel;

添加命名空間?using Excel = Microsoft.Office.Interop.Excel;

//創建接口變量------------------------------------------

_Workbook _xlWorkBook = null; Worksheet _xlWorkSheet = null; Excel.Application _xlApp = null;

//創建excle Application----------------------------------

_xlApp= new Excel.Application(); //_xlApp.DisplayAlerts = false; //設置報警窗口 _xlApp.Visible = true; //設置顯示// _xlApp.ScreenUpdating = false; //設置屏幕刷新

//創建workbook ----------------------------------------

//打開已存在的workbook path是文件路徑 _xlWorkBook = _xlApp.Workbooks.Open(path, System.Type.Missing, System.Type.Missing, System.Type.Missing,System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);

//創建worksheet--------------------------------------------

//得到指定的sheet //Excel.Worksheet xlsWorkSheet = (Worksheet)xlsWorkBook.Worksheets["2013年"]; _xlWorkSheet = (Worksheet)_xlWorkBook.Sheets["2013年"];//得到指定的sheet //_xlWorkSheet =(Worksheet) _xlWorkBook.ActiveSheet;//得到當前活躍sheet

//獲取所有sheet

Sheets xlsWorkSheets = _xlWorkBook.Worksheets; foreach (var s in xlsWorkSheets) {Worksheet xlsWorkSheet = s as Worksheet;string ss= xlsWorkSheet.Name; }

//增加sheet頁

// Worksheet workSheet = (Worksheet)_xlWorkBook.Worksheets.Add(System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);

?//創建Excel.Range----------------------------------------------------- 

//獲取單元格內容var cell= (Range)_xlWorkSheet.Cells[1, 3];var cellvalue = cell.Value.ToString();string pathd = @"c:\wellname.txt";_xlWorkSheet.Hyperlinks.Add(cell, pathd); //添加超鏈接 //RowHeight "1:1"表示第一行, "1:2"表示,第一行和第二行 ((Excel.Range)_xlWorkSheet.Rows["1:1", System.Type.Missing]).RowHeight = 100;//ColumnWidth "A:B"表示第一列和第二列, "A:A"表示第一列((Excel.Range)_xlWorkSheet.Columns["A:B", System.Type.Missing]).ColumnWidth = 10;Excel.Range excelRange = _xlWorkSheet.get_Range(_xlWorkSheet.Cells[10, 5], _xlWorkSheet.Cells[10, 5]);excelRange.Select(); //選中區域_xlApp.ActiveWindow.FreezePanes = true;//凍結字段excelRange.Borders.LineStyle = 1; //區域邊框線型excelRange.Borders.get_Item(XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlContinuous;//區域頂部邊框虛線excelRange.Borders.get_Item(XlBordersIndex.xlEdgeBottom).Weight = Excel.XlBorderWeight.xlMedium; //單元格下邊框線粗細excelRange.Borders.get_Item(XlBordersIndex.xlEdgeBottom).ColorIndex = 3;//邊框色彩excelRange.Font.Size = 15;//字體大小excelRange.Font.Underline = true;//下劃線excelRange.HorizontalAlignment = XlHAlign.xlHAlignCenter;//字體在單元格內的對其方式excelRange.ColumnWidth = 15;//單元格的寬度 excelRange.Cells.Interior.Color = System.Drawing.Color.FromArgb(255, 204, 153).ToArgb();//單元格的背景色//合并單元格excelRange.Merge(excelRange.MergeCells);_xlWorkSheet.get_Range("A15", "B15").Merge(_xlWorkSheet.get_Range("A15", "B15").MergeCells);

  

  

轉載于:https://www.cnblogs.com/crhdyl/p/4959029.html

總結

以上是生活随笔為你收集整理的c# 操作excle的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。