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

New Post: The closedxml load file slowly

$
0
0
I try to do a test and compare the time of load file.
I found the closedXml is the slowest between OpenXML and NPOI.

Just testing load the file and nothing to do.

OpenXML 103 ms
ClosedXML 2790ms
NPOI 1097ms

It's bad when do with lot of files. ╮(╯_╰)╭

Created Unassigned: System.Exception: Syntax error [9393]

$
0
0
Hi,

I am using excel sheet to calculate values from user provided inputs and i am getting error on the cell containing following formula

```
IF(C2=1,VLOOKUP(D7,A15:D28,4),(IF(C2=2,VLOOKUP(D7,A33:D46,4),VLOOKUP(D7,F15:I28,4))))
```

On line:

```
lblResult.Text = worksheet.Cell("D8").Value;
```

Attached file is template excel file i am using to calculate results

Please help

Thanks in advance

Edited Unassigned: System.Exception: Syntax error [9393]

$
0
0
Hi,

I am using excel sheet to calculate values from user provided inputs and i am getting error on the cell containing following formula

```
IF(C2=1,VLOOKUP(D7,A15:D28,4),(IF(C2=2,VLOOKUP(D7,A33:D46,4),VLOOKUP(D7,F15:I28,4))))
```

On line:

```
lblResult.Text = worksheet.Cell("D8").Value;
```

Attached file is template excel file i am using to calculate results

Please help

Thanks in advance

Following is the stack trace

```
Stack Trace:


[Exception: Syntax error.]
ClosedXML.Excel.CalcEngine.CalcEngine.GetParameters() +223
ClosedXML.Excel.CalcEngine.CalcEngine.ParseAtom() +141
ClosedXML.Excel.CalcEngine.CalcEngine.ParseUnary() +77
ClosedXML.Excel.CalcEngine.CalcEngine.ParsePower() +16
ClosedXML.Excel.CalcEngine.CalcEngine.ParseMulDiv() +16
ClosedXML.Excel.CalcEngine.CalcEngine.ParseAddSub() +16
ClosedXML.Excel.CalcEngine.CalcEngine.ParseCompare() +16
ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression) +67
ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression) +140
ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression) +27
ClosedXML.Excel.XLCell.get_Value() +411
TestExcel.btnResult_Click(Object sender, EventArgs e) in f:\Projects\Generation Circuit\gencricuit\GenerationCircuit\TestExcel.aspx.cs:30
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628026
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
```

Closed Unassigned: System.Exception: Syntax error [9393]

$
0
0
Hi,

I am using excel sheet to calculate values from user provided inputs and i am getting error on the cell containing following formula

```
IF(C2=1,VLOOKUP(D7,A15:D28,4),(IF(C2=2,VLOOKUP(D7,A33:D46,4),VLOOKUP(D7,F15:I28,4))))
```

On line:

```
lblResult.Text = worksheet.Cell("D8").Value;
```

Attached file is template excel file i am using to calculate results

Please help

Thanks in advance

Following is the stack trace

```
Stack Trace:


[Exception: Syntax error.]
ClosedXML.Excel.CalcEngine.CalcEngine.GetParameters() +223
ClosedXML.Excel.CalcEngine.CalcEngine.ParseAtom() +141
ClosedXML.Excel.CalcEngine.CalcEngine.ParseUnary() +77
ClosedXML.Excel.CalcEngine.CalcEngine.ParsePower() +16
ClosedXML.Excel.CalcEngine.CalcEngine.ParseMulDiv() +16
ClosedXML.Excel.CalcEngine.CalcEngine.ParseAddSub() +16
ClosedXML.Excel.CalcEngine.CalcEngine.ParseCompare() +16
ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression) +67
ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression) +140
ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression) +27
ClosedXML.Excel.XLCell.get_Value() +411
TestExcel.btnResult_Click(Object sender, EventArgs e) in f:\Projects\Generation Circuit\gencricuit\GenerationCircuit\TestExcel.aspx.cs:30
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628026
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
```
Comments: VLOOKUP is not supported. You can't resolve a formula that uses VLOOKUP.

New Post: The closedxml load file slowly

$
0
0
How many cells?

If performance is paramount then you should use SAX.

New Post: The closedxml load file slowly

$
0
0
Ok,Thanks.

