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

Created Unassigned: System.InvalidOperationException: Sequence contains no elements [9022]

$
0
0
Getting the following exception when reading/evaluation a cell value that contains "=MAX(V7, W7) * 8%" formula:

An Exception occurred: System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.Max(IEnumerable`1 source)
at ClosedXML.Excel.CalcEngine.Tally.Max()
at ClosedXML.Excel.CalcEngine.Statistical.Max(List`1 p)
at ClosedXML.Excel.CalcEngine.FunctionExpression.Evaluate()
at ClosedXML.Excel.CalcEngine.Expression.op_Implicit(Expression x)
at ClosedXML.Excel.CalcEngine.BinaryExpression.Evaluate()
at ClosedXML.Excel.CalcEngine.Expression.op_Implicit(Expression x)
at ClosedXML.Excel.CalcEngine.BinaryExpression.Evaluate()
at ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression)
at ClosedXML.Excel.XLWorksheet.Evaluate(String expression)
at ClosedXML.Excel.XLCell.get_Value()

Both V7 and W7 cell values are blank, but excel handles this scenario by evaluating MAX to 0.0.

New Post: Iphone-Ipad cant open genereted files

$
0
0
Hello,

I have problems when trying open my genereted files on iphone\ipad devices.

Image

Any ideas ?

New Post: Iphone-Ipad cant open genereted files

$
0
0
Yeah, Macs have issues too. The problem is that I can't think of a way to test/debug/fix it. If it tried to repair the file I could then compare them and see what the iPad doesn't like.

Any ideas?

New Post: Iphone-Ipad cant open genereted files

$
0
0
When i save genereted file on desktop and resave it in Excel 2012 to xlsx - the new file normaly opens on iphone. Also size of new resaved file a bit increased.
I also don't know how to debug problem on iphone ;(

New Post: Iphone-Ipad cant open genereted files

$
0
0
That's one of the main frustrations with OpenXML. You change one little thing and the whole file stops working. The way Excel saves the files is different than how ClosedXML does it. I may be able to help if you can find an iPhone/iPad emulator for Windows or Ubuntu that shows the same problem when opening the files.

No promises though,

New Post: Iphone-Ipad cant open genereted files

$
0
0
for history... same file on ipad

Image

New Post: Row Height is not proper

$
0
0
Dear MDeLeon
            Once the Excel generated using Closed XML the data populated in Rows are not aligned properly.   In detail the data in cells are not taking the row height automatically depends on content in respective cells. 


           I had tried worksheet property "Fit to pages" and "Adjust to contents" , But no use.


           How to resolve this issue ? 



Closed Unassigned: Workbook.SaveAs error [9106]

$
0
0
Hi All,
I am trying to use ClosedXLM in a Dynamics NAV environment to speed up some Excel workbook/sheet production. It is a bit complex situation with a template, NamedRanges, and also macro's to fit pictures in cell's.
Everything looks working perfect, speed is 4 times the old solution with an Office automation, till the workbook is saved to a memorystream, when I get the following error :

Microsoft Dynamics NAV
---------------------------
This message is for C/AL programmers: The call to member SaveAs failed: '.', hexadecimal value 0x00, is an invalid character..
---------------------------
OK
---------------------------

Changing saving to file produces the same error. The result file is written to file, but the sheet.xml is invaled.
Apparently the saving process stopped near the end op the process. Validation the XML produced the an error on missing closing tag's as : <x:oddHeader> (and others)

I guess the template is not correct or something like that, but the strange fact is : the automation solution is still working fine.

Any suggestions?

Benno
Comments: Closed per user's comment that they were able to fix the issue on their own.

Commented Unassigned: Datetimes read as double [9091]

$
0
0
Hello friends,

I'm having a problem while reading an .xls using ClosedXML

I'm trying to copy a worksheet into an html table. However, when I get down to the cells that have dates on them (see sample.xls), this is what I get:

Cell.GetFormattedString() = $-4417089]d-mmm-yy
Cell.Value = + 41708.0 {Double}

So, the value is taken as a double instead of a Date, and I haven't found any way to correct this. Any clues?

My version of ClosedXML is 0.59.0.0. However, I've downloaded the latest one, and I get the same results.

Thank you!
Comments: ** Comment from web user: SeanKilleen **

Have you tried something like this in the code that reads the Excel file?

``` C#
var resultDate = yourCellName.GetValue<DateTime>();
```

I think if the date is a date in Excel, that should return a DateTime, which you could then work with normally and format, etc.

Let me know if I'm not understanding correctly.

Created Unassigned: IntegerExtension.ToStringLookup not threadsafe [9118]

