關於讀取Excel模板對模板讀寫操作 1.根據文件名稱(帶盤符的文件目錄),建立SLDocument對象 SLDocument sldocument = new SLDocument(filename); sldocument.SelectWorksheet("Sheet1"); 2.讀取某一單元格 ...
關於讀取Excel模板對模板讀寫操作
1.根據文件名稱(帶盤符的文件目錄),建立SLDocument對象
SLDocument sldocument = new SLDocument(filename); sldocument.SelectWorksheet("Sheet1");
2.讀取某一單元格的內容
string Astring = sldocument.GetCellValueAsString("A" + (3 + i * 4).ToString());
3.寫入某一單元格
sldocument.SetCellValue("A1", DateTime.Now.ToString("yyyy/MM/dd"));
4.設置某一單元格的樣式
SLStyle slstyle0 = new SLStyle(); slstyle0.Alignment.Horizontal = HorizontalAlignmentValues.Center; slstyle0.Alignment.Vertical = VerticalAlignmentValues.Center; sldocument.SetCellStyle("A1", slstyle0);
SLStyle sStyle1 = sldocument.CreateStyle(); sStyle1.Alignment.Horizontal = HorizontalAlignmentValues.Center; sStyle1.Alignment.Vertical = VerticalAlignmentValues.Center; sStyle1.Fill.SetPattern(PatternValues.Solid, System.Drawing.Color.FromArgb(147, 205, 221), System.Drawing.Color.Black); sldocument.SetCellStyle("A1", sStyle2);
5.保存文檔
sldocument.Save();
註:需引用SpreadsheetLight.dll