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

New Post: "unreadable content" error when opening Excel file created via ClosedXML

$
0
0
SolanumVexus wrote:
I was getting a very similar error when downloading Excel files from an ASP.NET site.  Turns out I also needed the Content-Length header.  Here's a code snippet:   MemoryStream stream = export.ExportEx(types, ids); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"; Response.AddHeader("content-disposition", "attachment;filename=\"AnalysisExport.xlsx\""); Response.AddHeader("Content-Length", stream.Length.ToString()); stream.WriteTo(Response.OutputStream); stream.Close();
Thank you SolanumVexus. You solved my problem with the Content-Length header.

Commented Unassigned: Slow performance of IXLRow.InsertRowsAbove() / InsertRowsBelow() [9011]

$
0
0
Inserting lots of rows gets disproportionately slower the more rows you insert.

worksheet.Rows(1).InsertRowsBelow(1000); - OK
worksheet.Rows(1).InsertRowsBelow(10000); - Slow
worksheet.Rows(1).InsertRowsBelow(100000); - I gave up waiting...

It looks like there is a hash collision with RangeShiftedRowsDelegate / RangeShiftedColumnsDelegate. One of these delegates is created for each row, but each delegate object returns the same value of .GetHashCode().

When XLRangeBase.Dispose() is called, it removes the delegates for the 10000 rows just created one by one. The MulticastDelegate therefore has to search through all items one-by-one (because they are all in the same hash bucket). As this is done row by row, the performance is proportional to the square of the number of rows (it has to search ( 10000 * 10000 / 2 ) items to do all the removals).

I'm working on a fix (involving changing from delegates to a HashSet of the objects involved) so a patch may be available later.
Comments: So i try to use threadpool to deal Dispose method,And i don't find any wrong with the threadpool XLRangeRows.cs Try: ThreadPool.QueueUserWorkItem(new WaitCallback((x) => { if (_ranges != null) _ranges.ForEach(r => r.Dispose()); }));

New Post: It's very slow when insert new row with bigger rownumber

$
0
0
I try to add some rows in the excel,and is used like below:

worksheet.Rows(1).InsertRowsBelow(1000); - OK
worksheet.Rows(1).InsertRowsBelow(10000); - Slow
worksheet.Rows(1).InsertRowsBelow(100000); -Very Slow

And I hope the developer can try solved it,and now i ues the thread pool to make it faster,

like

ThreadPool.QueueUserWorkItem(new WaitCallback((x) =>
        {
            if (_ranges != null)
                _ranges.ForEach(r => r.Dispose());

}));

PS:

If you can add some rows at once time . like

worksheet.FirstRow().InsertRowsBelow(10,5);

And it can be added 5 rows at once. It can be better.
Tanks

Created Unassigned: Crashes on XLWorkbook workbook = new XLWorkbook(filename); [9316]

$
0
0
Hello!

I get an InvalidOperationException ("Sequence contains no matching element") when I try to open the attached Excel document. The attached document can be opened with Excel 2010.

I have downloaded the source and found that crasch is on the row below (when loading comments I think):

shape = xdoc.Root.Elements().First(e => (string)e.Attribute("type") == "#_x0000_t202");

Call stack:

at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\ClosedXML\ClosedXML\Excel\XLWorkbook_Load.cs:line 334
at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\ClosedXML\ClosedXML\Excel\XLWorkbook_Load.cs:line 47
at ClosedXML.Excel.XLWorkbook.Load(String file) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\ClosedXML\ClosedXML\Excel\XLWorkbook_Load.cs:line 36
at ClosedXML.Excel.XLWorkbook..ctor(String file, XLEventTracking eventTracking) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\ClosedXML\ClosedXML\Excel\XLWorkbook.cs:line 642
at ClosedXML.Excel.XLWorkbook..ctor(String file) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\ClosedXML\ClosedXML\Excel\XLWorkbook.cs:line 630
at SHB.SORA.BusinessEntities.Excel.Workbook.Load(String filename) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\services\SHB.SORA.BusinessEntities\Excel\Workbook.cs:line 30
at SHB.SORA.CreateReport.BatchService.<OnStart>b__0() in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\services\SHB.SORA.CreateReport\BatchService.cs:line 44
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

I can open other Excel documents with ClosedXML just fine.

Regards,

Tomas Sondén


Created Unassigned: ClosedXML IXLRow.Delete() very slow [9317]

$
0
0
Hi there,

I love this product and am trying to use it more and more in my day to day

I have an excel file which has loads of empty rows at the end which I need to delete

When i use the IXLRows.Delete or the IXLRow.Delete (when looping through the rows) i have a major performance issue when it attempts the Delete

The code used here is

var lastRow = ws.LastRowUsed().RowBelow();
var lastUnUsedRow = ws.LastRow();