The cells count about 6000+ and size is about 500kb.
Hope the closedxml will be better. :-D

New Post: Merging cells makes hidden value

$
0
0
Hello
IXLRange.Merge() makes hidden value.

e.g.
// Merge and save
XLWorkbook workBook = new XLWorkbook(textBox1.Text);
IXLWorksheet sheet = workBook.Worksheet(1);

sheet.Cell("A1").Value = "A1Value";
sheet.Cell("A2").Value = "A2Value";
sheet.Cell("A1").Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
sheet.Cell("A2").Style.Border.OutsideBorder = XLBorderStyleValues.Thin;

sheet.Range("A1:A2").Merge();

workBook.Save();

...

// Refer merged cell
XLWorkbook workBook = new XLWorkbook(textBox1.Text);
IXLWorksheet sheet = workBook.Worksheet(1);

Debug.Assert(sheet.Range("A1:A2").IsMerged());

IXLCell a2cell = sheet.Cell("A2");

XLBorderStyleValues a2TopBorder = a2cell.Style.Border.TopBorder; // <- Thin (not None)
string a2value = a2cell.Value.ToString();                          // <- "A2Value" (not "")
Do I have to add code to clear hidden value?
ClosedXML version is 0.75.0.

Thanks.

New Post: Get value error

$
0
0
I found when you set the cell style is Percent then closedXml can't get the value.

e.g. To input the value like 12 in to the cell A1 and then display 12%

I try get the value in A1 like this.
 ClosedXML.Excel.XLWorkbook wb = new ClosedXML.Excel.XLWorkbook(new FileStream(@"New Microsoft Excel Test.xlsx", FileMode.OpenOrCreate));
            var testCell = wb.Worksheet("Sheet1").Cell("A1");
Then I try to get the testCell value it will throw the format exception and the valuecached is null.


Is an issue? Thanks.

New Post: Get value error

$
0
0
And when i got the last update code and modify the XLCell.cs to get value from InnerText, it's ok.

I'm not sure which way is better.

Created Unassigned: Conditional Formatting not applying to Pivot Table [9394]

$
0
0
I'm creating a pivot table in ClosedXML, then trying to apply conditional formatting to it. When I open the sheet however, the conditional format applies to everywhere but the pivot table; see attached.

My code for setting up the pivot table, and applying a conditional format are as follows:

```
var pWorksheet = workbook.Worksheets.Add(_service.ResolveWorksheetTabName("ptable"));
var pt = pWorksheet.PivotTables.AddNew("PivotTEST", pWorksheet.Cell(2, 1), table);
pt.RowLabels.Add("SurveySectionElementTypeCode");
pt.ColumnLabels.Add("SurveySectionName");
pt.Values.Add(section.FieldName);
pt.SetShowGrandTotalsRows(false);
pt.SetShowGrandTotalsColumns(false);

pWorksheet.Row(3).Style.Alignment.TextRotation = 90;
pWorksheet.Row(2).Hide();
pt.SetPreserveCellFormatting(true);


pWorksheet.Range(1, 1, worksheet.LastRowUsed().RowNumber(), worksheet.LastColumnUsed().ColumnNumber())
.AddConditionalFormat().WhenEquals(1)
.Fill.SetBackgroundColor(XLColor.FromHtml(section.ConditionParameters["Priority-1"]));


```

The pivot table itself works fine, any idea why the conditional format isn't getting applied? (The text rotation of the header isn't working either).

Cheers

New Post: IndexOutOfBounds - new XLWorkbook( ... )

$
0
0
Hi folks,
I have an error with one of our Excel-Documents. When I call:
wb = new XLWorkbook( path );
I get an IndexOutOfBounds-Exception.

The problem occurs when there is a ',' (comma) in the sheetname. My sheetname for example is EA-Plan, (1.0). I don't know why someone has entered a comma in the sheetname, but it happend.


The exception is thrown in the XLWorkbook_Load.cs file. Line 702, Method: LoadDefinedNames(Workbook workbook).
Image

There is a foreach-loop with a String.Split for comma. This cuts my sheetname in two pieces. So just one piece is send to ParseReference(area, out sheetName, out sheetArea)-Method
        private static void ParseReference(string item, 
                out string sheetName, out string sheetArea)
        {
            var sections = item.Trim().Split('!');
            sheetName = sections[0].Replace("\'", "");
            sheetArea = sections[1];  
        }
