Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all 1877 articles
Browse latest View live

New Post: Workaround on big excel files and memory issues?

$
0
0
I've been working with a program in C#, that creates excel reports from several SQL tables, in separate sheets. But this particular report I'm on right now has a large ammount of data: about 5 sheets of 15k rows with somewhere around 80 columns each.

The thing is, it's so large that manipulating a single workbook with all the cells in it spins the process out of control, giving out of memory errors.

I was wondering if there is a way to workaround with this, peharps being able to work on a single sheet at a time and appending it to the file without having to load the whole workbook (as in: create a sheet, load it up, save it then the next one).

Any ideas?

Commented Unassigned: Date value as text in excel file [9444]

$
0
0
I am trying to set a text value to one of my columns.
Text value is 2015/06/03 15:15

Below is the code, that I use to set this column

excelWorkSheet.Cell(j + 1, k).SetDataType(XLCellValues.Text);
excelWorkSheet.Cell(j + 1, k)
.Style.NumberFormat.SetNumberFormatId(0);
excelWorkSheet.Cell(j + 1, k).Value = cellValue;

This is converting my string as a number.

How could I show this value as a text(Not as date time or a number)
Comments: If you prefix cellValue with apostrophe the Excel will treat cell content as a text. ``` cellValue = "'2015/06/03 15:15"; // notice apostrophe before 2015 ws.Cell(1, 1).Value = cellValue; OR string timeString = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); string stringForExcel = "'" + timeString; ws.Cell(1, 2).Value = stringForExcel; ``` Not sure if it is the "correct" way, but works for me. Cheers Olaf

Created Unassigned: ClosedXML does not preserve style [9454]

$
0
0
So this is my code

```
using (var document = new XLWorkbook(root + outFolder + copied))
{
var sheet = document.Worksheets.First();
var allRows = sheet.Rows();
foreach (var currentRow in allRows)
{
var allCells = currentRow.Cells();
foreach (var cell in allCells)
{
var cVal = cell.Value.ToString();
if (dict.ContainsKey(cVal))
{
cell.Value = dict[cVal];
}
}
}
document.SaveAs(root + outFolder + copied);
}
```

This is how the Excel file looked before editing with ClosedXML: http://i.imgur.com/jjBWsUJ.png

This is how it looks after: http://i.imgur.com/qH8DrhO.png

As you can see, there are a bunch of styles it isn't saving. OpenXML does not do this.

Commented Unassigned: ClosedXML does not preserve style [9454]

$
0
0
So this is my code

```
using (var document = new XLWorkbook(root + outFolder + copied))
{
var sheet = document.Worksheets.First();
var allRows = sheet.Rows();
foreach (var currentRow in allRows)
{
var allCells = currentRow.Cells();
foreach (var cell in allCells)
{
var cVal = cell.Value.ToString();
if (dict.ContainsKey(cVal))
{
cell.Value = dict[cVal];
}
}
}
document.SaveAs(root + outFolder + copied);
}
```

This is how the Excel file looked before editing with ClosedXML: http://i.imgur.com/jjBWsUJ.png

This is how it looks after: http://i.imgur.com/qH8DrhO.png

As you can see, there are a bunch of styles it isn't saving. OpenXML does not do this.
Comments: The styles in the first and second images look the same to me - could you be more specific about which styles are not being saved?

Created Unassigned: Unable to open .xlsx from iPad [9455]

$
0
0
I have a strange behaviour when I try to open a ClosedXML file from iPad.

A blank page is shown, with the message: filename.xlsx "Office Open XML Spreadsheet" file-size.
If I choose to open it with Numbers, the application doesn't recognize it as an Excel worksheet and suddenly crashes. I then installed Microsoft Excel for iPad, which finally succeeded in opening the file (!).

The problem is only related to .xlsx files generated with ClosedXML: if use Excel for Windows to create a new .xlsx file and then I send it to my iPad, the file opens correctly, both in Quick preview and in Numbers.

