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

New Post: Formula issue after worksheet copy

$
0
0
(1) The file that defines where the excel files get created is CreateFiles.cs in the Creating directory of the ClosedXML_Examples project.
(2) I have created Excel files with over 100,000 rows no problem.
(3) You have to give a valid file name for the SaveAs. @"C:\" is not a file name. Try using @"C:\Filename.xlsx" Also if you are running this via a web application, the server will not access directory like C:\ which is outside of the application location. Try using relative address @".\Filename.xlsx"

Commented Unassigned: Using IF formula with cell referenced produces invalid Excel 2010 document [9143]

$
0
0
This code will produce the file which would be impossible to open in Excel 2010 x32 (Russian) properly:

```
using (var workbook = new XLWorkbook ())
{
var worksheet = workbook.Worksheets.Add ("Report");

worksheet.Cell (1, 1).Value = 1;
worksheet.Cell (1, 2).FormulaR1C1 = "=IF(A1>0;1;0)";

workbook.SaveAs (@"c:\temp\test.xlsx");
}
```
Comments: ** Comment from web user: roberttanenbaum **

Try "IF(A1>0,1,0)"
Using commas instead of semicolons.

Commented Unassigned: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0 [9142]

$
0
0
i am getting the following error, can someone guide me what i am missing
Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.":"DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Comments: ** Comment from web user: roberttanenbaum **

Go to the first page of the documentation and download the DocumentFormat.OpenXml.dll that is there and add it to your project assembly.

Requirements:

To use ClosedXML you must reference the following DLL: DocumentFormat.OpenXml.dll (part of MS Open XML SDK 2.0)

Note that if your are deploying this to a server, make sure you deploy the .dll along with your application.

Commented Unassigned: Using IF formula with cell referenced produces invalid Excel 2010 document [9143]

$
0
0
This code will produce the file which would be impossible to open in Excel 2010 x32 (Russian) properly:

```
using (var workbook = new XLWorkbook ())
{
var worksheet = workbook.Worksheets.Add ("Report");

worksheet.Cell (1, 1).Value = 1;
worksheet.Cell (1, 2).FormulaR1C1 = "=IF(A1>0;1;0)";

workbook.SaveAs (@"c:\temp\test.xlsx");
}
```
Comments: ** Comment from web user: FuriCuri **

Thanks, thats working fine. Guess thats difference in language representation of formulas.

Commented Unassigned: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0 [9142]

$
0
0
i am getting the following error, can someone guide me what i am missing
Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.":"DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Comments: ** Comment from web user: robvon **

There is a newer version of the OpenXml - V2.5.

ClosedXml appears not to have been compiled against this release.

It may be that you have 2.5 installed. It may also be possible to download the source and compile against this version. I'm about to try that.

Created Unassigned: Compiling ClosedXML with OpenXml V2.5 and .Net 4+ [9145]

$
0
0
OpenXml V2.5 has deprecated SmartTags and also can't be used with with .Net 3.5 builds due some internal dependencies on .Net.4.0.

You can recompile the source to ClosedXml with a reference to the OpenXml SDK V2.5 if you don't need to target .Net 3.5 and if you comment out the line that refers to the SmartTag class


For more info on the SmartTag issue, Google to:

"What's new in the Open XML SDK 2.5 for Office - MSDN - Microsoft"

I'm at the point of testing now so there may be a few other things but even Resharper was happy so it can't be too bad.

New Post: How to get the name of the current workbook / worksheet

$
0
0
From within Excel, with a worksheet already displayed, how does one get the current XLWorkbook instance?

I don't want to open it with new XLWorkbook as it is already open. I would expect a static method along the lines of "XLWorkbook.Current()" but I can't find such a thing.

Regards

Rob

Created Unassigned: conditional formatting and inserting rows [9146]

$
0
0
Hello!

I am having a problem with conditional formatting and inserting rows.