The problem is that there is no Index 1 in the sections, since the sheetname was cut in to pieces before.
My question is, why do I have to parse for a comma in the sheetname?
Has this to do with a different culture ?


Kindly Regards,
Peter

New Post: Cell.Value throwing System.FormatException

$
0
0
I have the same error in the Excel file.
If I copy paste the formula in the excel file = value is correct.
        DataTable tbl_rez = new DataTable();
        tbl_rez.Columns.Add("V", typeof(int));
        for (int i = 1; i < 18; i++)
        {
            DataRow r1 = tbl_rez.NewRow();
            r1[0]=i;
            tbl_rez.Rows.Add(r1);
        }
        var workbook2 = new XLWorkbook();
        var worksheet2 = workbook2.Worksheets.Add("List1");
        worksheet2.PageSetup.PageOrientation = XLPageOrientation.Landscape;

        worksheet2.Cell(1, 1).InsertTable(tbl_rez.AsEnumerable());

        workbook2.CalculateMode = XLCalculateMode.Auto;
        workbook2.ReferenceStyle = XLReferenceStyle.R1C1;


        var cellWithFormulaR1C1 = worksheet2.Cell(1 + tbl_rez.Rows.Count, 1);
        // In Russia
        cellWithFormulaR1C1.FormulaR1C1 = "=СУММ(R[-" +( tbl_rez.Rows.Count-1).ToString() + "]C:R[-1]C)";
        // In English
        //cellWithFormulaR1C1.FormulaR1C1 = "=SUM(R[-" + (tbl_rez.Rows.Count - 1).ToString() + "]C:R[-1]C)";

New Post: Conditional Formatting not applying to Pivot Table

$
0
0
I'm creating a pivot table in ClosedXML, then trying to apply conditional formatting to it. When I open the sheet however, the conditional format applies to everywhere but the pivot table; see attached.

My code for setting up the pivot table, and applying a conditional format are as follows:
var pWorksheet = workbook.Worksheets.Add(_service.ResolveWorksheetTabName("ptable"));
var pt = pWorksheet.PivotTables.AddNew("PivotTEST", pWorksheet.Cell(2, 1), table);
pt.RowLabels.Add("SurveySectionElementTypeCode");
pt.ColumnLabels.Add("SurveySectionName");
pt.Values.Add(section.FieldName);
pt.SetShowGrandTotalsRows(false);
pt.SetShowGrandTotalsColumns(false);
            
pWorksheet.Row(3).Style.Alignment.TextRotation = 90;
pWorksheet.Row(2).Hide();
 pt.SetPreserveCellFormatting(true);


pWorksheet.Range(1, 1, worksheet.LastRowUsed().RowNumber(),  worksheet.LastColumnUsed().ColumnNumber())
    .AddConditionalFormat().WhenEquals(1)
    .Fill.SetBackgroundColor(XLColor.FromHtml(section.ConditionParameters["Priority-1"]));
The pivot table itself works fine, any idea why the conditional format isn't getting applied? (The text rotation of the header isn't working either).

Cheers

Created Unassigned: Excessive memory usage, bug? [9395]

$
0
0
Hi

We are using ClosedXML to generate reports with multiple millions of rows and our memory usage just goes through the roof.

As a rule of thumb ClosedXML needs around 100 times the memory a generated .xslx has in size.

Am I doing something wrong? Is there a way to reduce the memory usage besides disabling event tracking?
The whole thing is just straight forward filling of cells, one row at the time. No inserting, moving, styling etc

I can replicate this on a little console application.
```
private static void CreateWorkbook()
{
Random rnd = new Random();
using (XLWorkbook workbook = new ClosedXML.Excel.XLWorkbook())
{
using (var sheet = workbook.AddWorksheet("Result"))
{
for (int rowNumber = 1; rowNumber < RowNumbers; rowNumber++)
{
using (var row = sheet.Row(rowNumber))
{
for (int columnNumber = 1; columnNumber < 300; columnNumber++)
{
row.Cell(columnNumber).Value = rnd.Next();
}
}
if (rowNumber % Percentage == 0)
Console.Write("\r{0}%", rowNumber / Percentage);
}

using (var table = sheet.RangeUsed().CreateTable())
{
table.Theme = XLTableTheme.TableStyleLight2;
}

Console.Write("\r100%");
string savePath = Path.Combine(@"C:\temp\closedxml\", string.Format("{0}-report.xlsx", DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss")));
workbook.SaveAs(savePath);
}
}
}
```
This generates a file of about 26MB for which around 2.6GB of memory is needed.

