关于读取Excel模板对模板读写操作

0
17

关于读取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

<

发布回复

请输入评论!
请输入你的名字