//ws.Range(lastRow.RangeAddress.FirstAddress.ToString(), lastUnUsedRow.RangeAddress.LastAddress.ToString()).Delete(XLShiftDeletedCells.ShiftCellsUp);

IXLRows rows = ws.Rows();

foreach (IXLRow row in rows)
{
if (row.IsEmpty(true))
{
row.Delete();

var lastUnUsedCell = ws.RowsUsed().Count();
}
}

The above code, which is deleting only one row, has been running for a good 7 minutes now and not completed yet.

Is there a better way to do this?

I'm using version version 0.69.1.0 of the DLL

Thank you

New Post: How to make a string value (which is stored as character value in SQL) remain as string when populating cells.

$
0
0
I have a SQL table that has numeric values stored as chars (i.e. '0243', '0170'). When I insert the data into a workbook, it truncates the leading zero thinking it is an insignificant digit even though I declare the cell to have a datatype of text as shown below. I need the leading zero from the data:

indcell = "D" + i.ToString();
worksheet.Cell(indcell).DataType = XLCellValues.Text;
worksheet.Cell(indcell).Value = mySQLReader["CostCenter5"].ToString().ToUpper().Trim();

I have verified that the zero is still present when obtaining the data from the reader as a string as I have a log running that displays the data. All is good in the log. Can you help?

New Post: How to make a string value (which is stored as character value in SQL) remain as string when populating cells.

Source code checked in, #b676058cb4ad0766fc46f08c7350694b5c5c8ad4


Closed Unassigned: Slow performance of IXLRow.InsertRowsAbove() / InsertRowsBelow() [9011]

$
0
0
Inserting lots of rows gets disproportionately slower the more rows you insert.

worksheet.Rows(1).InsertRowsBelow(1000); - OK
worksheet.Rows(1).InsertRowsBelow(10000); - Slow
worksheet.Rows(1).InsertRowsBelow(100000); - I gave up waiting...

It looks like there is a hash collision with RangeShiftedRowsDelegate / RangeShiftedColumnsDelegate. One of these delegates is created for each row, but each delegate object returns the same value of .GetHashCode().

When XLRangeBase.Dispose() is called, it removes the delegates for the 10000 rows just created one by one. The MulticastDelegate therefore has to search through all items one-by-one (because they are all in the same hash bucket). As this is done row by row, the performance is proportional to the square of the number of rows (it has to search ( 10000 * 10000 / 2 ) items to do all the removals).

I'm working on a fix (involving changing from delegates to a HashSet of the objects involved) so a patch may be available later.
Comments: cooper360, I should have a new release soon but in the meantime pick up the latest source code.

New Post: It's very slow when insert new row with bigger rownumber

$
0
0
cooper360, I should have a new release soon but in the meantime pick up the latest source code. It has a fix for this issue.

Source code checked in, #f99038a786b72bcf6d85843538e929f4ce3f378f

$
0
0
Fix load with comments type="#_xssf_cell_comment"

Closed Unassigned: Crashes on XLWorkbook workbook = new XLWorkbook(filename); [9316]

$
0
0
Hello!

I get an InvalidOperationException ("Sequence contains no matching element") when I try to open the attached Excel document. The attached document can be opened with Excel 2010.

I have downloaded the source and found that crasch is on the row below (when loading comments I think):

shape = xdoc.Root.Elements().First(e => (string)e.Attribute("type") == "#_x0000_t202");

Call stack:

at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\ClosedXML\ClosedXML\Excel\XLWorkbook_Load.cs:line 334
at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\ClosedXML\ClosedXML\Excel\XLWorkbook_Load.cs:line 47
at ClosedXML.Excel.XLWorkbook.Load(String file) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\ClosedXML\ClosedXML\Excel\XLWorkbook_Load.cs:line 36
at ClosedXML.Excel.XLWorkbook..ctor(String file, XLEventTracking eventTracking) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\ClosedXML\ClosedXML\Excel\XLWorkbook.cs:line 642
at ClosedXML.Excel.XLWorkbook..ctor(String file) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\ClosedXML\ClosedXML\Excel\XLWorkbook.cs:line 630
at SHB.SORA.BusinessEntities.Excel.Workbook.Load(String filename) in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\services\SHB.SORA.BusinessEntities\Excel\Workbook.cs:line 30
at SHB.SORA.CreateReport.BatchService.<OnStart>b__0() in C:\CCShare\snap\toso06_snap_1406\sora\csharpkod\services\SHB.SORA.CreateReport\BatchService.cs:line 44
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

I can open other Excel documents with ClosedXML just fine.

Regards,

Tomas Sondén


Comments: Pick up latest source code.

Closed Unassigned: Crashes on XLWorkbook workbook = new XLWorkbook(); [9314]

$
0
0
Hello all. Apparently the no-nonsense way to use ClosedXML doesn't have enough nonsense in it. I'm crashing on the very first command it should use!

Attached is a picture of the error
Comments: You need to reference DocumentFormat.OpenXml.dll