Thanks for any feedback, hints & tips.

St

Edited Unassigned: Excessive memory usage, bug? [9395]

$
0
0
Hi

We are using ClosedXML to generate reports with multiple millions of rows and our memory usage just goes through the roof.

As a rule of thumb ClosedXML needs around 100 times the memory a generated .xslx has in size.

Am I doing something wrong? Is there a way to reduce the memory usage besides disabling event tracking?
The whole thing is just straight forward filling of cells, one row at the time. No inserting, moving, styling etc

I can replicate this on a little console application.
```
private static void CreateWorkbook()
{
Random rnd = new Random();
using (XLWorkbook workbook = new ClosedXML.Excel.XLWorkbook())
{
using (var sheet = workbook.AddWorksheet("Result"))
{
for (int rowNumber = 1; rowNumber < 10000; rowNumber++)
{
using (var row = sheet.Row(rowNumber))
{
for (int columnNumber = 1; columnNumber < 300; columnNumber++)
{
row.Cell(columnNumber).Value = rnd.Next();
}
}
if (rowNumber % Percentage == 0)
Console.Write("\r{0}%", rowNumber / Percentage);
}

using (var table = sheet.RangeUsed().CreateTable())
{
table.Theme = XLTableTheme.TableStyleLight2;
}

Console.Write("\r100%");
string savePath = Path.Combine(@"C:\temp\closedxml\", string.Format("{0}-report.xlsx", DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss")));
workbook.SaveAs(savePath);
}
}
}
```
This generates a file of about 26MB for which around 2.6GB of memory is needed.

Thanks for any feedback, hints & tips.

St

Edited Unassigned: Excessive memory usage, bug? [9395]

$
0
0
Hi

We are using ClosedXML to generate reports with multiple millions of rows and our memory usage just goes through the roof.

As a rule of thumb ClosedXML needs around 100 times the memory a generated .xslx has in size.

Am I doing something wrong? Is there a way to reduce the memory usage besides disabling event tracking?
The whole thing is just straight forward filling of cells, one row at the time. No inserting, moving, styling etc

I can replicate this on a little console application.
```
private static void CreateWorkbook()
{
Random rnd = new Random();
using (XLWorkbook workbook = new ClosedXML.Excel.XLWorkbook())
{
using (var sheet = workbook.AddWorksheet("Result"))
{
for (int rowNumber = 1; rowNumber < 10000; rowNumber++)
{
using (var row = sheet.Row(rowNumber))
{
for (int columnNumber = 1; columnNumber < 300; columnNumber++)
{
row.Cell(columnNumber).Value = rnd.Next();
}
}
if (rowNumber % Percentage == 0)
Console.Write("\r{0}%", rowNumber / Percentage);
}

Console.Write("\r100%");
string savePath = Path.Combine(@"C:\temp\closedxml\", string.Format("{0}-report.xlsx", DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss")));
workbook.SaveAs(savePath);
}
}
}
```
This generates a file of about 26MB for which around 2.6GB of memory is needed.

Thanks for any feedback, hints & tips.

St

Edited Unassigned: Excessive memory usage, bug? [9395]

$
0
0
Hi

We are using ClosedXML to generate reports with multiple millions of rows and our memory usage just goes through the roof.

As a rule of thumb ClosedXML needs around 100 times the memory a generated .xslx has in size.

Am I doing something wrong? Is there a way to reduce the memory usage besides disabling event tracking?
The whole thing is just straight forward filling of cells, one row at the time. No inserting, moving, styling etc

