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

New Post: Input string was not in a correct format when reading cell value

$
0
0
Hi,
Gettting "Input string was not in a correct format" exception when reading value from cell.
Also tried "GetDouble()" as this cell contains formula that returns number, but the same exception is thrown.
var requestedFundingStr = worksheet.Cell("C6").GetString();
File that is causing this error - file download link

ClosedXML version 0.68.1.0, DocumentFormat.OpenXml version 2.0.5022.0

New Post: Input string was not in a correct format when reading cell value

$
0
0
I just encountered this bug as well. I think it happens when a formula references an empty cell. Excel evaluates an empty cell as zero, but ClosedXML throws an exception.

Created Unassigned: Style, colour, formulas when using XLEventTracking.Disabled [8852]

$
0
0
i need to create some larger excel sheets using a "template" for colors, forumulas and styles.
(template is attached).
1st thing i do is adding the nr of needed rows using
ws.Row(srcrow).InsertRowsBelow();
srcrow is the row with the colors, formulas and stuff

when i open the template with XLEventTracking.Enabled i get Out of memory exeptions on some larger files.

when i try it with XLEventTracking.Disabled it seem a lot better with memory usage, but the copy'd rowd dont have colors styles or formulas.

C.huede

Commented Unassigned: System.OutOfMemoryException in v0.68.0.10, regression? [8808]

$
0
0
Hello,

In order to improve the speed of reading/writing of Excel files, I have recently updated ClosedXML from v0.64.0.0 to v0.68.0.10.

The kind of Excel file that I deal with is a big file, embedding a lot of VBA code ; I use it as a template, filling only 2 sheets with raw data (number or string, no formula).

The VBA developper improve this file continuously, for some files there was a huge speed difference, but we have arrived in a point where :

- With v0.64.0.0, we have the good results, but it is very slow
- With v0.68.0.10, the memory is increasing and then a "System.OutOfMemoryException" is thrown.

The exception is thrown in the code below

```
public XLWorkbook OpenExcel(MemoryStream xlsStream)
{
return new XLWorkbook(xlsStream, XLEventTracking.Disabled); //RR 13/06/2013 Turning off events
}
```

with v0.64.0.0 the memory is not increasing a lot during this operation (quite stable), but with v0.68.0.10 the memory used is increasing a lot (1 more GB) and then the exception occured.

I try to turn of the events, but it doesn't change anything.

Does anyone else had this issue before?

Thank you very much for your help.

Regards,
Renaud
Comments: ** Comment from web user: chuede **

any news in this case? i too have OutOfMemoryException problems on larger files.

Patch Uploaded: #14770

$
0
0

S1 has uploaded a patch.

Description:
- Added workaround for 'XLCell.Value' crash, when Value would be a 'Percentage', e.g. "0.00%" but treated as 'Number' and cannot be parsed to double.
The real fix would be to handle a 'XLCellValues.Percentage' instead.

- Fixed bug in Expression.cs where trying to evaluate a formula pointing to a cell without value would crash

New Post: Worksheets Incompatible with Excel 2007

$
0
0
Hello,

I am using Closed XML to generate Excel reports in VB.NET in the following way:

Workbook.SaveAs("myFile.xlsx")
Dim BinaryData() As Byte = File.ReadAllBytes("myFile.xlsx")
Response.AddHeader("Content-Length", BinaryData.Length - 1)
Response.AppendHeader("Content-Disposition", "attachment; filename=myFile.xlsx")
Response.BinaryWrite(BinaryData)

When I use Excel 2010 to open the file, everything works perfectly.

When I use Excel 2007 to open the file, it opens up with a bunch of gibberish.

Does anyone have any ideas about what might be casuing this?

New Post: Excel 2013 - 2010 compatibility

Created Unassigned: Background Cell Color [8860]

$
0
0
.Style.Fill.SetBackgroundColor() property sets the color pattern and not the background color :

public XLColor BackgroundColor
{
.....
get { return _patternColor; }
.....
_patternType = value.HasValue ? XLFillPatternValues.Solid : XLFillPatternValues.None;
_patternColor = new XLColor(value);
_patternBackgroundColor = new XLColor(value);
.....
}
}
}

Created Unassigned: Excessive Memory allocation using Borders [8862]

$
0
0
Hi, I am creating a relatively simple spreadsheet (from a dataset/datatable) with 27 columns and around 2500 rows and while performance is much better than Excel Interop, using borders can cause memory use to climb dramatically.

The company requires a thin border around the header and whole table and a hair border between columns and rows.

If I define borders on this table my application memory use increases from ~120MB to 400+MB while the inside borders are defined. Filling the table with data on a cell-by-cell basis setting number formats etc caused a ~50MB increase

