npoi

Convert xlsx file to xls using NPOI in c#

坚强是说给别人听的谎言 提交于 2019-12-30 11:27:13
问题 I've a excel file in *.xlsx format. I want convert this file into *.xls format in my MVC Web application. In my application hosted server there is no Microsoft.Office package. Please let me know how we can achieve it in NPOI with c#. Thanks in advance. 回答1: I found the solution based on the Andy's suggestion. Here is the source code which is customized to convert XLSX to XLS. public static class ConvertXLSXToXLS { public static HSSFWorkbook ConvertWorkbookXSSFToHSSF(XSSFWorkbook source) { /

Trying to edit cell value of existing Excel file using NPOI

安稳与你 提交于 2019-12-29 09:02:11
问题 I have written the following code to edit an Excel file using C# and NPOI library. There are no errors, but after running the code if I open the file, the value of the cell is not edited. What am I doing wrong? namespace Project37 { class Class1 { public static void Main() { string pathSource = @"C:\Users\mvmurthy\Downloads\VOExportTemplate.xlsx"; FileStream fs = new FileStream(pathSource, FileMode.Open, FileAccess.ReadWrite); HSSFWorkbook templateWorkbook = new HSSFWorkbook(fs, true);

运用NPOI操作EXCEL

故事扮演 提交于 2019-12-26 19:01:42
一、引入NPOI程序集 下载地址: http://pan.baidu.com/s/1qWI3Vgo 二、运用NPOI导出成excel文件 1 protected void btnOutExcel_Click(object sender, EventArgs e) 2 { 3 HSSFWorkbook workbook = new HSSFWorkbook();//创建一个工作薄 4 ISheet sheet1 = workbook.CreateSheet("学员信息页");//创建一个sheet页 5 IRow rowHeader = sheet1.CreateRow(0);//创建第一行 6 //设置表头内容 7 rowHeader.CreateCell(0, CellType.STRING).SetCellValue("ID");//创建第一行第一列的单元格,设定里面的值为ID 8 rowHeader.CreateCell(1, CellType.STRING).SetCellValue("姓名"); 9 rowHeader.CreateCell(2, CellType.STRING).SetCellValue("用户名"); 10 rowHeader.CreateCell(3, CellType.STRING).SetCellValue("手机号"); 11

C# NPOI Excel应用

左心房为你撑大大i 提交于 2019-12-26 17:11:19
参考链接 https://www.cnblogs.com/tangpeng97/p/7839189.html https://www.cnblogs.com/chenyanbin/archive/2019/05/10/10832614.html 准备工作 安装好插件后,需要重写方法 //年代有点久,忘记为什么要重写了 /// <summary> /// 重写Npoi方法 /// </summary> public class NpoiMemoryStream : MemoryStream { public NpoiMemoryStream() { AllowClose = true; } public bool AllowClose { get; set; } public override void Close() { if (AllowClose) base.Close(); } } Excel文件转DataTable 注意点 xlsx和xls 需要分别对应两个类型,xlsx对应XSSFWorkbook,xls对应HSSFWorkbook 根据文件路径得到Excel转Datatable XSSFWorkbook workbook = new XSSFWorkbook("D:\\test.xlsx");//这段没测试,应该可以用 NPOI.SS.UserModel.ISheet

npoi SetCellFormula custom formula in VBA

限于喜欢 提交于 2019-12-25 07:04:23
问题 I have an application that fills with data an excel template .Template is .xlsm .In template I created vba function called SumByColor when i try to set a cell formula to this function i get this error : {"Name 'SumByColor' is completely unknown in the current workbook"} I set formula like this : sheet.GetRow(rowIndex).GetCell(startPos + 2).SetCellFormula(string.Format("SumByColor($AQ$7,F{0}:AI{0})",rowIndex+1)); 来源: https://stackoverflow.com/questions/25077009/npoi-setcellformula-custom

NPOI Page Breaks

↘锁芯ラ 提交于 2019-12-25 01:55:58
问题 I am using the NPOI framework to generate a 97/2003 Excel workbook. I need to set a page break every 44 rows and from the example provided in the framework download, the code to do this is: sheet.SetRowBreak(int row) I can verify these are setting a collection of row integers but when opening the document and viewing the Page Break preview, there is but a single page that encompasses the entire worksheet. Sample Code below: for(int rowCount = 0; rowCount < MaxRows; rowCount += 44) { worksheet

NPOI export excel all columns but last become blank

我怕爱的太早我们不能终老 提交于 2019-12-24 10:44:32
问题 I am investing the AutoSizeColumn() of NPOI Excel exporting. From this SO question, I know that when exporting a DataTable to excel, have to write all data inside one column before calling the AutoSizeColumn() . Example: (as from this SO answer: HSSFWorkbook spreadsheet = new HSSFWorkbook(); DataSet results = GetSalesDataFromDatabase(); //here, we must insert at least one sheet to the workbook. otherwise, Excel will say 'data lost in file' HSSFSheet sheet1 = spreadsheet.CreateSheet("Sheet1");

c# NPOI为Excel添加批注

我是研究僧i 提交于 2019-12-24 10:44:15
这几天在为公司做员工报休系统,在管理后台需要将所有人员的报休情况导出Excel。 因为导出Excel是xlsx的,在网上找了一大堆用NPOI添加批注的方法,结果报错! 先看看导出的格式: 用网上的示例IDE不报错: HSSFPatriarch patr = (HSSFPatriarch)sheet2.CreateDrawingPatriarch(); HSSFComment comment2 = (HSSFComment)patr.CreateCellComment(new HSSFClientAnchor(0, 0, 0, 0, 0, 0, 0, 0)); comment2.String = new HSSFRichTextString(isRest.memo); comment2.Author = @"ycrc"; agtRestCells.CellComment = comment2; 但在调试的时候: 结果发现,网上的示例是针对Xls版本的,也就是说在创建工作薄的时候用的 HSSFWorkbook,而我用的是XSSFWorkbook。 继续看异常提示,既然有NPOI.XSSF.UserModel.XSSFDrawing这个类型。 然后发现IComment可以不进行强制转换,最后,把单元格的CellComment设置为Comment1就行了 网上一大篇介绍批注的定位

Password protected excel using NPOI

北城以北 提交于 2019-12-24 01:27:19
问题 i have a .net c# application in which im downloading one excel file on button click. the code im using is using NPOI.HSSF.UserModel; using NPOI.HSSF.Util; using NPOI.SS.UserModel; then some codes. HSSFWorkbook book = new HSSFWorkbook(); var sheet = book.CreateSheet("StatusReport"); some code for formatting the excel,then some code for downloading the excel. HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Charset = "utf-16"; HttpContext.Current.Response.ContentEncoding =

NPOI insert row like excel

泄露秘密 提交于 2019-12-23 19:30:40
问题 How can I use NPOI to insert a row like excel? The excel insert command copy the format for the upper row Thanks! 回答1: static void InsertRows(ref HSSFSheet sheet1, int fromRowIndex, int rowCount) { sheet1.ShiftRows(fromRowIndex, sheet1.LastRowNum, rowCount, true, false, true); for (int rowIndex = fromRowIndex; rowIndex < fromRowIndex + rowCount; rowIndex++) { HSSFRow rowSource = sheet1.GetRow(rowIndex + rowCount); HSSFRow rowInsert = sheet1.CreateRow(rowIndex); rowInsert.Height = rowSource