I can replicate this on a little console application.
```
private static void CreateWorkbook()
{
Random rnd = new Random();
using (XLWorkbook workbook = new ClosedXML.Excel.XLWorkbook(XLEventTracking.Disabled))
{
using (var sheet = workbook.AddWorksheet("Result"))
{
for (int rowNumber = 1; rowNumber < 10000; rowNumber++)
{
using (var row = sheet.Row(rowNumber))
{
for (int columnNumber = 1; columnNumber < 300; columnNumber++)
{
row.Cell(columnNumber).Value = rnd.Next();
}
}
if (rowNumber % Percentage == 0)
Console.Write("\r{0}%", rowNumber / Percentage);
}

Console.Write("\r100%");
string savePath = Path.Combine(@"C:\temp\closedxml\", string.Format("{0}-report.xlsx", DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss")));
workbook.SaveAs(savePath);
}
}
}
```
This generates a file of about 26MB for which around 2.6GB of memory is needed.

Thanks for any feedback, hints & tips.

St

Edited Unassigned: Excessive memory usage, bug? [9395]

$
0
0
Hi

We are using ClosedXML to generate reports with multiple millions of cells and our memory usage just goes through the roof.

As a rule of thumb ClosedXML needs around 100 times the memory a generated .xslx has in size.

Am I doing something wrong? Is there a way to reduce the memory usage besides disabling event tracking?
The whole thing is just straight forward filling of cells, one row at the time. No inserting, moving, styling etc

I can replicate this on a little console application.
```
private static void CreateWorkbook()
{
Random rnd = new Random();
using (XLWorkbook workbook = new ClosedXML.Excel.XLWorkbook(XLEventTracking.Disabled))
{
using (var sheet = workbook.AddWorksheet("Result"))
{
for (int rowNumber = 1; rowNumber < 10000; rowNumber++)
{
using (var row = sheet.Row(rowNumber))
{
for (int columnNumber = 1; columnNumber < 300; columnNumber++)
{
row.Cell(columnNumber).Value = rnd.Next();
}
}
if (rowNumber % Percentage == 0)
Console.Write("\r{0}%", rowNumber / Percentage);
}

Console.Write("\r100%");
string savePath = Path.Combine(@"C:\temp\closedxml\", string.Format("{0}-report.xlsx", DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss")));
workbook.SaveAs(savePath);
}
}
}
```
This generates a file of about 26MB for which around 2.6GB of memory is needed.

Thanks for any feedback, hints & tips.

St

Closed Unassigned: Excessive memory usage, bug? [9395]

$
0
0
Hi

We are using ClosedXML to generate reports with multiple millions of cells and our memory usage just goes through the roof.

As a rule of thumb ClosedXML needs around 100 times the memory a generated .xslx has in size.

Am I doing something wrong? Is there a way to reduce the memory usage besides disabling event tracking?
The whole thing is just straight forward filling of cells, one row at the time. No inserting, moving, styling etc

I can replicate this on a little console application.
```
private static void CreateWorkbook()
{
Random rnd = new Random();
using (XLWorkbook workbook = new ClosedXML.Excel.XLWorkbook(XLEventTracking.Disabled))
{
using (var sheet = workbook.AddWorksheet("Result"))
{
for (int rowNumber = 1; rowNumber < 10000; rowNumber++)
{
using (var row = sheet.Row(rowNumber))
{
for (int columnNumber = 1; columnNumber < 300; columnNumber++)
{
row.Cell(columnNumber).Value = rnd.Next();
}
}
if (rowNumber % Percentage == 0)
Console.Write("\r{0}%", rowNumber / Percentage);
}

Console.Write("\r100%");
string savePath = Path.Combine(@"C:\temp\closedxml\", string.Format("{0}-report.xlsx", DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss")));
workbook.SaveAs(savePath);
}
}
}
```
This generates a file of about 26MB for which around 2.6GB of memory is needed.

Thanks for any feedback, hints & tips.

St
Comments: 2.6GB to process 3 million cells is the price you pay for all the niceties ClosedXML has to offer. btw, it's 26MB compressed so the file is actually 162MB.

Created Unassigned: Cell.Value throw FormatException [9396]

$
0
0
It will throw the format exception when get the cell value which set the cell format is percent.
And I try to get the cell value like this code.

```
ClosedXML.Excel.XLWorkbook wb = new ClosedXML.Excel.XLWorkbook(new FileStream(@"New Microsoft Excel Test.xlsx", FileMode.OpenOrCreate));
var cell = wb.Worksheet("Sheet1").Cell("A1");
var value = cell.Value; //It will throw the format exception
```

Viewing all 1877 articles
Browse latest View live


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