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

New Post: Export cells as list

$
0
0
Is it possible to create cells as list item?

New Post: Excel 2013 - 2010 compatibility

$
0
0
I had the same problem happening apparently only on not very updated Office 2010 Standard installations.

The (very dirty) workaround I found (deducing it from this useful post) is removing those extensions completely, as I didn't need them.

After saving the workbook with ClosedXML I used the OOXML library directly doing this (in both workbook.xml and styles.xml):
using (SpreadsheetDocument excelDoc = SpreadsheetDocument.Open(ms, true))
{
    if (excelDoc.WorkbookPart.Workbook.Descendants<WorkbookExtensionList>().Any())
    {
        excelDoc.WorkbookPart.Workbook.RemoveAllChildren<WorkbookExtensionList>();
        excelDoc.WorkbookPart.Workbook.Save();
    }

    if (excelDoc.WorkbookPart.WorkbookStylesPart.Stylesheet.Descendants<StylesheetExtensionList>().Any())
    {
        excelDoc.WorkbookPart.WorkbookStylesPart.Stylesheet.RemoveAllChildren<StylesheetExtensionList>();
        excelDoc.WorkbookPart.WorkbookStylesPart.Stylesheet.Save();
    }
}
As a note, it appears that fully updated Office 2010 Professional installation do not corrupt the files after saving, in my experience only Office 2010 Standard did this.

I hope this can be useful.

Commented Issue: "Unreadable content" when editing and reopening generated file in Excel 2010 [8466]

$
0
0
The problem is described in the discussions in the following thread: http://closedxml.codeplex.com/discussions/403797
When I open an existing Excel file using ClosedXml and save it (even without performing any actions), the file gets corrupted when it is edited using Excel 2010 afterwards. Excel 2007 and Excel 2013 do not produce the problem on my Systems (tested with WinXP and Win8).
I've attached the following small sample program:

```
namespace ClosedXml_Template_Test
{
using System.IO;
using ClosedXML.Excel;
class Program
{
static void Main(string[] args)
{
string inFilepath = "Template.xlsx";
string outFilepath = "Generated.xlsx";
byte[] fileContent;
using (FileStream fileStream = File.OpenRead(inFilepath))
{
// Read from file
fileContent = new byte[fileStream.Length];
fileStream.Read(fileContent, 0, fileContent.Length);
}
using (MemoryStream memStream = new MemoryStream())
{
// Write to MemoryStream
memStream.Write(fileContent, 0, fileContent.Length);
// Create ClosedXml instances
using (XLWorkbook workbook = new XLWorkbook(memStream, XLEventTracking.Disabled))
{
// Save the workbook to the stream
workbook.Save();
}
// Get the content from the stream
fileContent = memStream.ToArray();
}
if (File.Exists(outFilepath))
{
// Delete existing generated file
File.Delete(outFilepath);
}
using (FileStream fileStream = File.OpenWrite(outFilepath))
{
// Save the new file
fileStream.Write(fileContent, 0, fileContent.Length);
}
}
}
}
```

EDIT: Reformatted the post (CodePlex somehow killed the layout...)
Comments: I just posted an update in the discussion at https://closedxml.codeplex.com/discussions/403797 that might help in some cases (expecially when the corruption comes from the <x:ext /> tags in workbook.xml or styles.xml)

Created Unassigned: Is there a way to create Excel relationships using ClosedXML? I tried to do it using a Dataset but it was not implemented in the Excel File. [9458]

$
0
0
Is there a way to create Excel relationships using ClosedXML? I tried to do it using a Dataset but it was not implemented in the Excel File.
```
using (XLWorkbook wb = new XLWorkbook())
{
var ds = exportableEntity.GetDataSet();
wb.Worksheets.Add(ds);


wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;

using (var memoryStream = new MemoryStream())
{
wb.SaveAs(memoryStream);
//Export file
}
}
```

New Comment on "Data Validation"

$
0
0
How can you add a list (dropdown) using a comma-separated string? I'd rather not have to use a range of cells from an existing worksheet. I tried: cell.Value = "Awesome"; var list = new List<string> {"Could be better", "Average", "Awesome"}; cell.DataValidation.List(string.Join(",", list.ToArray()), true); Excel tries to repair the document and I get the following exception message: "Removed Feature: Data validation from /xl/worksheets/sheet.xml part" Thanks, Cameron

New Post: Pull Request Integration?

$
0
0
Hi, in th meantime a couple of PullRequest are waiting to be included in the main branch.
Could someone of the developers do the integration? Thx

Commented Unassigned: Can not create more than 1 Pivot Table in WorkBook. [9397]

$
0
0
I can easily create two Worksheets, and I can easily add a Pivot Table to one of the worksheets. But if you try to add a second Pivot Table to the second Worksheet, you end up with a corrupted excel document.

Below is the method I am calling. It works great once, but not twice.

When I call this method, wsPivot is a new worksheet. I have tried using a different dataRange, or the same dataRange, but either way fails. The new worksheets are there, and work without issue if I don't add a pivot table to them.

I will try to dive into the XML to find the problem, but that is as we all know challenging. Hope somebody has a work around, I really need this fix to continue using this library. Thanks.

