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

Commented 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.
Comments: ** Comment from web user: FuriCuri **

Any progress on this? It really bugs me to have package manager to update 20+ packages and then fail to update OpenXML due to ClosedXML and I have to update 10+ manually.


Created Unassigned: Console Application (example) OutOfMemoryException [9188]

$
0
0
There is a high priority report we are creating that keeps getting an OutOfMemoryException.
The exception occurs after the report is created and formatting is applied and while the report is being saved.
It doesn't matter whether it is saved to MemoryStream or to a file.

I created a sample console application that can reproduce the problem.
It is being built with VisualStudio 2010 and uses ClosedXml.dll version 0.69.1.0.
I am running on a Windows 7, 64 bit machine with 8GB memory.

The sample application creates a report out of 164,000 custom objects where each object is identical and contains 19 properties. So the finished Excel file would have 164,000 rows, plus the heading row, and 19 columns. When the console application is run from the command line the user can specify how many rows to create. What is interesting is that sometimes it will throw the OutOfMemoryException and sometimes it will go to completion.

The sample application uses identical data in every row, so Excel's string sharing algorithm should conserve a lot of space, but for some reason ClosedXML keeps bombing out.

A lot of people have mentioned the same problem, but I think this is the first time anyone submitted a sample application to test with.

My workaround is to use Aspose.Cells for .Net in place of ClosedXML and Aspose has no problem saving the file, but ClosedXML throws an exception on the same data.
I much prefer the object model used by ClosedXML, but I have to use Aspose.Cells unless this can be fixed.

Thank you.

Created Unassigned: Read Only setting (?) [9189]

$
0
0
Hello and thank you for the library! I need to read data from an Excel Worksheet and this is totally feasible as long as the file is not open when the following statement is invoked:

var xlWorkBook = new ClosedXML.Excel.XLWorkbook(path);

I understand that when writing in an Excel worksheet it should not be possible to have it opened but what about reading? Is there any "only-reading" setting implemented?

Thank you in advance,
a_pri

Created Unassigned: When I try to deal with a file with #REF error, IndexOutOfRangeExceptionexception occurs. [9192]

$
0
0
When I try to deal with a file with #REF error, IndexOutOfRangeExceptionexception occurs.

new XLWorkbook(_errorfile_)

Can't I deal with a file with #REF error?
Without correcting an #REF error, isn't it possible to deal with this file?

New Post: error when copying worksheet

$
0
0
Has anyone found a solution to this issue? I have the same problem. I have 1 workbook with several worksheets. One of the worksheets is a template that is copied the number of times needed.

I get the error "An item with the same key has already been added" every time I try to copy a sheet. Changing the name of the copy doesn't help. I don't see where to set a key that it is finding a duplicate.

Anyone else have this problem? Thanks!

New Post: How do I stop getting the "number stored as text" message?

$
0
0
I've tried many different methods, but I've had no luck. This is the code I'm using to add the value to the cell
ws.Cell(baseCell).Value = NumberValue;
ws.Cell(baseCell).Style.NumberFormat.SetNumberFormatId(37);
ws.Cell(baseCell).SetDataType(XLCellValues.Number);
I've tried it with several datatypes for "NumberValue" including double, decimal, and float.
I've also tried changing the cell datatype from number to text.

No matter what I do I always get the message. The data I'm using to create the document is all numeric values, so the entire sheet has flags.

New Post: How do I stop getting the "number stored as text" message?

$
0
0
Please disregard or delete this discussion. User error. I was changed the cell type further down in the code.

Created Unassigned: Issue enumerating Pivot tables in xlsx.. [9196]

$
0
0
Hi.
Anyone has issues accessing Pivot tables?
.WorkSheet.PivotTables.Count() returns 0 ..

... yet, when I access the xlsx via OpenXML, i can see the Pivot...

using ClosedXML ver 0.69.1.0 on Framework 4.0 ... please advise, thanks....

New Post: User defined Number Format