$
0
0
Hi,
We are using this library in our service which generates several reports in parallel threads and we're getting the following exceptions:

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)

This error is caused by those lines of code (of static class ClosedXML.Excel.IntegerExtensions):
private static readonly Dictionary<int, string> intToString = new Dictionary<int, string>();

public static string ToStringLookup(this int value)
{
if (!IntegerExtensions.intToString.ContainsKey(value))
IntegerExtensions.intToString.Add(value, value.ToString((IFormatProvider) IntegerExtensions.nfi));
return IntegerExtensions.intToString[value];
}

I think replace this dictionary by ConcurrentDictionary and use AddOrUpdate method will do the trick :)

Regards,
Maciej.

New Post: ClosedXml doesn't copy printer settings

$
0
0
Hi,
I have xltx Excel's template, when I create (manually) new document from it and click File->Print in Excel first sheet fits on one page.

Than I create new document from my template with the help of ClosedXml:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClosedXML.Excel;

namespace ClosedXml1
{
    class Program
    {
        staticvoid Main(string[] args)
        {
            var tXltx = "t.xltx";
            using (XLWorkbook workbook = new XLWorkbook(tXltx))
            {
                using (XLWorkbook newWb = new XLWorkbook())
                {
                    foreach (XLWorksheet worksheet in workbook.Worksheets.Reverse())
                    {
                        worksheet.CopyTo(newWb, worksheet.Name, 1);
                    }

                    newWb.SaveAs("new.xlsx");
                }
            }
        }
    }
}
When I open resulting document and open printing dialog (File->Print) first sheet doesn't fit on one page.

So there are questions:
  1. What has to be copied from original template that resulting sheet fits one page?
  2. Is there any way to accomplish it?
(Here is a SO question)

New Comment on "Pivot Table example"