New Comment on "Evaluating Formulas"

$
0
0
Hi, is VLOOKUP already supported? i'm havig a syntax error everytime i try to get row values on the cells with VLOOKUP. a reply would be really helpful! Thanks!

Created Unassigned: ClosedXML read row with VLOOKUP formula [9456]

$
0
0

im currently working on a project that reads data from excel but im having errors with my code because the excel cells have vlookup formulas in it. is there a way for xlosedxml to read row values with vlookup formulas? Thanks!nks!


```
if (rowValue.Cell(colnum).HasFormula)
{
((IDictionary<String, Object>)item)[field] = rowValue.Cell(colnum).Value.ToString();
}
```

New Post: Workaround on big excel files and memory issues?

$
0
0
I'm having a similar issue (except one very large sheet rather than 5 small ones). I've seen comments elsewhere that suggest moving to x64, but I'm not convinced that'll solve the issue for me since users are likely to be on 4gb ram machines, and if I'm hitting 1.7gb when after around 1/4 of one sheet is loaded, I'd expect to get considerably larger before all the data was there (let alone for the actual save processess).

Looking at the object model, it looks like cells don't get written back immediately to the representation of the file (rather they kick around until save or saveas is called), which is obviously going to exacerbate the situation. That is to say, there are two points where OOM exceptions show up:
  1. When inserting data/manipulating the sheet (Too many XLCell objects floating around, I think)
  2. When saving the sheet to disk (Haven't dug into this; I'm just hoping that internally it's not using XmlSerializer, because this is OMGBAD for memory footprint)
I'm wondering whether it would be possible to optimize the ClosedXML cell model to explicitly flush cells on command to reduce its memory footprint, and potentially allow saving in blocks instead of all at once. After all, there are programs that do handle this much data even on x86 machines (e.g. Access from experience, and probably most respectable DBs in any event, especially if Access can do it). Obviously the age old adage of don't use Excel as a DB does apply etc. but in this case, since Excel itself can handle that much data on users' machines, it would be nice if the solution we're using to build the files could as well!

New Post: Workaround on big excel files and memory issues?

$
0
0
I've been doing some profiling and digging through the code to see what's going on with memory; I've got a test program which generates about 60 columns of dummy data and it throws OOM Exceptions when I try to generate 100,000 rows. This is on Windows 10, 64-bit, with 8 GB of memory.

It's possible that the underlying OpenXML libraries from Microsoft are using XMLSerializer, but that's not something that ClosedXML can do much about. As far as I can tell, ClosedXML doesn't use XMLSerializer directly.

The bulk of the problem does seem to be the number of XLCell objects allocated. Reducing their size would help, but I don't see an easy way of doing that. Every single XLCell ultimately allocates its own XLStyle object (which in turn has an Alignment, Border, Fill, etc.); the library doesn't re-use XLStyle objects across multiple cells. It would require a pretty significant change to the style design to make that re-use happen.

A little bit of breathing room would be gained by removing the _trimmedAddress and _columnLetter members from XLAddress; these are being used to cache values which can be computed. Removing them will reduce the memory pressure - since every XLCell has and XLAddress, those two cached values are being stored for every single cell allocated, which adds up when we're talking about hundreds of thousands (or even millions) of cells.

Commented Unassigned: ClosedXML does not preserve style [9454]

$
0
0
So this is my code

```
using (var document = new XLWorkbook(root + outFolder + copied))
{
var sheet = document.Worksheets.First();
var allRows = sheet.Rows();
foreach (var currentRow in allRows)
{
var allCells = currentRow.Cells();
foreach (var cell in allCells)
{
var cVal = cell.Value.ToString();
if (dict.ContainsKey(cVal))
{
cell.Value = dict[cVal];
}
}
}
document.SaveAs(root + outFolder + copied);
}
```

This is how the Excel file looked before editing with ClosedXML: http://i.imgur.com/jjBWsUJ.png

This is how it looks after: http://i.imgur.com/qH8DrhO.png

As you can see, there are a bunch of styles it isn't saving. OpenXML does not do this.
Comments: Thanks for the reply. There is a blueprint that I use (it's the blue logo top left corner) which is automatically added to every page. ClosedXML preserves all styles perfectly except for the "blueprint."

New Post: Date time format in cell read issue

$
0
0
Hi ,
i have a cell is formatted as datetime,
where every time i try to get the datetime it return me value .

var v = ws1.cell(1,2).value

Any good way to retrieve the datetime formatted value ?

Created Unassigned: How to remove autofilter? [9457]

$
0
0
How to remove autofilter from workbook when convert to excel?

New Comment on "Documentation"

$
0
0
Amazing utility, thanks for your effort !!!

Reviewed: ClosedXML 0.76.0 (Aug 18, 2015)

$
0
0
Rated 5 Stars (out of 5) - This is really amazing ! Thank you for all your hard work

Reviewed: ClosedXML 0.76.0 (Aug 18, 2015)

$
0
0
Rated 5 Stars (out of 5) - This is really amazing ! Thank you for all your hard work. I had to read big excel sheets into my application for processing, and it works really well, everytime !

New Post: Out of Memory Exception when exporting more than 50k

$
0
0
I am using closedxml to export datatable to excel in asp.net. it works fine if i export less than 50k rows but throwing exception when i export more rows. It has 31 columns. I am Spliting the datatable to 10000 rows then adding the datatable to a seperate sheet. Would appreciate if some one help me. Below is the code.
   XLWorkbook wb = new XLWorkbook();

    foreach (DataTable dtdiv in splitdt) 
    {
        foreach (DataRow row in dtdiv.Rows)//to remove any special characters to avoid format                   exception(the datatable has xml content)
        {
            for (int i = 0; i < dtdiv.Columns.Count; i++)
            {
                if (dtdiv.Columns[i].DataType == typeof(string))
                {
                    if (row[i] != System.DBNull.Value)
                    {
                        row[i] = ReplaceHexadecimalSymbols((string)row[i]);
                    }
                }
            }
        }
        string newString = "report_" + k;

        wb.AddWorksheet(dtdiv, newString);
        k++;

    }


        Response.Clear();
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("content-disposition", "attachment;filename=" + (String)Session["MatrixOutputFileName"]);

    using (MemoryStream memoryStream = new MemoryStream())
    {
        wb.SaveAs(memoryStream);
        memoryStream.WriteTo(Response.OutputStream);
        memoryStream.Close();
    }
    Response.End();

New Post: Out of Memory Exception when exporting more than 50k

$
0
0
I had the same issue with Closed XML running out of memory with 100K+ rows and 65 columns running in a 32bit environment. It does not run out of memory on a 64bit bit server with IIS but is very slow.

My solution was to generate a very basic spreadsheet using the Open XML dll. What took over 25 minutes to generate with Closed XML generated in less than 5 minutes using the basic Open XML approach. But be advised that there was no formatting or any other processing whatsoever.

New Post: Plain Text Export

$
0
0
Hi everybody, I want to know if there is a way to export from a xlsx to a txt file using ClosedXml Library?

My best regards.
José

New Post: How Can I Un-Encrypt (while knowing the password) a .xlsx file before or while loading it to a XLWorkbook?

$
0
0
I have a excel file with data. When I tried to load the file:

using (var wb = new XLWorkbook(path))
{
}

it wont load. I get an error of: 'System.IO.FileFormatException' occurred in mscorlib.dll

Additional information: File contains corrupted data.

Once I go into the excel file and remove the encryption it works. Is there a way for me to remove the encryption of the file before I open it or while I am opening it?

New Post: Out of Memory Exception when exporting more than 50k

$
0
0
Thank you for the response. Will Try using OpenXML. Is there any limitation for OpenXML.Can you please point to any place where i can check an example.
Viewing all 1877 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>