$
0
0
Hello,
is it possible to make a user definded number Format in Excel-Cells?

I Need something like this: 10,00 pieces
thank you

New Post: Get Value of Formula using Named Range over Sheets

$
0
0
Assume an Excel File with two Sheets "input" and "calc"
input[a1] is named input1 with value 5,
input[b1] has the formula "=input1"
calc[a1] has the formula "=input1" too.

When i try:

var resultByteArray = File.ReadAllBytes(@"C:\temp\test.xlsx");
        using (var mem2 = new MemoryStream())
        {
            mem2.Write(resultByteArray,0,resultByteArray.Length);
            var wbResult = new XLWorkbook(mem2);
            var res = wbResult.Worksheet("input").Cell(1, 2).Value;
            var res2 = wbResult.Worksheet("calc").Cell(1,1).Value;
        }
res will contain 5 and res2 will throw an NullReferenceException...

has anyone an idea how to resolve values over sheet-borders?

New Post: Cells.InsertDataTable Time values are recognized as String

$
0
0
Just realized after long tests that when using this code to fill in many cells, the IIS worker process and therefore the memory consumption shoots up to more than 1GB. Maybe because I used a for loop? Can the developer of this library provide inputs on how to help lessen the memory consumption when I use this code?

I could have just used the Cell.InsertDataTable property instead, but due to certain data types (timestamp variables) I need to use a regular expression to match them then a boolean variable for the if-else statement therefore the use of a for loop.

Much appreciated! :)


small4ward wrote:
I managed to find the solution to my query. But I did not utilize anymore the Cell.InsertData property. What I did was to parse each and every cell according to its data type before assigning it to a particular Excel cell.

For the time values, I used regular expressions to match, then used the boolean variable to parse and set the data type of the cell to either TimeSpan or DateTime depending on what I need.
 public void DataTableToExcel(DataTable dt, string usertemplate, string exceltab)
            {

            //open worksheet
            var workbook = new XLWorkbook(usertemplate);
            var worksheet = workbook.Worksheet(exceltab);

            //declare variables
            int totrow = dt.Rows.Count;
            int totcol = dt.Columns.Count;
            int numval;
            double dobval;
            DateTime dateval;
            TimeSpan timeval;

            //loop through each cells

                for (int i = 0; i < totrow; i++)
                    {
                    DataRow dataRow = dt.Rows[i];

                    for (int j = 0; j < dataRow.Table.Columns.Count; j++)
                        {
                        #region Regex 0:00:00
                        string input = dataRow[j].ToString();
                        string pattern = "^\\d{1}:\\d{2}:\\d{2}";
                        Match match = Regex.Match(input, pattern);
                        bool match1;
                        if (match.Success)
                            {
                            match1 = true;
                            }
                        else
                            {
                            match1 = false;
                            }
                        #endregion

                        #region Regex 00:00:00
                        string input2 = dataRow[j].ToString();
                        string pattern2 = "^\\d{2}:\\d{2}:\\d{2}";
                        Match match2 = Regex.Match(input2, pattern2);
                        bool match3;
                        if (match2.Success)
                            {
                            match3 = true;
                            }
                        else
                            {
                            match3 = false;
                            }
                        #endregion

                        if (int.TryParse(dataRow[j].ToString(), out numval))
                            {
                            var cell = worksheet.Cell(i+2, j + 1);
                            cell.Value = dataRow[j].ToString();
                            cell.DataType = XLCellValues.Number;
                            }
                        else if (double.TryParse(dataRow[j].ToString(), out dobval))
                            {
                            var cell = worksheet.Cell(i+2, j + 1);
                            cell.Value = dataRow[j].ToString();
                            cell.DataType = XLCellValues.Number;
                            }
                        else if (TimeSpan.TryParse(dt.Rows[i].ToString(), out timeval))
                            {
                            var cell = worksheet.Cell(i+2, j + 1);
                            cell.Value = dataRow[j].ToString();
                            cell.DataType = XLCellValues.TimeSpan;
                            continue;
                            }
                        else if (match1 == true) //0:00:00
                            {
                            string[] timeval1 = dataRow[j].ToString().Split(':');
                            TimeSpan t = new TimeSpan(Convert.ToInt16(timeval1[0].ToString()), Convert.ToInt16(timeval1[1].ToString()), Convert.ToInt16(timeval1[2].ToString()));
                            var cell = worksheet.Cell(i+2, j + 1);
                            cell.Value = t.ToString();
                            cell.DataType = XLCellValues.TimeSpan;
                            match1 = false;
                            }
                        else if (match3 == true) //00:00:00
                            {
                            string[] timeval1 = dataRow[j].ToString().Split(':');
                            int hour = Convert.ToInt16(timeval1[0].ToString());

                            if (hour <= 23)
                                {
                                TimeSpan t = new TimeSpan(Convert.ToInt16(timeval1[0].ToString()), Convert.ToInt16(timeval1[1].ToString()), Convert.ToInt16(timeval1[2].ToString()));
                                var cell = worksheet.Cell(i + 2, j + 1);
                                cell.Value = t.ToString();
                                cell.DataType = XLCellValues.TimeSpan;
                                }
                            else
                                {
                                WeirdDateTime d = new WeirdDateTime();
                                d = d.Parse(dataRow[j].ToString());
                                object a = d.ReturnValue;
                                var cell = worksheet.Cell(i + 2, j + 1);
                                cell.Value = a.ToString();
                                cell.DataType = XLCellValues.DateTime;
                                cell.Style.NumberFormat.NumberFormatId = 46;
                                }

                            match3 = false;
                            }
                        else if (DateTime.TryParse(dataRow[j].ToString(), out dateval))
                            {
                            var cell = worksheet.Cell(i + 2, j + 1);
                            cell.Value = dataRow[j].ToString();
                            cell.DataType = XLCellValues.DateTime;
                            }
                        else
                            {
                            var cell = worksheet.Cell(i+2, j + 1);
                            cell.Value = dataRow[j].ToString();
                            cell.DataType = XLCellValues.Text;
                            }
                        }
                    }

            workbook.Save();
            }