Larger tables (9000+ rows) can push the memory use over 1.4GB and cause an out-of-memory exception.

Compiling and/or running a 64-bit application is not an option due to the mix of hardware + OS in use.

I have tried the following (where dt is a datatable)
var rngContent = ws.Range(1, 1, dt.Rows.Count, dt.Columns.Count);
rngContent.Style.Borders.InsiderBorder = XLBorderStyleValues.Hair;
rngContent.Style.Borders.OutsideBorder = XLBorderStyleValues.Thin;
or on a row-by-row basis
or on a cell-by-cell basis (OutsideBorder)
and using SetInsideBorder & SetOutsideBorder

Setting other formatting options such as alignment across the table or on a cell by cell basis etc does not appear to increase the memory in this way.

Created Unassigned: German Special Characters Problem when Exporting to Excel [8869]

$
0
0
Hello,

i`m sucessfully exporting a GridView into Excel but when using german special characters (ä, ü, ö, ß) they get replaced with ü in the excel file. Is there a way to fix that problem? Not using these characters isn't an option. ;-)

My Code looks like following:

```
Response.Clear();

Response.AddHeader("content-disposition",
"attachment;filename=ExcelExport.xls");

Response.Charset = "";

// If you want the option to open the Excel file without saving than

// comment out the line below

// Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);

GridView1.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();
}

