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

Commented Unassigned: While Writing to Excel file its throwing an error "'.', hexadecimal value 0x00, is an invalid character." [9421]

$
0
0
Hi All,

While Writing to Excel File using the ClosedXML facing an issue. Above is the error mentioned into caption which I am getting.

Have attached the Excel File which I am trying to Write by passing the DataSet.

Please Reply ASAP.

Thanks,
Samir.
Comments: Hi, I have same problem. It seems to fail to write the xml and contains invalid characters. Example: * u0010 * u0011 * u0012 * u0013 etc… Stack trace: ``` 場所 System.Xml.XmlUtf8RawTextWriter.InvalidXmlChar(Int32 ch, Byte* pDst, Boolean entitize) 場所 System.Xml.XmlUtf8RawTextWriter.WriteElementTextBlock(Char* pSrc, Char* pSrcEnd) 場所 System.Xml.XmlUtf8RawTextWriter.WriteString(String text) 場所 System.Xml.XmlWellFormedWriter.WriteString(String text) 場所 DocumentFormat.OpenXml.OpenXmlLeafTextElement.WriteContentTo(XmlWriter w) 場所 DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter) 場所 DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w) 場所 DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter) 場所 DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w) 場所 DocumentFormat.OpenXml.OpenXmlPartRootElement.WriteTo(XmlWriter xmlWriter) 場所 DocumentFormat.OpenXml.OpenXmlPartRootElement.SaveToPart(OpenXmlPart openXmlPart) 場所 DocumentFormat.OpenXml.OpenXmlPartRootElement.Save() 場所 DocumentFormat.OpenXml.Packaging.OpenXmlPackage.SavePartContent(OpenXmlPart part) 場所 DocumentFormat.OpenXml.Packaging.OpenXmlPackage.TrySavePartContent(OpenXmlPart part) 場所 DocumentFormat.OpenXml.Packaging.OpenXmlPackage.SavePartContents() 場所 DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose(Boolean disposing) 場所 DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose() 場所 ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath, SpreadsheetDocumentType spreadsheetDocumentType) 場所 ClosedXML.Excel.XLWorkbook.SaveAs(String file) ```

Commented Unassigned: Improve performance [9425]

$
0
0
Hi
There is room for performance improvements in ClosedXML.