I use a sheet with a conditional formatting in row 7 (see Before.png). I use sheetSource.Row(7).InsertRowsBelow(37); to insert rows.

The used formatting should be extended to the new rows. But ClosedXML added a new rule for the new rows. But the formula is wrong (see After.png).

Commented Unassigned: conditional formatting and inserting rows [9146]

$
0
0
Hello!

I am having a problem with conditional formatting and inserting rows.

I use a sheet with a conditional formatting in row 7 (see Before.png). I use sheetSource.Row(7).InsertRowsBelow(37); to insert rows.

The used formatting should be extended to the new rows. But ClosedXML added a new rule for the new rows. But the formula is wrong (see After.png).
Comments: ** Comment from web user: RainerKoch **

Sorry, the second file...

New Post: How to get the name of the current workbook / worksheet

$
0
0
XLWorkbook wb = new XLWorkbook(fileLocation);  // open an existing workbook
XLWorksheet ws = wb.Worksheet(1);   // get first worksheet contained by this workbook
XLWorkbook sameWb = ws.Workbook;   // get reference to the workbook that contains this worksheet

Created Unassigned: Out of memory exception [9150]

$
0
0
Hello guys,

I´m working with large amount of data in Excel.
What I need to do is read the data, and put it into a generic list, with some business rules.
In this process, I have the total count of 1 200 000 objects inside the list.
Often it causes an memory exception due the large amount of data, rarely the process doesn´t throw an exception.
I´ve already read the support documentation and have already used the tips for better performance, but it doesn´t works to me.
Could someone help me in this case, please?

Thanks in advance,

Thiago

Patch Uploaded: #15531

$
0
0

das974 has uploaded a patch.

Description:
ClosedXml cannot handle formulas that refer to text values for date and numeric calculations.

Steps
1) Create new Workbook,
2) In A1, type '11/20/2013 6:00 - (make sure to include the apostrophe)
3) In B1, type '11/20/2013 9:00 - (make sure to include the apostrophe)
4) In C1, type the enter the formula =B1-A1
5) In A2 type '1
6) In B2 type '5
7) in C2 type B1-A1
8) Save and use the ClosedXml library to get the value of C1 and C2
Expected:
Value of C1 is .0125 - matches value in Excel and cached value
Value of C2 is 4 - matched value in Excel and cached value
Actual:
Value of C1 is 0
Value of C2 is 0

Excel is able to convert text to dates or numbers in formulas if appropriate and so should the ClosedXml library to keep the behaviors consistent. I believe that the Expression logic should be improved to handle these scenarios similar to how the Excel client application handles it - by attempting to parse the strings and give the best answer possible without modifying the underlying datatype.

In the ClosedXML.Excel.CalcEngine.Expression type, the operator override for double should be expanded as shown below, but I think that the parsing logic should be more elaborate to handle multiple cultures. The following change is sufficient to handle most US scenarios and is an improvement over what is already available.

//Handle values that formatted as strings and try to parse them.
if (v is string)
{
DateTime date;
if (DateTime.TryParse(v as string, out date))
return date.ToOADate();

double doubleVal;
if (Double.TryParse(v as string, out doubleVal))
return (doubleVal);
}

Commented Unassigned: Out of memory exception [9150]

$
0
0
Hello guys,

I´m working with large amount of data in Excel.
What I need to do is read the data, and put it into a generic list, with some business rules.
In this process, I have the total count of 1 200 000 objects inside the list.
Often it causes an memory exception due the large amount of data, rarely the process doesn´t throw an exception.
I´ve already read the support documentation and have already used the tips for better performance, but it doesn´t works to me.
Could someone help me in this case, please?

Thanks in advance,

Thiago
Comments: ** Comment from web user: roberttanenbaum **

Here's the obvious problem. Over a million items are being kept in memory twice. Once in the Excel file and then again in the in-memory list.

At what point does it run out of memory?
How many items are added to the in-memory generic list before it runs out of memory?

