npoi

How can columns be set to 'autosize' in Excel documents created with NPOI?

こ雲淡風輕ζ 提交于 2019-11-29 01:24:18
NPOI is a .NET port of the Java POI project, which allows one to read and write Microsoft Excel documents (as well as other Office formats). NPOI 1.2.2 has introduced support for 'autosizing' columns, whereby the column is set to the width of the widest cell entry in the column. However, there are many reports that this does not work. So is it possible? I've posted this just to answer it, so as to provide a record. It is possible to make columns autosized using NPOI, but you have to add all the data in columns, rather than in rows. Once all the cells have been added to a column @ columnIndex

NPOI导入导出实例代码

江枫思渺然 提交于 2019-11-29 01:03:22
WinForm导出 private string fileName = null; //文件名 private IWorkbook workbook = null; private FileStream fs = null; private bool disposed; public int DataTableToExcel(DataTable data, string sheetName, bool isColumnWritten) { int i = 0; int j = 0; int count = 0; ISheet sheet = null; fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); if (fileName.IndexOf(".xlsx") > 0) // 2007版本 workbook = new XSSFWorkbook(); else if (fileName.IndexOf(".xls") > 0) // 2003版本 workbook = new HSSFWorkbook(); try { if (workbook != null) { sheet = workbook.CreateSheet(sheetName); } else { return

NPOI导出Excel

情到浓时终转凉″ 提交于 2019-11-29 01:02:53
using System; using System.Collections.Generic; using System.Linq; using System.Text; #region NPOI using NPOI.HSSF.UserModel; using NPOI.HSSF.Util; using NPOI.SS.UserModel; using System.Web; using System.IO; using System.Data; using System.Collections; using System.Web.UI.WebControls; #endregion /*======================================================================================== * * * 说 明:导入、导出Excel * 作 者:李朝强 * 日 期:2015/03/28 * * * =====================================================================================*/ namespace TiKu.Common.Office { public class Excel { #region ==========

Trying to create a new .xlsx file using NPOI and write to it

 ̄綄美尐妖づ 提交于 2019-11-28 18:24:46
