npoi

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

两盒软妹~` 提交于 2019-12-17 22:35:55
问题 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

Npoi导出Word

混江龙づ霸主 提交于 2019-12-16 23:57:27
参考网上大神们笔记,完成Word导出。 //创建文档 XWPFDocument doc = new XWPFDocument(); //标题 XWPFParagraph p1 = doc.CreateParagraph(); XWPFRun r1 = p1.CreateRun(); r1.SetBold(true); r1.FontSize = 23; r1.SetText("先进个人基本信息"); r1.SetTextPosition(30); CT_P doc_p1 = doc.Document.body.GetPArray(0);//标题居中 doc_p1.AddNewPPr().AddNewJc().val = ST_Jc.center; //创建表格 XWPFTable table = doc.CreateTable();//行,列 table.RemoveRow(0); #region //for (int i = 0; i < table.Rows.Count; i++)//水平和垂直居中 //{ // for (int j = 0; j < table.Rows.Count; j++) // { // CT_Tc cttc = table.GetRow(i).GetCell(j).GetCTTc(); // CT_TcPr ctpr = cttc

Cannot access a closed stream (NPOI Library)

对着背影说爱祢 提交于 2019-12-13 21:32:47
问题 I am using the following code to create an excel file using NPOI library. I am getting "Cannot access a closed stream" error. I have gone through a few threads and tried to implement the suggestions, but its not working. XSSFWorkbook wb = null; using (FileStream file = new FileStream("D:\\Test_Output.xlsx", FileMode.Open, FileAccess.Read)) { wb = new XSSFWorkbook(file); } MemoryStream mstream = new MemoryStream(); wb.Write(mstream); FileStream xfile = new FileStream(Path.Combine(taskpath,

Add image to Word docx file with NPOI

陌路散爱 提交于 2019-12-13 19:23:57
问题 I'm getting started with NPOI for creating Word documents, and I'm trying to add a simple image to a document, but it's just not showing up. (I can get text to show fine though). This is my code: var wDoc = new XWPFDocument(); var bytes = File.ReadAllBytes(Settings.Configuration.WebsiteRootPath + "images/logo-large.png"); wDoc.AddPictureData(bytes, (int)PictureType.JPEG); I also tried this: var wDoc = new XWPFDocument(); using (Stream s = File.OpenRead(Settings.Configuration.WebsiteRootPath +

How do I add the NPOI library to a .NET Core 1.0 project?

為{幸葍}努か 提交于 2019-12-13 17:22:37
问题 I would like to add the NPOI library to my .NET Core project. I want to work with xls and xlsx files. 回答1: There are 4 steps to add the NPOI library to a .NET Core project. Add net451 as a dependency under the frameworks property in the project.json file and include a reference to the NPOI library: "frameworks": { "netcoreapp1.0": { "imports": [ "dotnet5.6", "portable-net45+win8" ] }, "net451": { "dependencies": { "NPOI": "2.2.1" } } }, In the project.json file, add runtimes as a top-level

'OutOfMemoryException' reading 20mb XLSX file

浪尽此生 提交于 2019-12-13 16:22:38
问题 I'm using NPOI to deal with Excel files. Here's how I'm reading files: using (FileStream stream = File.OpenRead(excelFilePath)) { IWorkbook wb = WorkbookFactory.Create(stream); ... } However, for any XLSX file larger than a few megabytes, it causes memory usage to shot up to about 1GB and eventually throw an OOM exception. Doing some research, I've found out that, strangely, loading a workbook from a File rather than a Stream results in less memory consumption by POI. The closest C#

How set height row in excel with NPOI?

≯℡__Kan透↙ 提交于 2019-12-13 14:54:05
问题 How set height row in c# with NPOI? To specify the width of the columns I'm using XSSFSheet.SetColumnWidth, but what does the command for the height of the cells look like? 回答1: The height of the row is the same: XSSFSheet.GetRow(index).Heigh {get;set;} 回答2: try below approach var row = sheet.CreateRow(0); row.Height = 10 ; //Or sheet.GetRow(1).Height = 10; 来源: https://stackoverflow.com/questions/46147969/how-set-height-row-in-excel-with-npoi

C#. xlsx date cell import to DataTable by NPOI 2.0

十年热恋 提交于 2019-12-13 13:22:46
问题 I'm tried to convert .xlsx file to DataTable format by using NPOI 2.0 library. It's OK, but I have a problem with convert to string date cell. When I try to use construction like row.GetCell(j).ToString() - it's threw exception "Cannot get numeric value from a text cell". I tried to use DateCellValue property, but it also threw this exception. With other cell formats it's work good. Function, that I use it's: private DataTable xlsxToDT(string fileName) { DataTable table = new DataTable();

NPOI writes 0 bytes in the MemoryStream

点点圈 提交于 2019-12-12 18:34:22
问题 I need to save a report to MemoryStream , so I do the next: byte[] result = new byte[0]; using (var stream = new MemoryStream()) { XlsxReport.BuildTaskReport(stream); result = stream.ToArray(); } Below my XlsxReport class: public sealed class XlsxReport { public const string FontName = "Times New Roman"; private const int FontSize = 14; private readonly IWorkbook workbook; // Fonts private readonly IFont boldFont; private readonly IFont defaultFont; // Styles private readonly ICellStyle

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

痴心易碎 提交于 2019-12-12 09:55:32
问题 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