Are you running on a 64-bit machine with 8 GB memory or on a 32-bit machine with 4 GB memory?
Maybe you can move to a 64-bit machine.
What is the cache memory size on the server?
Maybe you can increase the size of the cache.

If those things fail, you might have to implement your own memory management.
Pick a number like 100,000 and when you have that many items in your generic list, write them out to disk and close the file and reset the list to zero and read the next 100,000 items until it is all written out to disk.
Dispose of the workbook and force a garbage collection. Then close the Excel file and read back the items from disk.

Let us know what you do to solve this issue.

Commented Unassigned: Out of memory exception [9150]

$
0
0
Hello guys,

I´m working with large amount of data in Excel.
What I need to do is read the data, and put it into a generic list, with some business rules.
In this process, I have the total count of 1 200 000 objects inside the list.
Often it causes an memory exception due the large amount of data, rarely the process doesn´t throw an exception.
I´ve already read the support documentation and have already used the tips for better performance, but it doesn´t works to me.
Could someone help me in this case, please?

Thanks in advance,

Thiago
Comments: ** Comment from web user: ThiagoGrandesso **

About the amount of objects inside the list when it throws a memory exception, is around 100 000.

The machine is 64 bit and has 4 GB memory.

I suppose the idea about implement my own memory management is the best approach. Due the great DLL offered by you, I wouldn´t have to change a lot of code.

I have found some articles from the SAX approach using Open XML SDK. It doesn´t load the entire file into memory. Is there any approach like this in ClosedXML? It´s the best scenario I could have in performance terms.

Here are the articles:
http://msdn.microsoft.com/en-us/library/office/gg575571.aspx
http://msdn.microsoft.com/en-us/library/hh180830(v=office.14).aspx

Thank you,

Thiago

New Post: Assembly in SQL2012

$
0
0
I had closedXml installed in SQL2008.
Now, we moved to SQL2012 which has support for NET 4.0.
I wanted to install closedXML there, but I can't install windowsBase.dll

This is from Microsoft:
" In .NET Framework 4.0, the “WindowsBase.dll” includes not only “System.IO.Packaging” but also a lot of other libraries that are UI related. As SQL Server is supposed to run as a service on a server platform, which is not desktop interactive, loading libraries like “System.Drawings” ,which is desktop interactive, could cause potential problems (eg. leaving security holes or leaking orphaned Windows handles). As the DLL runs within the SQL Server process, all these problems will directly affect the health of the whole database system."

Is it possible to build closedXML without this references, some light version?
Or is there any other solution?

br, Simon

Commented Issue: Saving workbook creates extra NumFmt elements [8369]

$
0
0
It appears that each time a workbook is saved a empty NumFmt (NumberingFormat) element is appended in the stylesheet. Once this is done enough times, it will start stepping on the built-in formats. I was noticing this with the percent format which I belive is #10.

The excel file attached has one cell, formatted as a percentage. After 9 saves, the formatting is lost.
In my practical application the stream was being passed around and many classes were opening a workbook from the stream and saving back to the stream.

This was the latest version, 77207



byte[] calculatedExcelStreamBytes = File.ReadAllBytes("c:\\LoseFormatTest.xlsx");

using (MemoryStream calculatedExcelStream = new MemoryStream())
{
calculatedExcelStream.Write(calculatedExcelStreamBytes, 0, calculatedExcelStreamBytes.Length);
XLWorkbook b = new XLWorkbook(calculatedExcelStream);

b.Save(); // Each save will increase the number of formats written, looking to step on built-in formats
b.Save();
b.Save();
b.Save();
b.Save();
b.Save();
b.Save();
b.Save();
b.Save(); // At this point we are stepping on the percent format
b.Save();
b.Save();
b.Save();
b.Save();

using (FileStream fs = new FileStream("C:\\LoseFormatTest.Modify.xlsx", FileMode.Create, FileAccess.Write))
{
calculatedExcelStream.WriteTo(fs);
fs.Flush();
fs.Close();
}
}
Comments: ** Comment from web user: FeelingPhoggy **