Edit: I'm trying to write a small console application that will read in lines from an excel spreadsheet, parse the lines and write the fielded data to a new excel file. I'm using .NET and the NPOI library. I finally after much digging found Java documentation for POI on the apache site. Here is my updated code with new errors. This actually creates a readable file except it only writes text to the third column. public static void TransferXLToTable() { DataTable dt = new DataTable(); dt.Columns.Add("City", typeof(string)); dt.Columns.Add("State", typeof(string)); dt.Columns.Add("Zip", typeof

excel导出

老子叫甜甜 提交于 2019-11-28 17:27:27
.NET导出Excel的四种方法及评测 导出 Excel 是 .NET 的常见需求,开源社区、市场上,都提供了不少各式各样的 Excel 操作相关包。本文,我将使用 NPOI 、 EPPlus 、 OpenXML 、 Aspose.Cells 四个市面上常见的库,各完成一个导出 Excel 示例。然后对其代码风格和 性能 做一个横向比较。最后我将说出我自己的感想。 文中所有的示例代码可以在这里下载: https://github.com/sdcb/blog-data/tree/master/2019/20190824-dotnet-excel-compare NPOI NPOI 源自于 Java 写的 Apache POI ,目前最新版本是 2.4.1 。 NPOI 是开源项目,作者是 华人 ,项目地址是: https://github.com/tonyqus/npoi 。 几年前大家导出 Excel 都使用 COM ,但 COM 不方便,这个组件的推出无疑弥补了 .NET 在 Excel 方面组件的空白,大家都说比 COM 好用。 NPOI 还加入了 .NET Core Community组织 。 EPPlus EPPlus 是另一个开源的 Excel 操作库,目前最新版本是 4.5.3.2 。 Github 地址如下: https://github.com/JanKallman

.NET导出Excel的四种方法及评测

China☆狼群 提交于 2019-11-28 15:04:19
.NET导出Excel的四种方法及评测 导出 Excel 是 .NET 的常见需求,开源社区、市场上,都提供了不少各式各样的 Excel 操作相关包。本文,我将使用 NPOI 、 EPPlus 、 OpenXML 、 Aspose.Cells 四个市面上常见的库,各完成一个导出 Excel 示例。然后对其代码风格和 性能 做一个横向比较。最后我将说出我自己的感想。 文中所有的示例代码可以在这里下载: https://github.com/sdcb/blog-data/tree/master/2019/20190824-dotnet-excel-compare NPOI NPOI 源自于 Java 写的 Apache POI ,目前最新版本是 2.4.1 。 NPOI 是开源项目,作者是 华人 ,项目地址是: https://github.com/tonyqus/npoi 。 几年前大家导出 Excel 都使用 COM ,但 COM 不方便,这个组件的推出无疑弥补了 .NET 在 Excel 方面组件的空白,大家都说比 COM 好用。 NPOI 还加入了 .NET Core Community组织 。 EPPlus EPPlus 是另一个开源的 Excel 操作库,目前最新版本是 4.5.3.2 。 Github 地址如下: https://github.com/JanKallman

SSIS Script Task cant find reference to assembly

五迷三道 提交于 2019-11-28 12:31:22
I have an SSIS package that uses a script task to populate a datatable with data from a variety of different file types including excel. I am using NPOI to read in the data from Excel and have put the NPOI.dll file in the same folder as the SSIS package and added it as a reference in the script task. I'm a Noob when it comes to NPOI so I'm only tinkering at the moment, but even still I have fallen at the first hurdle! My script contains the code below (which i copied from this SA answer ): using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; HSSFWorkbook wb; using (FileStream file = new

NPOI 操作Excel

◇◆丶佛笑我妖孽 提交于 2019-11-27 23:47:57
一、NPOI组件导入 右键项目菜单,“管理NuGet程序包” 直接搜索“NPOI”即会出现列表,下载第一个进行安装即可 安装完成后项目引用会出现以下几项 二、基础使用 添加引用 using NPOI.HPSF; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; Excel操作开始 HSSFWorkbook hssfworkbook = new HSSFWorkbook();//先创建Workbook ISheet sheet= hssfworkbook.CreateSheet("Sheet1");//创建sheet页 IRow row1=sheet.CreateRow(0);//创建行 row1.CreateCell(0).SetCellValue("test");//创建单元格并设置值 文件导出 FileStream file = new FileStream(sFilePath, FileMode.Create); hssfworkbook.Write(file); file.Close(); 测试代码(以MVC实例): /// <summary> /// 读取xls内容 /// </summary> /// <returns></returns> public ActionResult Index() { string

Edit existing Excel file C# npoi

房东的猫 提交于 2019-11-27 21:50:50
问题 I want to with a console application C# open an existing excel file and add content to it. NPOI 2.1.1.0 My first approach was simply to add a value to last cell figure I solved that it will solve my other problem. This will read the file correctly with the new content but it will not save it. Output: "Cannot access a closed file.". HSSFWorkbook hssfwb; using (FileStream file = new FileStream(@"c:\testfile.xls", FileMode.Open, FileAccess.ReadWrite)) { hssfwb = new HSSFWorkbook(file); ISheet

Does NPOI have support to .xlsx format?

北慕城南 提交于 2019-11-27 18:19:06
问题 Will NPOI DLL recognize .xlsx file? Currently I'm using NPOI 1.2.5 version DLL for Microsoft Excel 97-2003, but I need to access Excel sheets of extension .xlsx also. Will NPOI support the above? Code snippet: static void Main(string[] args) { XSSFWorkbook xssfwb; using(FileStream file=new FileStream( @"C:\Users\347702\Desktop\Hello.xlsx", FileMode.Open, FileAccess.Read)) { xssfwb=new XSSFWorkbook(file); } ISheet sheet=xssfwb.GetSheet("sheet1"); sheet.GetRow(1048576); Console.WriteLine(sheet