To create a performance base line I updated the sandbox example in the branch https://closedxml.codeplex.com/SourceControl/network/forks/AlbinSunnanbo/closedxml?branch=Performance_Example to create a Excel document similar to our production code
(See change set https://closedxml.codeplex.com/SourceControl/network/forks/AlbinSunnanbo/closedxml/changeset/6aedcc8946cc210a4f81224f8e65f2f4feb0ee10 )

I created a pull request with some low hanging fruit fixes: https://closedxml.codeplex.com/SourceControl/network/forks/AlbinSunnanbo/closedxml/contribution/8065

Before the pull request the execution time on my computer was 9.8 seconds, with the pull request applied the execution time was 6.7 seconds. That's an overall 30% improvement on a generate + save cycle.

I have some further fixes in the works, I'll add comments to this issue when the are ready.

// Albin Sunnanbo @ Kentor
Comments: I have looked on XLCell.GetStyle(). It is called from XLColumn.AjustToContents in three locations. All locations use the Style in a read only fashion. However GetStyle does some deep copying (I assume to make it safe to update). This is a bit expensive. I made a prof of concept to bypass the deep copy in https://closedxml.codeplex.com/SourceControl/network/forks/AlbinSunnanbo/closedxml/changeset/5a0007ab6fc55bcc31e0af8b6c0c0bfc55309e5e It speed things up more than 10%, my example is now down to 5 seconds flat. That's good. The bad thing is that my proof of concept punches big holes in the architecture. I don't like big holes. I'd like to create a read only get style, returning an interface IXLReadOnlyStyle or something like that, but I can't figure out how to get it read only all the way down. So that IXLReadOnlyStyle only exposes IXLReadOnlyAlignment and so on. Its a known problem that you can't vary return types in your interfaces like that. Unless you have a good idea I'm prepared to to leave the style handling as it was. When looking at the big picture I see that the Save part now takes about 2/3 of the total execution time. The save part has a much more spread out execution pattern, no big chunks making up most of the time. It would have been fun to get down to 4.9 seconds (50% reduction), but currently I don't have the time to invest to get there as it would require me to get a much more thorough understanding of the code base to get there. In my opinion you may close the issue as done. // Albin

New Post: Inserting Rows without a Loop

$
0
0
Thank you for your quick response!

I've already tried turning off events, but that resulted in my algorithm not working anymore...

Compiling to x64 at least liberated me from the Out of Memory exception, but it's still much more than my machine could ever handle.

It seems I have to rebuild my algorithm from scratch then...

New Comment on "Inserting and Deleting Rows"

$
0
0
I am experiencing the exact some issue... My full code sample (sample doc omitted): using (var workbook = loadWorkbook(fileContent)) { using (var sheet = workbook.Worksheets.FirstOrDefault()) { var successRows = sheet.RowsUsed( (row) => { var lastUsedCell = row.LastCellUsed(); return lastUsedCell != null && lastUsedCell.Value != null && lastUsedCell.Value.ToString() == "Success"; }); successRows.Delete(); var memStream = new MemoryStream(); workbook.SaveAs(memStream); memStream.Seek(0, SeekOrigin.Begin); return memStream; } } Basically just looking for cell's that equal success and removing them from the doc and then saving off to a memory stream... When i later retrieve this workbook from the stream all rows are deleted including the headers... Any help would be greatly appreciated!!

New Comment on "Inserting and Deleting Rows"

$
0
0
I am experiencing the exact some issue... My full code sample (sample doc omitted): using (var workbook = loadWorkbook(fileContent)) { using (var sheet = workbook.Worksheets.FirstOrDefault()) { var successRows = sheet.RowsUsed( (row) => { var lastUsedCell = row.LastCellUsed(); return lastUsedCell != null && lastUsedCell.Value != null && lastUsedCell.Value.ToString() == "Success"; }); successRows.Delete(); var memStream = new MemoryStream(); workbook.SaveAs(memStream); memStream.Seek(0, SeekOrigin.Begin); return memStream; } } Basically just looking for cell's that equal success and removing them from the doc and then saving off to a memory stream... When i later retrieve this workbook from the stream all rows are deleted including the headers... Any help would be greatly appreciated!! I have tried to just foreach over the success records and remove one at a time, this works but is way to slow for the larger documents i have to process.

New Post: searching data in opened document

$
0
0
hello!
how can i search data in opened workbok?

Commented Unassigned: Improve performance [9425]

$
0
0
Hi
There is room for performance improvements in ClosedXML.

To create a performance base line I updated the sandbox example in the branch https://closedxml.codeplex.com/SourceControl/network/forks/AlbinSunnanbo/closedxml?branch=Performance_Example to create a Excel document similar to our production code
(See change set https://closedxml.codeplex.com/SourceControl/network/forks/AlbinSunnanbo/closedxml/changeset/6aedcc8946cc210a4f81224f8e65f2f4feb0ee10 )

I created a pull request with some low hanging fruit fixes: https://closedxml.codeplex.com/SourceControl/network/forks/AlbinSunnanbo/closedxml/contribution/8065

Before the pull request the execution time on my computer was 9.8 seconds, with the pull request applied the execution time was 6.7 seconds. That's an overall 30% improvement on a generate + save cycle.

I have some further fixes in the works, I'll add comments to this issue when the are ready.

// Albin Sunnanbo @ Kentor
Comments: Update: I've been sick for the last 2 weeks so I've had little time to continue working on this (work and other projects getting in the way too). I'll come back to it soon. Sorry.

Created Unassigned: Null reference bug in XLWorkbook_Load [9426]

$
0
0
This manifests itself when opening XSLX files generated by Microsoft ReportViewer control.


XLWorkbook_Load.cs line 857:
```
xlCell._cellValue = cell.InlineString != null ? cell.InlineString.Text.Text.FixNewLines() : String.Empty;
```

should be changed to:

```
xlCell._cellValue = cell.InlineString != null && cell.InlineString.Text != null ? cell.InlineString.Text.Text.FixNewLines() : String.Empty;
```

New Comment on "Pivot Table example"

$
0
0
Hi, I am creating a Pivot Table, and I want to put the resulting table in a tabular form to show the row labels instead of the legend "row labels" and so with the columns. I have tried with the pivotTable.SetLayout(XLPivotLayout.Tabular); and also doing the same with each row label and each row column, but nothing seems to be working, is there something I am missing?

Created Unassigned: Pivot table tabular form closedxml [9427]

$
0
0
I am creating a Pivot Table, and I want to put the resulting table in a tabular form to show the row labels instead of the legend "row labels" and so with the columns.

I have tried with (IXLPivotTable)

pivotTable.SetLayout(XLPivotLayout.Tabular);

pivotTable.SetLayout(XLPivotLayout.Tabular);
and also doing the same with each row label and each row and column, but nothing seems to be working, is there something I am missing?

(Image) http://i.stack.imgur.com/H0lCv.png

Source code checked in, #fec0dad2aedd9836325d4919c6ae4e88064f3d65

$
0
0
Add null check for cell.InlineString.Text

Closed Unassigned: Null reference bug in XLWorkbook_Load [9426]

$
0
0
This manifests itself when opening XSLX files generated by Microsoft ReportViewer control.


XLWorkbook_Load.cs line 857:
```
xlCell._cellValue = cell.InlineString != null ? cell.InlineString.Text.Text.FixNewLines() : String.Empty;
```

should be changed to:

```
xlCell._cellValue = cell.InlineString != null && cell.InlineString.Text != null ? cell.InlineString.Text.Text.FixNewLines() : String.Empty;
```
Comments: Added the fix. Thanks.

Source code checked in, #2f47aad067bc3fc10a92c70aeb9d3cc4857d013c

$
0
0
When saving, don't create a cell object if it's not going to be used.

New Post: PatterColor, PatternStyle and Gradient missing

$
0
0
Good afternoon!

Sorry to bring this thread back from the dead but has there been any progress on this? Currently working on a project which requires a gradient on the top row and this is the closest thing I could find to a lead! Thanks!

Chumba

New Post: Get Table's AutoFilter Values

$
0
0
Is it possible to do without reflection?

I see Filters property is public, but XLAutoFilter class is internal(

Commented Unassigned: Reduce memory usage during SaveAs() [9410]

$
0
0
I'm trying to use ClosedXml to generate a large sheet (620K rows, 10 columns, CSV version approx 104 MB), loading the data and creating the sheets needs a lot of memory (approx 4 GB) but this is fine. But then when I try to SaveAs() I get an OutOfMemory exception when the process uses approx 9 GB of memory.

I believe the _problem_ is that the DOM approach is being used with the OpenXML SDK. Is there any chance this can be rewritten to use the streaming approach (i.e. using OpenXmlWriter)?

I don't have experience using the OpenXML SDK, but I would be willing to contribute if you can provide some pointers.

The simplest approach (least code impact which would seem to work in my particular situation) I considered was a two phase approach. First use the DOM approach to write an baseline file, then re-open the file using OpenXmlReader and write a replacement WorksheetPart using OpenXmlWriter basically copying what is there but creating a new SheetData in which the rows and their columns are streamed. But like I said I have no real experience is this area so this might be completely wrong.
Comments: I am having the same issue. I have users that have 5GB RAM on 32-bit machines and the large report files they are trying to export throw OutOfMemory exceptions. These files are only about 16MB but it completely chews up their memory during the SaveAs() function. Upgrading the machines to handle it at this point is not an option.

Created Unassigned: Unreadable content in Excel file after deleting sheets [9428]

$
0
0
I have a template .xlsx file which I open with ClosedXML, populate with necessary info, and depending on the user options, delete some irrelevant sheets (mostly the empty ones). Then I save the file, but when the user tries to open the file, Excel complains about unreadable content (a common error, I know).

My sheets contain NamedRanges and Tables, and there are also some pivot tables. I try to delete these all explicitly before deleting the actual sheet, but I think some reference somewhere still remains.

I attach a simplified version of the empty template file, some code that shows how I delete the sheets, and the resultant file that has the 'unreadable content'.

Please advise.

```
private void DeleteIrrelevantSheet(XLWorkbook wb)
{
new string[] {
"YieldCurvePivot",
"GeneratedYieldCurveEntries"
}.ForEach(s => DeleteSheetAndTable(wb, s));
}

private void DeleteSheetAndTable(XLWorkbook wb, string sheetName)
{
var sheet = wb.Worksheet(sheetName);

//Delete named ranges on workbook level pointing to sheet
string[] namedRangesToDelete = wb.NamedRanges.Where(nr => nr.RefersTo.Contains(sheetName)).Select(nr => nr.Name).ToArray();
foreach (var nr in namedRangesToDelete)
{
wb.NamedRanges.Delete(nr);
}

//Delete named ranges on sheet level pointing to sheet
foreach (var sheet2 in wb.Worksheets)
{
namedRangesToDelete = sheet2.NamedRanges.Where(nr => nr.RefersTo.Contains(sheetName)).Select(nr => nr.Name).ToArray();
foreach (var nr in namedRangesToDelete)
{
sheet2.NamedRanges.Delete(nr);
}
}

//Delete tables
var tablesToDelete = sheet.Tables.Select(t => t.Name).ToArray();
foreach (var table in tablesToDelete)
{
sheet.Tables.Remove(table);
}

//Delete pivot tables
sheet.PivotTables.DeleteAll();
sheet.Delete();
}

```

Edited Unassigned: Unreadable content in Excel file after deleting sheets [9428]

$
0
0
I have a template .xlsx file which I open with ClosedXML, populate with necessary info, and depending on the user options, delete some irrelevant sheets (mostly the empty ones). Then I save the file, but when the user tries to open the file, Excel complains about unreadable content (a common error, I know).

My sheets contain NamedRanges and Tables, and there are also some pivot tables. I try to delete these all explicitly before deleting the actual sheet, but I think some reference somewhere still remains.

I attach a simplified version of the empty template file, some code that shows how I delete the sheets, and the resultant file that has the 'unreadable content'.

Please advise.

``` C#
private void DeleteIrrelevantSheet(XLWorkbook wb)
{
new string[] {
"YieldCurvePivot",
"GeneratedYieldCurveEntries"
}.ForEach(s => DeleteSheetAndTable(wb, s));
}

private void DeleteSheetAndTable(XLWorkbook wb, string sheetName)
{
var sheet = wb.Worksheet(sheetName);

//Delete named ranges on workbook level pointing to sheet
string[] namedRangesToDelete = wb.NamedRanges.Where(nr => nr.RefersTo.Contains(sheetName)).Select(nr => nr.Name).ToArray();
foreach (var nr in namedRangesToDelete)
{
wb.NamedRanges.Delete(nr);
}

//Delete named ranges on sheet level pointing to sheet
foreach (var sheet2 in wb.Worksheets)
{
namedRangesToDelete = sheet2.NamedRanges.Where(nr => nr.RefersTo.Contains(sheetName)).Select(nr => nr.Name).ToArray();
foreach (var nr in namedRangesToDelete)
{
sheet2.NamedRanges.Delete(nr);
}
}

//Delete tables
var tablesToDelete = sheet.Tables.Select(t => t.Name).ToArray();
foreach (var table in tablesToDelete)
{
sheet.Tables.Remove(table);
}

//Delete pivot tables
sheet.PivotTables.DeleteAll();
sheet.Delete();
}

```

Edited Unassigned: Unreadable content in Excel file after deleting sheets [9428]

$
0
0
I have a template .xlsx file which I open with ClosedXML, populate with necessary info, and depending on the user options, delete some irrelevant sheets (mostly the empty ones). Then I save the file, but when the user tries to open the file, Excel complains about unreadable content (a common error, I know).

My sheets contain NamedRanges and Tables, and there are also some pivot tables. I try to delete these all explicitly before deleting the actual sheet, but I think some reference somewhere still remains.

I attach a simplified version of the empty template file, some code that shows how I delete the sheets, and the resultant file that has the 'unreadable content'.

We're on Excel 2010, Windows 7 32b, ClosedXML 0.76.0.0

Please advise.

``` C#
private void DeleteIrrelevantSheet(XLWorkbook wb)
{
new string[] {
"YieldCurvePivot",
"GeneratedYieldCurveEntries"
}.ForEach(s => DeleteSheetAndTable(wb, s));
}

private void DeleteSheetAndTable(XLWorkbook wb, string sheetName)
{
var sheet = wb.Worksheet(sheetName);

//Delete named ranges on workbook level pointing to sheet
string[] namedRangesToDelete = wb.NamedRanges.Where(nr => nr.RefersTo.Contains(sheetName)).Select(nr => nr.Name).ToArray();
foreach (var nr in namedRangesToDelete)
{
wb.NamedRanges.Delete(nr);
}

//Delete named ranges on sheet level pointing to sheet
foreach (var sheet2 in wb.Worksheets)
{
namedRangesToDelete = sheet2.NamedRanges.Where(nr => nr.RefersTo.Contains(sheetName)).Select(nr => nr.Name).ToArray();
foreach (var nr in namedRangesToDelete)
{
sheet2.NamedRanges.Delete(nr);
}
}

//Delete tables
var tablesToDelete = sheet.Tables.Select(t => t.Name).ToArray();
foreach (var table in tablesToDelete)
{
sheet.Tables.Remove(table);
}

//Delete pivot tables
sheet.PivotTables.DeleteAll();
sheet.Delete();
}

```

New Post: Inject macros

$
0
0
Hello !

I use your great library, and I need your help to finish the work.

I need to allow a table to be sorted in a protected sheet, and allow group functionnalities too. I read that it is not possible with closedXML but possible with macros. So, I need to know if it's possible to inject some VB code in an Excel file via closedXML.

Thank you for your help !
Viewing all 1877 articles
Browse latest View live


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