$
0
0
Hi, I have the same problem described by estyfen when adding two Values. Morover, I find another way to replicate the same error (Removed Feature/Records removde), and here the code to replicate it: public class TEA { public DateTime TimeEntryDate { get; set; } public String EmployeeName { get; set; } public String ProjectName { get; set; } public String DepartmentName { get; set; } public String TimeEntryPeriodName { get; set; } public decimal BillableHours { get; set; } public decimal BilledPrice { get; set; } } ... var items = new List<TEA> { // Uncomment this line and comment the next one to make it working! //new TEA() {TimeEntryDate=new DateTime(2013,10,7), BillableHours = 3, BilledPrice = 0, EmployeeName = "Minnie", DepartmentName = "Dep1", ProjectName = "FORMAZIONE", TimeEntryPeriodName = "Ottobre 2013" }, new TEA() {TimeEntryDate=new DateTime(2013,10,7), BillableHours = 3, BilledPrice = 0, EmployeeName = "Minnie", DepartmentName = "Dep1", ProjectName = "Formazione", TimeEntryPeriodName = "Ottobre 2013" }, new TEA() {TimeEntryDate=new DateTime(2013,10,8), BillableHours = 8, BilledPrice = 0, EmployeeName = "Bugs Bunny", DepartmentName = "Dep2", ProjectName = "FORMAZIONE", TimeEntryPeriodName = "Ottobre 2013" }, new TEA() {TimeEntryDate=new DateTime(2013,10,10), BillableHours = 8, BilledPrice = 0, EmployeeName = "Mickey Nouse", DepartmentName = "Dep2", ProjectName = "FORMAZIONE", TimeEntryPeriodName = "Ottobre 2013" }, }; var workbook = new XLWorkbook(); var sheet = workbook.Worksheets.Add("PastrySalesData"); // Insert our list of pastry data into the "PastrySalesData" sheet at cell 1,1 var source = sheet.Cell(1, 1).InsertTable(items, "PastrySalesData", true); // Create a range that includes our table, including the header row var range = source.DataRange; var header = sheet.Range(1, 1, 1, 7); var dataRange = sheet.Range(header.FirstCell(), range.LastCell()); // Add a new sheet for our pivot table var ptSheet = workbook.Worksheets.Add("PivotTable"); // Create the pivot table, using the data from the "PastrySalesData" table var pt = ptSheet.PivotTables.AddNew("PivotTable", ptSheet.Cell(1, 1), dataRange); // The rows in our pivot table will be the names of the pastries pt.RowLabels.Add("DepartmentName"); // The columns will be the months pt.ColumnLabels.Add("TimeEntryPeriodName"); // The values in our table will come from the "NumberOfOrders" field // The default calculation setting is a total of each row/column pt.Values.Add("BillableHours"); ... However if you replace the ProjectName = "Formazione" with upper case everythings works like a charm. I hope this is helpful for understanding the reason causing the error.

New Comment on "Pivot Table example"

$
0
0
Hi, I have an other question, is it possibile to adjust the pivot column width to displayed contents? I tryed the following ways but they didn't produce the expected result powerPivot.SetAutofitColumns(true); sheet.Columns().AdjustToContents(1, 100);

Created Unassigned: Pivot Table Lower/Upper Case results in error [9121]

$
0
0
Try the below example, and you will get the following error

Error:
Removed Feature: PivotTable report from / xl / PivotTables / pivotTable.xml part ( PivotTable view)
Records removed : book Properties / xl / workbook.xml part ( Book)

Example:

public class TEA
{
public DateTime TimeEntryDate { get; set; }
public String EmployeeName { get; set; }
public String ProjectName { get; set; }
public String DepartmentName { get; set; }
public String TimeEntryPeriodName { get; set; }
public decimal BillableHours { get; set; }
public decimal BilledPrice { get; set; }
}

...
var items = new List<TEA>
{
// Uncomment this line and comment the next one to make it working!
//new TEA() {TimeEntryDate=new DateTime(2013,10,7), BillableHours = 3, BilledPrice = 0, EmployeeName = "Minnie", DepartmentName = "Dep1", ProjectName = "FORMAZIONE", TimeEntryPeriodName = "Ottobre 2013" },
new TEA() {TimeEntryDate=new DateTime(2013,10,7), BillableHours = 3, BilledPrice = 0, EmployeeName = "Minnie", DepartmentName = "Dep1", ProjectName = "Formazione", TimeEntryPeriodName = "Ottobre 2013" },

new TEA() {TimeEntryDate=new DateTime(2013,10,8), BillableHours = 8, BilledPrice = 0, EmployeeName = "Bugs Bunny", DepartmentName = "Dep2", ProjectName = "FORMAZIONE", TimeEntryPeriodName = "Ottobre 2013" },
new TEA() {TimeEntryDate=new DateTime(2013,10,10), BillableHours = 8, BilledPrice = 0, EmployeeName = "Mickey Nouse", DepartmentName = "Dep2", ProjectName = "FORMAZIONE", TimeEntryPeriodName = "Ottobre 2013" },
};

var workbook = new XLWorkbook();
var sheet = workbook.Worksheets.Add("PastrySalesData");

// Insert our list of pastry data into the "PastrySalesData" sheet at cell 1,1
var source = sheet.Cell(1, 1).InsertTable(items, "PastrySalesData", true);

// Create a range that includes our table, including the header row
var range = source.DataRange;
var header = sheet.Range(1, 1, 1, 7);
var dataRange = sheet.Range(header.FirstCell(), range.LastCell());

// Add a new sheet for our pivot table
var ptSheet = workbook.Worksheets.Add("PivotTable");

// Create the pivot table, using the data from the "PastrySalesData" table
var pt = ptSheet.PivotTables.AddNew("PivotTable", ptSheet.Cell(1, 1), dataRange);

// The rows in our pivot table will be the names of the pastries
pt.RowLabels.Add("DepartmentName");

// The columns will be the months
pt.ColumnLabels.Add("TimeEntryPeriodName");

// The values in our table will come from the "NumberOfOrders" field
// The default calculation setting is a total of each row/column
pt.Values.Add("BillableHours");
...

However if you replace the ProjectName = "Formazione" with upper case everythings works like a charm.

I hope this is helpful for understanding the reason causing the error.

Patch Uploaded: #15406

$
0
0

das974 has uploaded a patch.

Description:
This library is great! Great work and thank you!
I am not sure the correct way upload a patch, so I have submitted the file I modified. If you need something else (like the entire solution), please let me know.
Anyways, I have an issue with reading dates that are formatted with a non local format.
Steps:
1) Create Excel file - in cell A1 enter date 5/5/2013
2) Format cell using dd-mmm-yy
3) Read date using the following code:
XLWorkbook wbk = new XLWorkbook(@"Sample.xlsx");
IXLWorksheet sheet = wbk.Worksheets.FirstOrDefault();
DateTime val = sheet.Cell("A1").GetDateTime();

Expected:
val is datetime with value 5/5/2013
Actual:
Error thrown from ClosedXML.Excel.XLCell - function T GetValue<T>
"Cannot convert cell value to System.DateTime"

I believe that the error is because of the locale ID contains a zero which is pre-pended to the number format. In the attached Sample.zip file, you will find the following number format in styles.xml:

<numFmt numFmtId="165" formatCode="[$-409]d\-mmm\-yy;@" />

The string "[$-409]" (the English locale) is expected as described here: http://office.microsoft.com/assistance/hfws.aspx?AssetID=HA010346351033