Commented Unassigned: ClosedXML IXLRow.Delete() very slow [9317]

$
0
0
Hi there,

I love this product and am trying to use it more and more in my day to day

I have an excel file which has loads of empty rows at the end which I need to delete

When i use the IXLRows.Delete or the IXLRow.Delete (when looping through the rows) i have a major performance issue when it attempts the Delete

The code used here is

var lastRow = ws.LastRowUsed().RowBelow();
var lastUnUsedRow = ws.LastRow();

//ws.Range(lastRow.RangeAddress.FirstAddress.ToString(), lastUnUsedRow.RangeAddress.LastAddress.ToString()).Delete(XLShiftDeletedCells.ShiftCellsUp);

IXLRows rows = ws.Rows();

foreach (IXLRow row in rows)
{
if (row.IsEmpty(true))
{
row.Delete();

var lastUnUsedCell = ws.RowsUsed().Count();
}
}

The above code, which is deleting only one row, has been running for a good 7 minutes now and not completed yet.

Is there a better way to do this?

I'm using version version 0.69.1.0 of the DLL

Thank you
Comments: Row deletes are slow (I need to work on it) but in your particular case you're checking all 1M+ rows in the worksheet to see if they're empty and deleting every single row that you're not using (probably most in the worksheet). Use something like: // Delete empty rows in the used range ws.RangeUsed().Rows(row => row.IsEmpty()).ForEach(row => row.Delete()); or // Delete the entire worksheet rows that are empty (within the range used) ws.RangeUsed().Rows(row => row.IsEmpty()).ForEach(row => row.WorksheetRow().Delete());

New Comment on "Print Areas and Page Breaks"

$
0
0
This is not working i tried this but its remain same.

Created Unassigned: infoBackground [80] is not a valid value for Int32. [9318]

$
0
0
Hi, I'm facing this exception while opening a template. It is in the correct format and I'm able to open it with excel, but somehow it crashes when I attempt to open the file through ClosedXML. Any suggestions?

Commented Unassigned: infoBackground [80] is not a valid value for Int32. [9318]

$
0
0
Hi, I'm facing this exception while opening a template. It is in the correct format and I'm able to open it with excel, but somehow it crashes when I attempt to open the file through ClosedXML. Any suggestions?
Comments: attach the template.

Commented Unassigned: infoBackground [80] is not a valid value for Int32. [9318]

$
0
0
Hi, I'm facing this exception while opening a template. It is in the correct format and I'm able to open it with excel, but somehow it crashes when I attempt to open the file through ClosedXML. Any suggestions?
Comments: I'm sorry but I'm no table to upload the template due to customer privacy. Can you figure out what could be the reason? (colors, formats, comments, hide tabs, etc Thanks in advance)

Commented Unassigned: ClosedXML IXLRow.Delete() very slow [9317]

$
0
0
Hi there,

I love this product and am trying to use it more and more in my day to day

I have an excel file which has loads of empty rows at the end which I need to delete

When i use the IXLRows.Delete or the IXLRow.Delete (when looping through the rows) i have a major performance issue when it attempts the Delete

The code used here is

var lastRow = ws.LastRowUsed().RowBelow();
var lastUnUsedRow = ws.LastRow();

//ws.Range(lastRow.RangeAddress.FirstAddress.ToString(), lastUnUsedRow.RangeAddress.LastAddress.ToString()).Delete(XLShiftDeletedCells.ShiftCellsUp);

IXLRows rows = ws.Rows();

foreach (IXLRow row in rows)
{
if (row.IsEmpty(true))
{
row.Delete();

var lastUnUsedCell = ws.RowsUsed().Count();
}
}

The above code, which is deleting only one row, has been running for a good 7 minutes now and not completed yet.

Is there a better way to do this?

I'm using version version 0.69.1.0 of the DLL

Thank you
Comments: Hi, Thanks for your reply. I tried both samples you provided, and unforunately neither of them work. I have 700+ empty rows at the end of my worksheet that I'm trying to delete and after the delete lines run, those lines are still there. I have also tried to set IncludeFormats to true in case that was stopping it but again that didn't help either ws.RangeUsed().Rows(row => row.IsEmpty(true)).ForEach(row => row.Delete()); //or // Delete the entire worksheet rows that are empty (within the range used) //ws.RangeUsed().Rows(row => row.IsEmpty(true)).ForEach(row => row.WorksheetRow().Delete());

Commented Unassigned: infoBackground [80] is not a valid value for Int32. [9318]

$
0
0
Hi, I'm facing this exception while opening a template. It is in the correct format and I'm able to open it with excel, but somehow it crashes when I attempt to open the file through ClosedXML. Any suggestions?
Comments: Delete the text from the template, you'll probably be able to reproduce the error. If so, attach the empty template.
Viewing all 1877 articles
Browse latest View live


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