protected void Button1_Click(object sender, EventArgs e)
{
// Create the workbook
var Workbook = new XLWorkbook();

// Create the table
DataTable dt = new DataTable();

// Important because the sheet must have a name
dt.TableName = "Information";

// Not allowing Paging to avoid potential problems with GridView
// Replaces gvUpLoad with your own GridView
GridView1.AllowPaging = false;

// Loop the GridView to copy it as DataTable
// add the columns to the datatable
if (GridView1.HeaderRow != null)
{
for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
{
dt.Columns.Add(GridView1.HeaderRow.Cells[i].Text);
}
}

// add each of the data rows to the table
foreach (GridViewRow row in GridView1.Rows)
{
DataRow dr;
dr = dt.NewRow();

for (int i = 0; i < row.Cells.Count; i++)
{
dr[i] = row.Cells[i].Text.Replace("&nbsp;", "");
}
dt.Rows.Add(dr);
}

// add the footer row to the table
if (GridView1.FooterRow != null)
{
DataRow dr;
dr = dt.NewRow();

for (int i = 0; i < GridView1.FooterRow.Cells.Count; i++)
{
dr[i] = GridView1.FooterRow.Cells[i].Text.Replace("&nbsp;", "");
}
dt.Rows.Add(dr);
}

// Add a DataTable as a worksheet
Workbook.Worksheets.Add(dt);

// Create Response
HttpResponse response = Response;

//Prepare the response
response.Clear();
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
response.AddHeader("content-disposition", "attachment;filename=HelloWorld.xlsx");

//Flush the workbook to the Response.OutputStream
using (MemoryStream MyMemoryStream = new MemoryStream())
{
Workbook.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(response.OutputStream);
MyMemoryStream.Close();
}

response.End();
```

Thanks in Advance for any help.

Greetings

musti2k3

New Post: German Special Characters Problem when Exporting to Excel

$
0
0
Hello,

i`m sucessfully exporting a GridView into Excel but when using german special characters (ä, ü, ö, ß) they get replaced with "& #252;" in the excel file. Is there a way to fix that problem? Not using these characters isn't an option. ;-)

My Code looks like following:
        protected void Button1_Click(object sender, EventArgs e)
        {
            // Create the workbook
            var Workbook = new XLWorkbook();

            // Create the table
            DataTable dt = new DataTable();

            // Important because the sheet must have a name
            dt.TableName = "Information";

            // Not allowing Paging to avoid potential problems with GridView
            // Replaces gvUpLoad with your own GridView
            GridView1.AllowPaging = false;

            // Loop the GridView to copy it as DataTable
            // add the columns to the datatable            
            if (GridView1.HeaderRow != null)
            {
                for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
                {
                    dt.Columns.Add(GridView1.HeaderRow.Cells[i].Text);
                }
            }

            //  add each of the data rows to the table
            foreach (GridViewRow row in GridView1.Rows)
            {
                DataRow dr;
                dr = dt.NewRow();

                for (int i = 0; i < row.Cells.Count; i++)
                {
                    dr[i] = row.Cells[i].Text.Replace(" ", "");
                }
                dt.Rows.Add(dr);
            }

            //  add the footer row to the table
            if (GridView1.FooterRow != null)
            {
                DataRow dr;
                dr = dt.NewRow();

                for (int i = 0; i < GridView1.FooterRow.Cells.Count; i++)
                {
                    dr[i] = GridView1.FooterRow.Cells[i].Text.Replace(" ", "");
                }
                dt.Rows.Add(dr);
            }

            // Add a DataTable as a worksheet
            Workbook.Worksheets.Add(dt);

            // Create Response
            HttpResponse response = Response;

            //Prepare the response
            response.Clear();
            response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            response.AddHeader("content-disposition", "attachment;filename=HelloWorld.xlsx");

            //Flush the workbook to the Response.OutputStream
            using (MemoryStream MyMemoryStream = new MemoryStream())
            {
                Workbook.SaveAs(MyMemoryStream);
                MyMemoryStream.WriteTo(response.OutputStream);
                MyMemoryStream.Close();
            }

            response.End(); 
Thanks in Advance for any help.

Greetings

musti2k3

Created Unassigned: Open XML 2.5 [8873]

$
0
0
Hi,

if i use Open XML 2.5 the ClosedXML library not work because, i thing, is compiled with Open XML 2.0.
It 'will be a new implementation of ClosedXML with Open XML 2.5 version?

Thanks

New Post: handle null date

$
0
0
Hello, when I export a datatable to excel if a date columns value is null then created excel file displays 1/0/1900 as the null date value.

How can I ensure if the date value is null to not show 1/0/1900 but display nothing in that cell?

Dim DS As New DataSet
        Dim DT As DataTable
        DS = ConvertToDataSet(MyData)
        DT = DS.Tables(0)

        Dim wb As New XLWorkbook

        wb.Worksheets.Add(DT)

Created Unassigned: Cell formating - missing [8876]

$
0
0
I'm using Closed XML (0.68.1) to read Template document and then to generate new documents from template, but problem is that formatting of cells (Border, colors, ...) is lost after first cycle.
Below my test code

for (int i = 0; i < 4; i++) {
byte[] tTemplate = File.ReadAllBytes("MyTemplate.xlsx");
var workbook = new XLWorkbook(new MemoryStream(tTemplate));

MemoryStream tOut = new MemoryStream();
workbook.SaveAs(tOut);
byte[] tOutData = tOut.ToArray();

string tOutDoc = string.Format("Ret_{0}.xlsx", DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss_fff"));
FileStream tFile = File.Create(tOutDoc);
tFile.Write(tActual, 0, tActual.Length);
tFile.Close();
}

Thanks

Created Unassigned: Evaluating Formulas with Round() [8877]

$
0
0
Hi,

ClosedXML doesn't evaluate formulas with the Round() function.

PS: Is their a list of supported / not supported functions?

Greetings,
Raidri

Commented Unassigned: Evaluating Formulas with Round() [8877]

$
0
0
Hi,

ClosedXML doesn't evaluate formulas with the Round() function.

PS: Is their a list of supported / not supported functions?

Greetings,
Raidri
Comments: ** Comment from web user: Raidri **

Stack trace:

[Exception: Identifier expected.]
ClosedXML.Excel.CalcEngine.CalcEngine.Throw(String msg) +54
ClosedXML.Excel.CalcEngine.CalcEngine.GetToken() +2503
ClosedXML.Excel.CalcEngine.CalcEngine.GetParameters() +126
ClosedXML.Excel.CalcEngine.CalcEngine.ParseAtom() +259
ClosedXML.Excel.CalcEngine.CalcEngine.ParseUnary() +135
ClosedXML.Excel.CalcEngine.CalcEngine.ParsePower() +46
ClosedXML.Excel.CalcEngine.CalcEngine.ParseMulDiv() +46
ClosedXML.Excel.CalcEngine.CalcEngine.ParseAddSub() +46
ClosedXML.Excel.CalcEngine.CalcEngine.ParseCompare() +46
ClosedXML.Excel.CalcEngine.CalcEngine.ParseExpression() +40
ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression) +131
ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression) +218
ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression) +80
ClosedXML.Excel.CalcEngine.CellRangeReference.GetValue(IXLCell cell) +212
ClosedXML.Excel.CalcEngine.CellRangeReference.GetValue() +55
ClosedXML.Excel.CalcEngine.XObjectExpression.Evaluate() +61
ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression) +100
ClosedXML.Excel.CalcEngine.CellRangeReference.GetValue(IXLCell cell) +212
ClosedXML.Excel.CalcEngine.CellRangeReference.GetValue() +55
ClosedXML.Excel.CalcEngine.XObjectExpression.Evaluate() +61
ClosedXML.Excel.CalcEngine.Expression.op_Implicit(Expression x) +51
ClosedXML.Excel.CalcEngine.BinaryExpression.Evaluate() +799
ClosedXML.Excel.CalcEngine.Expression.op_Implicit(Expression x) +51
ClosedXML.Excel.CalcEngine.MathTrig.Round(List`1 p) +60
ClosedXML.Excel.CalcEngine.FunctionExpression.Evaluate() +45
ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression) +100
ClosedXML.Excel.CalcEngine.CellRangeReference.GetValue(IXLCell cell) +212
ClosedXML.Excel.CalcEngine.CellRangeReference.GetValue() +55
ClosedXML.Excel.CalcEngine.XObjectExpression.Evaluate() +61
ClosedXML.Excel.CalcEngine.Expression.op_Implicit(Expression x) +51
ClosedXML.Excel.CalcEngine.BinaryExpression.Evaluate() +579
ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression) +100
ClosedXML.Excel.XLWorksheet.Evaluate(String expression) +51
ClosedXML.Excel.XLCell.get_Value() +1013

Commented Unassigned: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. [8770]

$
0
0
I am getting an error when I try to create an object XLWorkbook.

Code :
```
var workbook = new XLWorkbook();
```


Message that I get :

```
Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Environment.get_UserName()
at ClosedXML.Excel.XLWorkbook..ctor(XLEventTracking eventTracking)
at XXXXXX.UI.Controls.ShowViewXXXXXX.ViewXXXXXXTableControl.ViewXXXXXXExportExcelButton_Click(Object sender, ImageClickEventArgs args) in c:\@work\XXXXXX\XXXXXX\Source\XXXXXX\App_Code\ViewXXXXXX\ShowViewXXXXXX.Controls.cs:line 89
```

I have added the next files to BIN Directory of my website :
* ClosedXML.dll (ClosedXML_Net3.5 version 0.68.1.0)
* DocumentFormat.OpenXml.dll (Open XML Format SDK 2.0 version 2.0.2022.0)
Comments: ** Comment from web user: akorff **

I had this problem. I could open a new workbook or load an existing excel file, but when I published it to production it would not open an existing excel file (only a new workbook).

After a lot of research, I found that 95% of the answer say to set your trust level to full (but unfortunately I already had it set to full on both my dev server and my production server):

In your web.config in the system.web section:
<system.web>
<trustLevel name="Full" policyFile="internal"/>
</system.web>

What solved it for me: If you have access to IIS and you are running IIS 7, find the app pool for the site, and set Load User Profile = True.

New Post: 17 MB a WB with only one WS having 29 rows and 11 columns???

$
0
0
Hi all,

I love ClosedXML. I've used it before to create WBs containing up to 20 WSs. Data source primarily .NET DataTables. I save these WBs files to a MSSQL DB as binary data. Most of these WBs are of size between 118 KB and 150 KB. That's pretty good.

Now I'm trying to create a WB with only one WS from a .NET DataTable that has a schema of 11 columns and returns only 29 rows. This one I don't save it to the database. I send it to the user's browser, so the user can open it or save it.

What happens actually is that IE returns a message stating that the WB can't be opened, thus the user is forced to save it to his/her PC. The resulting file is of size 17,211 KB. Something must be wrong here... Is there something wrong with my code? Any help is greatly appreciated. Thanks.
Dim xlWB As New XLWorkbook(XLEventTracking.Disabled)  
Dim xlWS = xlWB.Worksheets.Add("Report Name")
xlWS.Cell(1, 1).InsertTable(objDs.Tables(0).AsEnumerable())

Dim xlRange_Amount = xlWS.Range("C2:C" & xlWS.RowCount)
xlRange_Amount.Style.NumberFormat.Format = "$ #,##0.00"

xlWS.Columns.AdjustToContents()

Dim objMS As MemoryStream = Nothing
Dim arrByte As Byte()

objMS = New MemoryStream
xlWB.SaveAs(objMS)
arrByte = objMS.GetBuffer

Response.AddHeader("Content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
Response.AddHeader("Content-Disposition", "attachment; filename=Test.xlsx")
Response.BinaryWrite(arrByte)
Response.Flush()
Response.End()

New Comment on "Documentation"

New Post: Background colour of cells being lost

$
0
0
Hi,

I am opening an existing excel file to use as a template. There is a grey background in the template surrounding a "form" in each worksheet.

After setting values of certain cells within the form area (which no not have a Fill), the background colour of random cells outside of the form are lost.

Is there anything which could be causing this? I know I could programmatically set the fill, but this would be very tedious and hard to maintain. I'm wondering if I'm doing something the wrong way which could cause this.

It's worth pointing out that I am not adding any new rows or columns. They are in a fixed position.

Thanks
John
Viewing all 1877 articles
Browse latest View live


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