Questions tagged [closedxml]

ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files.

ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.

ClosedXML provides a object oriented way to manipulate Excel 2007+ (.xlsx, .xlsm, etc) files (similar to VBA) without dealing with the hassles of XML Documents. It can be used by any .NET language like C# and Visual Basic (VB).

Online resources:

615 questions
51
votes
4 answers

Reading from Excel File using ClosedXML

My Excel file is not in tabular data. I am trying to read from an excel file. I have sections within my excel file that are tabular. I need to loop through rows 3 to 20 which are tabular and read the data. Here is party of my code: string…
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
30
votes
7 answers

Download file with ClosedXML

All How can I download a file so the user sees that it is downloading (like with a stream?) I am currently using ClosedXML, but if I use the SaveAs method, I have to give a hard-coded URL, and if I just give the file name it does not automatically…
Tjekkles
  • 5,352
  • 8
  • 36
  • 53
29
votes
5 answers

Autofit column in ClosedXML.Excel

I understand that the question stupid and from FAQ, but i cant set auto width in excel columns (using ClosedXML.Excel library) my code: var wb = new XLWorkbook(); var wsDep =…
krabcore
  • 885
  • 2
  • 8
  • 22
26
votes
1 answer

What are the differences between the EPPlus and ClosedXML libraries for working with OpenXML?

I'm trying to choose between ClosedXML, EPPlus, and possibly SpreadsheetLight. What reasons might I consider for picking one over the others?
llasarov
  • 2,064
  • 5
  • 27
  • 40
23
votes
6 answers

System.drawing.common the type initializer for 'gdip' threw an exception

This is my code to add a picture to a worksheet. I get the picture as a byte from the database. .Net Core framework version is 2.2.104. This is an API project. In my locale, the code works well. I use the ClosedXML component 0.95.4 version as…
Ömer Yalvaç
  • 231
  • 1
  • 2
  • 3
23
votes
2 answers

How to set a data type for a column with ClosedXML?

I see a lot of examples in documentation where data type for a cell is set: ws.Cell(1, 1).SetDataType(XLCellValues.Text); But when I try to set a data type for a column: ws.Column(1).SetDataType(XLCellValues.Text) ClosedXML generates a 5MB file…
astef
  • 8,575
  • 4
  • 56
  • 95
23
votes
5 answers

Using ClosedXML how to adjust row height to content?

I create cell with text. After that I set WrapText property and column width. var cell = worksheet.Cell("A1"); cell.Style.Alignment.WrapText = true; cell.SetValue("This is very long text"); worksheet.Column(1).Width =…
Vlad
  • 1,377
  • 2
  • 17
  • 29
22
votes
5 answers

How to format currency in ClosedXML as numeric

we're using ClosedXML to convert datatable objects into Excel spreadsheets for presentation to the user. The DataTable object is build simply by assigning all db values (from NHibernate) to strings and then formating them like below: …
Paul Duer
  • 1,100
  • 1
  • 13
  • 32
20
votes
5 answers

Keep excel cell format as text with "date like" data

This seems silly, but I haven't been able to get my values in the format of #/#### to write as the literal string rather than becoming formatted as a date within excel. I'm using ClosedXML to write to excel, and using the following: //…
Kritner
  • 13,557
  • 10
  • 46
  • 72
17
votes
6 answers

How to make Excel wrap text in formula cell with ClosedXml

The problem is that the cell content is not wrapped, when that cell contains a formula referring to a cell with some long string. On CodePlex I found a thread on this issue and a simple code to see the problem: var generated = new XLWorkbook(); var…
horgh
  • 17,918
  • 22
  • 68
  • 123
16
votes
2 answers

Failed to install ClosedXML dependency

I need to install ClosedXML dependency to build a C# project with .net framework 4.7.2 but when trying to install I always get the same error: "Cannot resolve dependency 'SixLabors.Fonts'. Sources used: 'nuget.org', 'Microsoft Visual Studio Offline…
16
votes
5 answers

ClosedXML find last row number

I'm using ClosedXML with C# to modify an Excel workbook. I need to find the last row number used but .RowCount() counts how many rows are in the worksheet. So it is returning 1 million rows when there are only a few thousand. I have tried…
Daniel Blois
  • 187
  • 1
  • 1
  • 7
16
votes
3 answers

Date Formatting in ClosedXML

I have date's in an excel sheet that I am reading from. What I like to do is to force the date to be in mm/dd/yyyy Is there a way to do this in Closed XML. I took at a look https://closedxml.codeplex.com/documentation but could not find how to…
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
16
votes
2 answers

ClosedXML - Creating multiple pivot tables

I am trying to export some data to an excel sheet S1 whose data would be shown as Pivoted views in the next two sheets S2 and S3. I am able to create a single pivot and it works perfect. But when I create two pivots, the consequent Excel file…
Nikhil Girraj
  • 1,135
  • 1
  • 15
  • 33
16
votes
1 answer

Append to excel file with ClosedXML

I need to append new data to existing excel file created with ClosedXML. How can I append to an excel file using ClosedXML? How can I get the row number of the last record and append to that or is there something other? Thanks!
Codesmell
  • 379
  • 1
  • 4
  • 22
1
2 3
40 41