New Comment on "Documentation"

$
0
0
it's amazing!!! great library. muhteşem.

Created Unassigned: System.ApplicationException: Column Length must be between 1 and 3. [9206]

$
0
0
When I run this code (there is Data column in my sheet)
```
Console.WriteLine(ws.Cell(2, "Data").GetString());

```

I get this exception
```
Unhandled Exception: System.ApplicationException: Column Length must be between 1 and 3.
at ClosedXML.Excel.XLHelper.GetColumnNumberFromLetter(String columnLetter)
at ClosedXML.Excel.XLAddress..ctor(XLWorksheet worksheet, Int32 rowNumber, String columnLetter, Boolean fixedRow, Boolean fixedColumn)
at ClosedXML.Excel.XLWorksheet.ClosedXML.Excel.IXLWorksheet.Cell(Int32 row, String column)
at ObslugaExcela.Program.Main(String[] args) in e:\DATA\CS-solutions\Polkomtel\ObslugaExcela\ObslugaExcela\Program.cs:line 29

```

I am using .net 3.5

Commented Unassigned: System.ApplicationException: Column Length must be between 1 and 3. [9206]

$
0
0
When I run this code (there is Data column in my sheet)
```
Console.WriteLine(ws.Cell(2, "Data").GetString());

```

I get this exception
```
Unhandled Exception: System.ApplicationException: Column Length must be between 1 and 3.
at ClosedXML.Excel.XLHelper.GetColumnNumberFromLetter(String columnLetter)
at ClosedXML.Excel.XLAddress..ctor(XLWorksheet worksheet, Int32 rowNumber, String columnLetter, Boolean fixedRow, Boolean fixedColumn)
at ClosedXML.Excel.XLWorksheet.ClosedXML.Excel.IXLWorksheet.Cell(Int32 row, String column)
at ObslugaExcela.Program.Main(String[] args) in e:\DATA\CS-solutions\Polkomtel\ObslugaExcela\ObslugaExcela\Program.cs:line 29

```

