NPOI 1.2.3教程 -19 读取模板Template
2011-01-23 16:19
495 查看
using System; using System.Text; using System.IO; using NPOI.HSSF.UserModel; using NPOI.HPSF; using NPOI.POIFS.FileSystem; using NPOI.SS.UserModel; namespace GenerateXlsFromXlsTemplate { class Program { static void Main(string[] args) { InitializeWorkbook(); Sheet sheet1 = hssfworkbook.GetSheet("Sheet1"); //create cell on rows, since rows do already exist,it's not necessary to create rows again. sheet1.GetRow(1).GetCell(1).SetCellValue(200200); sheet1.GetRow(2).GetCell(1).SetCellValue(300); sheet1.GetRow(3).GetCell(1).SetCellValue(500050); sheet1.GetRow(4).GetCell(1).SetCellValue(8000); sheet1.GetRow(5).GetCell(1).SetCellValue(110); sheet1.GetRow(6).GetCell(1).SetCellValue(100); sheet1.GetRow(7).GetCell(1).SetCellValue(200); sheet1.GetRow(8).GetCell(1).SetCellValue(210); sheet1.GetRow(9).GetCell(1).SetCellValue(2300); sheet1.GetRow(10).GetCell(1).SetCellValue(240); sheet1.GetRow(11).GetCell(1).SetCellValue(180123); sheet1.GetRow(12).GetCell(1).SetCellValue(150); //Force excel to recalculate all the formula while open sheet1.ForceFormulaRecalculation = true; WriteToFile(); } static HSSFWorkbook hssfworkbook; static void WriteToFile() { //Write the stream data of workbook to the root directory FileStream file = new FileStream(@"test.xls", FileMode.Create); hssfworkbook.Write(file); file.Close(); } static void InitializeWorkbook() { //read the template via FileStream, it is suggested to use FileAccess.Read to prevent file lock. //book1.xls is an Excel-2007-generated file, so some new unknown BIFF records are added. FileStream file = new FileStream(@"template/book1.xls", FileMode.Open,FileAccess.Read); hssfworkbook = new HSSFWorkbook(file); //create a entry of DocumentSummaryInformation DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation(); dsi.Company = "NPOI Team"; hssfworkbook.DocumentSummaryInformation = dsi; //create a entry of SummaryInformation SummaryInformation si = PropertySetFactory.CreateSummaryInformation(); si.Subject = "NPOI SDK Example"; hssfworkbook.SummaryInformation = si; } } }
相关文章推荐
- Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template
- Xamarin XAML语言教程构建ControlTemplate控件模板 (四)
- NPOI 1.2.3教程 -21 下载Download
- NPOI 1.2教程 – 3.1 基于.xls模板生成Excel文件
- Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template
- C# .Net :Excel NPOI导入导出操作教程之将Excel文件读取并写到数据库表,示例分享
- Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template
- Xamarin XAML语言教程构建ControlTemplate控件模板 (二)
- Xamarin XAML语言教程构建ControlTemplate控件模板 (三)
- Grafana使用教程之template(模板)
- NPOI 1.2.3教程 -22 画图Drawing
- C#使用NPOI读取excel模板,并导出excel
- NPOI 1.2.3教程 -7 单元格高度和宽度HeightAndWidth
- NPOI 1.2.3教程 -23 页眉页脚HeaderFooter
- 教程:SpagoBI开源商业智能之XML Template 图表模板
- Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template
- NPOI 1.2.3教程 -8 打印Print
- NPOI 1.2.3教程 -24 下拉框DropDownList
- Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template
- NPOI 1.2.3教程 -9 格式化Format