According to the article - "If you specify a different locale before you select a format, a locale component will be added to the code, in brackets, and the resulting format code may look like this: [$-412]m/d/yy"

This causes the method XLCellValues GetDataTypeFromFormat(String format) in the ClosedXml.Excel.XLWorkbook class to return number as the type.

I modified the function to detect the locale string and skip it, but I feel like there should be a way to get the type from the OpenXml API. Is that not true? It seems like the Excel app knows when numbers are stored as text so I would think (hopefully) there should be some standard way of doing this through the API. I would be glad to research this, though for the short term, I think this patch would suffice as a work-around.


New Post: Formulas auto-change when inserting rows

$
0
0
Could you do SUM(J17:J$17) ?
Alternatively, hide row 16 and make the formula =SUM(J16:J17)
Then when you insert at row 17 it will become = SUM(J16:J18)
Just have to make sure you have no data in row 16!

Commented Unassigned: IntegerExtension.ToStringLookup not threadsafe [9118]

$
0
0
Hi,
We are using this library in our service which generates several reports in parallel threads and we're getting the following exceptions:

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)

This error is caused by those lines of code (of static class ClosedXML.Excel.IntegerExtensions):
private static readonly Dictionary<int, string> intToString = new Dictionary<int, string>();

public static string ToStringLookup(this int value)
{
if (!IntegerExtensions.intToString.ContainsKey(value))
IntegerExtensions.intToString.Add(value, value.ToString((IFormatProvider) IntegerExtensions.nfi));
return IntegerExtensions.intToString[value];
}

I think replace this dictionary by ConcurrentDictionary and use AddOrUpdate method will do the trick :)

Regards,
Maciej.
Comments: ** Comment from web user: SpyderTech02 **

We're seeing the same exception. In case it helps, here's a couple example stack traces, but there are several different stack traces that we've hit this exception with.

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)
at ClosedXML.Excel.XLAddress.ToString()
at System.String.Concat(Object arg0, Object arg1, Object arg2)
at ClosedXML.Excel.XLRangeAddress.ToString()
at ClosedXML.Excel.XLRangeBase.Merge(Boolean checkIntersect)
at ClosedXML.Excel.XLRangeBase.Merge()

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)
at ClosedXML.Excel.XLWorkbook.GenerateWorksheetPartContent(WorksheetPart worksheetPart, XLWorksheet xlWorksheet, SaveContext context)
at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document)
at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath)
at ClosedXML.Excel.XLWorkbook.SaveAs(String file)

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)
at ClosedXML.Excel.XLAddress.GetTrimmedAddress()
at ClosedXML.Excel.XLWorkbook.GenerateWorksheetPartContent(WorksheetPart worksheetPart, XLWorksheet xlWorksheet, SaveContext context)
at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document)
at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath)
at ClosedXML.Excel.XLWorkbook.SaveAs(String file)

Commented Unassigned: IntegerExtension.ToStringLookup not threadsafe [9118]

$
0
0
Hi,
We are using this library in our service which generates several reports in parallel threads and we're getting the following exceptions:

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)

This error is caused by those lines of code (of static class ClosedXML.Excel.IntegerExtensions):
private static readonly Dictionary<int, string> intToString = new Dictionary<int, string>();

public static string ToStringLookup(this int value)
{
if (!IntegerExtensions.intToString.ContainsKey(value))
IntegerExtensions.intToString.Add(value, value.ToString((IFormatProvider) IntegerExtensions.nfi));
return IntegerExtensions.intToString[value];
}

I think replace this dictionary by ConcurrentDictionary and use AddOrUpdate method will do the trick :)

Regards,
Maciej.
Comments: ** Comment from web user: SpyderTech02 **

Something like this should work...

public static class IntegerExtensions
{
private static readonly NumberFormatInfo nfi = CultureInfo.InvariantCulture.NumberFormat;
private static readonly ConcurrentDictionary<Int32, String> intToString = new ConcurrentDictionary<int, string>();
public static String ToStringLookup(this Int32 value)
{
return intToString.GetOrAdd(value, v => v.ToString(nfi));
}
}

Reviewed: ClosedXML 0.69.1 (nov 10, 2013)

$
0
0
Rated 5 Stars (out of 5) - Extremely easy to use, and very helpful documentation. NuGet install in literally seconds, and just minutes to have my DataTable in Excel!

New Post: Feature request: Initial zoom of spreadsheet

$
0
0
This is a feature i would really like as well. Not sure how to raise up to get prioritized but hopefully this comment helps.
Viewing all 1877 articles
Browse latest View live


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