I am using .Net 3.5 and ClosedXML 0.69.1.0
Comments: ** Comment from web user: robert_pl **

OK, I've found that I can only give letter marking of the column, not name that I gave to this column.

Created Unassigned: System.TypeInitializationException [9213]

$
0
0
Hi,

I am trying to use the ClosedXML library to create an Excel workbook from a VB.Net Windows Form app and am getting a __System.TypeInitializationException__ error when I try and create an XLWorkbook with the following code:

Dim workbook = New XLWorkbook()

I have included the ClosedXML.dll and the DocumentFormat.OpenXml.dll in my project properties (see attachment) as well as

Imports ClosedXML.Excel

Any pointers to what else could be wrong would be appreciated.

Thanks,

M

New Post: How to open xl file diractly in closed xml

$
0
0
I have successfully created xl file and stored local path, How open the xl file diractly using source code.

New Post: Redistributible for my App using ClosedXML

$
0
0
Great tool!

First, in development,

Any Nuget package for ClosedXML?

What's about DocumentFormat.OpenXml.dll ?

Second, in deployment,

How can I redistributible my App using ClosedXML ( and DocumentFormat.OpenXml.dll) ? XCOPY deployment is right ?

Thx.

Created Unassigned: Databar with negative values [9216]

$
0
0
Hi everybody,

I have a column with numbers ( positive and negative ) and I want to add databars to them. when I do this directly in excel, then it generates bars with different colors in both directions ( positive and negative ). when I apply the same formatting using closedXML, the bars only go in the positive direction. I did a bit of digging and I realized that the negative value handling was introduced in Excel 2010. How hard would it be to add support for this feature to closedXML ? is there any intention to add it at all ?

Thank you tons.

Best,
Ali

New Post: OpenXML 2.5 not totally compatible to 2.0?

$
0
0
About DocumentFormat.OpenXml and OpenXML SDK, and ClosedXML

Note: I have send message in nuget, for better support, I post here again.

DocumentFormat.OpenXml 2.5.0 uses Microsoft OpenXML SDK 2.5
http://www.nuget.org/packages/DocumentFormat.OpenXml/

Here Open XML SDK 2.0.0
http://www.nuget.org/packages/OpenXmlSdk/

ClosedXML has dependency DocumentFormat.OpenXml version 2.0.5022.0 (Open XML SDK 2.0.0 )
https://www.nuget.org/packages/ClosedXML


Questions:

1.) ClosedXML will be available for Microsoft OpenXML SDK 2.5 (DocumentFormat.OpenXml 2.5.0) ?

2.) http://www.nuget.org/packages/OpenXmlSdk/ will be available for OpenXML SDK 2.5?

Thx.

New Post: How do I stop getting the "number stored as text" message?

$
0
0
hello,
I have a simmilar problem. I'm using a DataTable as source to export data to Excel File (xls)
When I opening this file all digits I have to convert from text to digit.
What Can I change in my code to solve problem "number stored as text" in my exported data in EXCEL file ??
When I exporting to XLSX I have the same problem and second problem - numeric digit has dot instead of comma. (XLS format has no problem with commas)

 using (XLWorkbook wb = new XLWorkbook())
                {
                    wb.Worksheets.Add(dt);

                    Response.Clear();
                    Response.Buffer = true;
                    Response.Charset = "";
                    //Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.ContentType = "application/vnd.ms-excel";
                    Response.AddHeader("content-disposition", "attachment;filename=File1.xls");
                    using (MemoryStream MyMemoryStream = new MemoryStream())
                    {
                        wb.SaveAs(MyMemoryStream);
                        MyMemoryStream.WriteTo(Response.OutputStream);
                        Response.Flush();
                        Response.End();
                    }
                }
Thank you,
Br.
Viewing all 1877 articles
Browse latest View live


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