private static void CreatePivotTable(IXLRange dataRange, IXLWorksheet wsPivot, string pivotTableName)
{
var pt = wsPivot.CreatePivotTable(wsPivot.Cell(3, 1), pivotTableName);
pt.SourceRange = dataRange;

// OR
// var pt = wsPivot.PivotTables.AddNew(pivotTableName, wsPivot.Cell(3, 1), dataRange);

pt.RowLabels.Add("UnitNames");
pt.Values.Add("TotalPrice").SetSummaryFormula(XLPivotSummary.Sum);
}
Comments: @jahndohse, Using latest Closedxml (0.76.0) with Net 4.5.1 and getting the same issue. I have also tried multiple combinations (i.e. data on same sheet as the pivot). Unzipped the Excel archive and made adjustments to rels that I thought might be wrong. Couldn't fix it. Wondered if anybody has gotten around this issue?

Created Unassigned: How to Create a Workbook from Excel template (.xltx) [9459]

$
0
0
Hello,

I am getting an exception saying that "Extension .xltx is not supported" when trying to create an XLWorkbook by passing it an .xltx file. However, I see here in the discussions that people say you can open a .xltx file. Am I doing something wrong and is there a different way to open a template? Thank you.

Edited Unassigned: How to Create an XLWorkbook from Excel template (.xltx) [9459]

$
0
0
Hello,

I am getting an exception saying that "Extension .xltx is not supported" when trying to create an XLWorkbook by passing it an .xltx file. However, I see here in the discussions that people say you can open a .xltx file. Am I doing something wrong and is there a different way to open a template? Thank you.

New Post: Maintaining Defaul Sort Order

$
0
0
Hello,

I have an Excel Workbook. When I open the workbook using new XLWorkbook(memoryStream) constructor. My workbook sort order has changed. How can I prevent any sorting from occurring when opening an Excel Workbook

New Post: Unable to Create XLWorkbook from Excel Template (.xltx)

$
0
0
Hello,

I am getting an exception saying that "Extension .xltx is not supported" when trying to create an XLWorkbook by passing it an .xltx file. However, I see here in the discussions that people say you can open a .xltx file. Am I doing something wrong and is there a different way to open a template?

New Comment on "Copying Worksheets"

$
0
0
Hi, We are facing problems as images are getting missed as part of the copy. Is there a way to copy the embedded images also?

Created Unassigned: Use of AddConditionalFormat > Unreadable XLS [9460]

$
0
0
Hi,

I'm opening/modifying/saving an existing Excel 2010 file. When I don't use conditional formatting > no pb to read it with MS Excel 2010 once I made the modifications. When I use conditional formatting (for instance with the following code :

xlWorksheet.Range( 4, 8, 4 + (dateTimeCount - 1), 8).AddConditionalFormat().ColorScale().Minimum(XLCFContentType.Percentile, 5.0, XLColor.LightCarminePink).Midpoint(XLCFContentType.Number, 0.0, XLColor.White).Maximum(XLCFContentType.Percentile, 95.0, XLColor.LightGreen );

The C# code executes without notice but the resulting XLS file can't be opened with MS Excel 2010 anymore. What's quite strange is that I use C# code which worked last year with an older version of ClosedXML (don't ask me which one, I lost the info) but which doesn't work anymore with the latest one (0.76.0).

Any help is welcome.

Eric

Reviewed: ClosedXML 0.76.0 (Sep 20, 2015)

$
0
0
Rated 5 Stars (out of 5) - I spent a lot of time looking for easy fast library and I finally found what I need, thank you

Reviewed: ClosedXML 0.76.0 (Sep 22, 2015)

$
0
0
Rated 5 Stars (out of 5) - After searching and searching I FINALLY came across this amazing library, well worth the wait!

New Comment on "Basic Table"

New Post: How to remove a page break

$
0
0
I can see how to add them, but how can I delete them?

Commented Unassigned: Export empty DataTable ignores DataColumn Caption [9423]

$
0
0
In the current implementation, when exporting a DataTable to excel via InsertTable method, if a DataColumn.Caption is not null or whitespace then the DataColumn.Caption string is taken into account for Excel's column names instead of DataColumn.ColumnName.

However, if the exported DataTable has no rows, the DataColumnCaption field is not taken into account and DataColumn.ColumnName is used.

I believe it would be nice to have the same behaviour for column names for both cases.

Steps to reproduce:

1. Create a DataTable with no rows but with some DataColumns.
2. Fill the DataColumn.Caption field with some non-whitespace string
3. Export the DataTable with worksheet.Cell("A1").InsertTable(dataTable);

Comments: Pull request with fix https://closedxml.codeplex.com/SourceControl/network/forks/vittoso/EmptyDatatableCaption/contribution/8497

New Post: Problem with InDesing

$
0
0
Hi. I am Alejandro González from spain.

I have a problem with an excel file that i created with ClosedXML and when i try to import in InDesing occurs a error message:

"Cannot place this file. No filter found for requested operation."

If I open the excel file, excel make some changes automatic and when i try to exit from excel ask me if i lose my changes. If save my changes, then the excel file is ok from import in InDesing.

Can someone help me out?

Thanks and sorry for my bad english. ;)

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: Did you also experience any slowdowns during save operations? I noticed that when I create large documents (4 sheets with 44 columns and, respectively, 60K rows, 180K, 5K, and 17K, the resulting XLSX file is about 50MB), calling SaveAs requires a very long time, about 30 minutes. Does it probably depend on the same reason?
Viewing all 1877 articles
Browse latest View live


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