npoi

NPOI formats all cells the same way

安稳与你 提交于 2019-12-10 14:55:26
问题 Please, take a look at the following code snippet. I simply open the excel file myfile.xlsx and I add rows from an object of type List<Account> (where my Account object only has Date , Account and Amount properties), and store the file with the name myoutputfile.xlsx . I would like the cells where I write the dates to have a date format, and the cells where I have amounts to have a numeric format. However, if I try the code below, all cells are formatted with the #.00 format (dates as well).

Copy sheet from one workbook to another using NPOI in C#

北慕城南 提交于 2019-12-10 08:59:02
问题 I need to copy a sheet from one workbook to another. I am trying with the below code, but it is not working: ISheet newSheet = wb.GetSheetAt(0).CopySheet("WeeklyReport"); string filePath = "billing_template2.xlsx"; XSSFWorkbook billingWorkbook; using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { billingWorkbook = new XSSFWorkbook(fs); } billingWorkbook.Add(newSheet); where wb is the source workbook and billingWorkbook is my destination workbook. Note: My destination

How to get the value of cell containing a date and keep the original formatting using NPOI

对着背影说爱祢 提交于 2019-12-10 03:59:39
问题 I have an Excel file that I edited using DevExpress and I am reading using NPOI. When I try to get the value of a date cell as string, it does not keep the original value. For example: In a DevExpress grid I set this value: 2016-08-12 . I want to obtain the same value in my string but instead I get 42689 . My code to get the cell value is like this: ICell cell = row.GetCell(i); cell.SetCellType(CellType.String); string fieldString = cell.StringCellValue; result = result + ";" + FieldValue;

使用npoi导入导出Excel

只谈情不闲聊 提交于 2019-12-09 12:51:52
1、整个Excel表格叫做工作表:WorkBook(工作薄),包含的叫页(工作表):Sheet;行:Row;单元格Cell。 2、NPOI是POI的C#版本,NPOI的行和列的index都是从0开始 3、POI读取Excel有两种格式一个是HSSF,另一个是XSSF。 HSSF和XSSF的区别如下: HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format. XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format. 即:HSSF适用2007以前的版本,XSSF适用2007版本及其以上的。 下面是用NPOI读写Excel的例子:ExcelHelper封装的功能主要是把DataTable中数据写入到Excel中,或者是从Excel读取数据到一个DataTable中。 ExcelHelper类: using System; using System.Collections.Generic; using System.Linq; using System.Text; using NPOI.SS.UserModel; using NPOI

NPOI DataFormat

你。 提交于 2019-12-09 11:45:58
问题 I'm exporting a grid with NPOI v1.2.3, and am having trouble getting cell formatting to work. I have a class that exports a list of objects to an XLS file. A row is created for each object, and a cell is added for each configured property. The cell data format can be set on a per-property level. I've read that you shouldn't create a new style for each cell. I can't hard-code my styles, since my exporter needs to support any class. Instead, I wrote a little cache system that only creates a new

Programmatically export Excel files to XML using xmlMaps

廉价感情. 提交于 2019-12-08 04:10:26
With the Excel addin OfficeExcel2003XMLToolsAddin I've been able to define XML mapping for an Excel Worksheet (this addin converts a range to a XML list) and now I'm able to manually save the Excel file as a XML file, using Save as. Excel correctly produces something like <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Row> <brand>Brand1</brand> <Italian>Description1</Italian> <English>Description2</English> </Row> <Row> <brand>Brand2</brand> <Italian>Description3</Italian> <English>Description4</English> </Row> </Root> Now,

NPOI.dll 在哪里?

感情迁移 提交于 2019-12-06 09:57:08
一、问题 NPOI下载后找不到网上人家说的几个DLL https://bbs.csdn.net/topics/392510552 二、答案: 1、VS2015引用NPOI2.4.1和NuGet的安装方法 https://blog.csdn.net/lgxrobot/article/details/93966536 2、NPOI下载 (github方式) https://www.cnblogs.com/WarBlog/p/9604257.html 核心:用vs打开它,然后重新生成。 最简单是nuget方法,一键安装。 来源: https://www.cnblogs.com/hao-1234-1234/p/11975512.html

NPOI 表格处理

会有一股神秘感。 提交于 2019-12-06 04:14:09
/// <summary> /// 获取单元格类型 /// </summary> /// <param name="cell">目标单元格</param> /// <returns></returns> private static object GetValueType(ICell cell) { if (cell == null) return null; switch (cell.CellType) { case CellType.Blank: return null; case CellType.Boolean: return cell.BooleanCellValue; case CellType.Numeric: return cell.NumericCellValue; case CellType.String: return cell.StringCellValue; case CellType.Error: return cell.ErrorCellValue; case CellType.Formula: default: return "=" + cell.CellFormula; } } /// <summary> /// Excel导入成DataTble /// </summary> /// <param name="file">导入路径

how to download a xls file generated by NPOI in ASP MVC

北慕城南 提交于 2019-12-06 02:50:42
i found an exemple of how to Stream the Excel spreadsheet back to the client but in aspx code. the code is below using (var exportData = new MemoryStream()) { workbook.Write(exportData); string saveAsFileName = string.Format("MembershipExport-{0:d}.xls", DateTime.Now).Replace("/", "-"); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName)); Response.Clear(); Response.BinaryWrite(exportData.GetBuffer()); Response.End(); } i'am working with asp MVC 5 and webApi Controller. I want to migrate this code

export Excel to DataTable using NPOI

醉酒当歌 提交于 2019-12-05 16:49:29
问题 I want to read Excel Tables 2010 xlsx using NPOI and then export data to DataTables but don't know how to use it. Can anyone show me step by step how to export Excel to Datatable? I have downloaded NPOI.dll, added to reference but don't know what further ... 回答1: Here's about the minimum code you can use to convert an Excel file to a DataSet using NPOI: IWorkbook workbook; using (FileStream stream = new FileStream(excelFilePath, FileMode.Open, FileAccess.Read)) { workbook = new HSSFWorkbook