I am having the same issue, as far as I can tell.

I have a workbook with multiple worksheets. When make changes to 1 worksheet and then save the workbook, date formatting on a completely different worksheet than I edited is lost and the dates do not appear as they did before the .Save() operation.

Any help or tips for workarounds would be great.

Commented Issue: Saving workbook creates extra NumFmt elements [8369]

$
0
0
It appears that each time a workbook is saved a empty NumFmt (NumberingFormat) element is appended in the stylesheet. Once this is done enough times, it will start stepping on the built-in formats. I was noticing this with the percent format which I belive is #10.

The excel file attached has one cell, formatted as a percentage. After 9 saves, the formatting is lost.
In my practical application the stream was being passed around and many classes were opening a workbook from the stream and saving back to the stream.

This was the latest version, 77207



byte[] calculatedExcelStreamBytes = File.ReadAllBytes("c:\\LoseFormatTest.xlsx");

using (MemoryStream calculatedExcelStream = new MemoryStream())
{
calculatedExcelStream.Write(calculatedExcelStreamBytes, 0, calculatedExcelStreamBytes.Length);
XLWorkbook b = new XLWorkbook(calculatedExcelStream);

b.Save(); // Each save will increase the number of formats written, looking to step on built-in formats
b.Save();
b.Save();
b.Save();
b.Save();
b.Save();
b.Save();
b.Save();
b.Save(); // At this point we are stepping on the percent format
b.Save();
b.Save();
b.Save();
b.Save();

using (FileStream fs = new FileStream("C:\\LoseFormatTest.Modify.xlsx", FileMode.Create, FileAccess.Write))
{
calculatedExcelStream.WriteTo(fs);
fs.Flush();
fs.Close();
}
}
Comments: ** Comment from web user: FeelingPhoggy **

I have put together a relatively simple application that illustrates this issue. Attached is the full project and the original Excel workbook and the resulting workbook.

Essentially, what this mimics is a way that I was looking to use an Excel workbook as a simple data repository for a process that needs to be run monthly. The "MonthlyTotals" worksheet keeps the number of records and the total dollar amount of those records for up to 6 months. Once the worksheet has 6 months of data and new data is to be added, the 3rd column (oldest month) is dropped and the other 5 columns moved over to the left with the new month put in the 8th column.

As ISOLDOUT found previously, it works just fine the first few times that it is ran, but once the workbook is saved many times, the formatting gets completely out of whack. In fact, after just saving the workbook 5 times, the dates on the "HeaderPage" worksheet are not formatted like they were in the original.

New Comment on "ClosedXML Predefined Colors"

$
0
0
No se ve la representación de cada color, todas las celdas salen blancas...

Commented Unassigned: Reading a large excel file, part by part using range still throws MemoryException [9100]

$
0
0
Hi,

I have an excel file with 1 lakh rows and 250 columns. I want to read 25k rows at a time using range.
But, the XLWorkbook throws an OutOfMemoryException in the line where it opens the workbook, even before it tries to read the range.

var workBook= new XLWorkbook("Book1Lakh.xlsx");

Is there any workaround to solve my problem, preferably could you provide me with a sample code?
Comments: ** Comment from web user: ThiagoGrandesso **

I´m facing this problem too.
When I use this line of code to open the excel file it throws an exception.
Have you found the problem´s cause? Please, let us know if you solve this issue.

XLWorkbook wb = new XLWorkbook(fileName);

Could you help please?

Patch Uploaded: #15554

$
0
0

Fabian84 has uploaded a patch.

Description:
Hello,
I have identified and fixed a bug regarding Conditional Formats.
Existing conditional formats styles are disordered by the ClosedXML library by just opening and saving a xlsx document.

Regards,
Fabian

Viewing all 1877 articles
Browse latest View live


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