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

Closed Issue: Databars causing Unhandled Exception [8418]

$
0
0
Hi,opening a file with simple databars and saving the file without doing anything else is causing this exception.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.XLCFDataBarConverter.Convert(IXLConditionalFormat cf, Int32 priority, SaveContext context) at ClosedXML.Excel.XLCFConverters.Convert(IXLConditionalFormat conditionalFormat, Int32 priority, SaveContext context) 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)I attached a simple xlsx. I also tried the latest check-in.Edit: I should have uploaded the valid file - not the corrupted one.br,Peter

Closed Issue: Range is invalid when saving a file [8406]

$
0
0
Hi, im trying to learn ClosedXML and doing some simple Tests with my Excel Template. private void testCX_direct() { XLWorkbook wb = new XLWorkbook(@"z:\xls\EAV_VU-Daten_Master_1.xlsx"); // öffnen IXLRange r1 = wb.Range("meldung_zeile"); var ws = r1.Worksheet; int rowNr = r1.FirstRow().RowNumber(); for (int i = 1; i < anz_rows; i++) { for (int k = 0; k < 20; k++) { ws.Cell(rowNr, 1 + k).Value = k.ToString(); } ws.Row(rowNr).CopyTo(ws.Row(rowNr + i)); // neue zeile einfügen } ws.Row(rowNr).Delete(); wb.SaveAs(@"z:\xls\EAV_VU-Daten_Master_ClosedXML.xlsx"); }it works well, but when trying to save the file it throws an error (range is invalid)'Einnahmemeldungen'!$A$3:$A$3 in Worksheet Einnahmemeldungenthat range doesnt even exist. the only one i can think of is the named row, and even if i delete that one (ws.NamedRanges.DeleteAll();)the error is still there.attaching the xlsx file that i use a test-template for the above code.

Closed Issue: "NaN" causes unreadable content error [8403]

$
0
0
I was getting "Excel found unreadable content" errors in some of my workbooks, but I finally tracked down the issue. To reproduce, start a new workbook and add "NaN" to one of the cells:

Dim wb As New XLWorkbook()
Dim ws As IXLWorksheet = wb.Worksheets.Add("Test")
ws.Cell(1, 1).Value = "NaN"

Upon opening the file, you'll get the "unreadable content" error. If you choose to repair the file, it will then show "NaN" in the cell as expected.

I compared the orignial and repaired versions of xl\SharedStrings.xml, and "NaN" wasn't present in the original file - could that have something to do with it?

Closed Issue: ValueCached shows null after I reopen the ClosedXML saved file [8396]

$
0
0
I faced an issue while trying to recover a formula cell through ValueCache after saving the file through the workbook save method. Following are the steps to reproduce this issue:
1) Open the attached file
2) Its a simple file with the following values
A1 = 8
B1 = 6
C1 = A1 + B1 = 14
3) I use the following code snippet to open the file, read ValueCached from C1, change the value in A1 and save the file. So far its good and the ValueCached shows the correct value which is 14. Now when I run this second time, the ValueCached shows null

var wb = new XLWorkbook(@"c:\fincalc\simple.xlsx");
var ws = wb.Worksheet(1);
var c1 = ws.Cell("C1").ValueCached;
ws.Cell("A1").Value = "10";
wb.Save();

4) Also if I open the same file through excel and try to exit excel, it promts me to save the file even when I have not changed anything. Can you please let me know if the wb.Save() method is missing out something while saving the file?

Thanks in advance for your time.

Closed Issue: Freeze + Cell select creates unreadable excel [8389]

$
0
0
Hi there,

I found that whenever I do the following:

sheet.SheetView.FreezeColumns(1);
sheet.Cell(1, 1).Select();

The Excel saved is unreadable by MS Excel. However, if I either don't select the first cell or don't freeze panes, the resultant Excel works fine.

Closed Issue: Version 68.1 changed order of Rows collection [8373]

$
0
0
I upgraded from version 67.2 to version 68.1 and now the following code does not work.

int rowCount = 0;
XLWorkbook sourceWB = new XLWorkbook(fileLocation);
IXLWorksheet sourceWS = sourceWB.Worksheet(1);
foreach (IXLRow row in sourceWS.Rows())
{
rowCount = row.RowNumber();
...
}

In version 67.2 and all prior versions this gave me each row in order starting at row 1.
Now in version 68.1 the first row in the list is the row of the cell that was selected when the file was saved.

This breaks all my existing code because I expect the first row in the list to be the header row and I depend on the rows being in order.

Thank you.

Closed Issue: Issue with inserting and deleting row [8339]

$
0
0
I am still having issues with these edge cases when inserting and deleting rows, where cells are selected. As before I do not get library errors but, do get an error in excel when opening the file.

I tried adding sh1.Cell(1, 1).Select(); before deleting/adding rows, but that did not help.

Below are the two tests I was using.

using (XLWorkbook b = new XLWorkbook("C:\\rowDelete2.xlsx"))
{

IXLWorksheet sh1 = b.Worksheets.Worksheet(1);

sh1.Row(2).InsertRowsAbove(2);
sh1.Row(4).Delete();
sh1.Row(4).Delete();

b.SaveAs("C:\\rowDelete_modify2.xlsx");
}


using (XLWorkbook b = new XLWorkbook("C:\\rowDelete.xlsx"))
{

IXLWorksheet sh1 = b.Worksheets.Worksheet(1);

sh1.Row(2).InsertRowsAbove(2);
sh1.Row(4).Delete();

b.SaveAs("C:\\rowDelete_modify.xlsx");
}

Commented Issue: Workbook cannot be opened if it contains a table that is filtered by a date. [8581]

$
0
0
The following code results in an InvalidCastException when the Workbook contains a table where a column is filtered by the date. At example workbook is attached.

```
new XLWorkbook(@"C:\Scratch\DateFilter example.xlsx")
```

The full details of the exception are:
```
Unable to cast object of type 'DocumentFormat.OpenXml.Spreadsheet.DateGroupItem' to type 'DocumentFormat.OpenXml.Spreadsheet.Filter'.
at ClosedXML.Excel.XLWorkbook.LoadAutoFilterColumns(AutoFilter af, XLAutoFilter autoFilter)
at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName)
at ClosedXML.Excel.XLWorkbook..ctor(String file)
```
Comments: ** Comment from web user: Ged325 **

I added this to XLWorkbook_Load.cs at line ~1200

Boolean isText = false;
[b] foreach (Object f in filterColumn.Filters)
{

if (f.GetType().FullName == "DocumentFormat.OpenXml.Spreadsheet.Filter")
{
[/b]
foreach (Filter filter in filterColumn.Filters)
{


Commented Issue: Workbook cannot be opened if it contains a table that is filtered by a date. [8581]

$
0
0
The following code results in an InvalidCastException when the Workbook contains a table where a column is filtered by the date. At example workbook is attached.

```
new XLWorkbook(@"C:\Scratch\DateFilter example.xlsx")
```

The full details of the exception are:
```
Unable to cast object of type 'DocumentFormat.OpenXml.Spreadsheet.DateGroupItem' to type 'DocumentFormat.OpenXml.Spreadsheet.Filter'.
at ClosedXML.Excel.XLWorkbook.LoadAutoFilterColumns(AutoFilter af, XLAutoFilter autoFilter)
at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName)
at ClosedXML.Excel.XLWorkbook..ctor(String file)
```
Comments: ** Comment from web user: Ged325 **

Please note the above is NOT tested for all cases, but it bypassed the issue for me to allow it to open. For my project I'm not using filters, I just need the spreadsheet data.

New Post: Identifier Expected

$
0
0
The following does work:

namespace ClosedXML_Issues
{
class _443852
{
    public void Test()
    {
        string targetFile = this.ToString() + ".xlsx";

        // Create workbook
        XLWorkbook wb = new XLWorkbook();

        // Sheet1 is just data - as extracted from sql server 
        IXLWorksheet ws1 = wb.Worksheets.Add("sheet1");
        ws1.Cell("A6").Value = 3.14159;  // everybody like pi

        // On Sheet2 are a number of "='Sheet1'!<CellRef>" formulas (where <CellRef> is the A1 style reference for the cell)
        IXLWorksheet ws2 = wb.Worksheets.Add("sheet2");
        ws2.Cell("B12").FormulaA1 = @"=sheet1!A6";

        // copy the information in sheet2 to a different range on Sheet2
        double sourceValue = ws2.Cell("B12").GetDouble();
        ws2.Cell("B32").Value = sourceValue;

        wb.SaveAs(targetFile);
    }
}
}

The above generates a value in two cells in sheet2. Perhaps the single quotes around sheet1 is your issue??
  • MJH

New Post: Reading call values for empty cells in first row

$
0
0
When I read the values from empty cells in the first row the values are returned as "Column1", "Column2" etc.
How can I turn off this behaviour so the cell values are reported as an empty string?
Thanks.

New Post: Reading call values for empty cells in first row

$
0
0
Do you have a table? If so you can use table.DataRange

Commented Issue: Workbook cannot be opened if it contains a table that is filtered by a date. [8581]

$
0
0
The following code results in an InvalidCastException when the Workbook contains a table where a column is filtered by the date. At example workbook is attached.

```
new XLWorkbook(@"C:\Scratch\DateFilter example.xlsx")
```

The full details of the exception are:
```
Unable to cast object of type 'DocumentFormat.OpenXml.Spreadsheet.DateGroupItem' to type 'DocumentFormat.OpenXml.Spreadsheet.Filter'.
at ClosedXML.Excel.XLWorkbook.LoadAutoFilterColumns(AutoFilter af, XLAutoFilter autoFilter)
at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName)
at ClosedXML.Excel.XLWorkbook..ctor(String file)
```
Comments: ** Comment from web user: rhysparry **

Thanks @Ged325.

I've attached my patch which works in a similar way to yours except using the OfType<T>() extension method to do the necessary filter filtering by type. Like you I only need the data which seems to be workable with the solution and so far doesn't seem to make things any worse than they already are.

Patch Uploaded: #14519

$
0
0

rhysparry has uploaded a patch.

Description:
Works around the filter issue by only using the current filtering logic on filters of type 'Filter'. This enables the opening of excel files with active date filters.

New Post: Case issues with Named Ranges

$
0
0
Hi,

I am very pleased with the library overall, but am having one issue converting my application to this method vs. OLEDB. I have an application that goes after specific named ranges in a series of spreadsheets and reformats the data. The OLEDB connections were not case sensitive, so the users have been lax about case when naming the ranges. It appears from my testing that your range functions are case sensitive, at least by default. Is there any way to override this and make a range extraction case insensitive? There are dozens of these spreadsheets, so reworking all of the ranges to a uniform case is not a trivial thing.

Thanks,

Jim Reinardy

Jim

New Post: How to get value of reference??

$
0
0
Hi!

I'm reading data from an Excel sheet, that contains references. For example in Excel the Cell C4 contains "='E-Modul'!D87".
When I try to read the value of Cell C4 with ClosedXML, I need to get cell.CachedValue.
Sometimes cell.CachedValue is NULL. I got no idea what influences that... When cell.CachedValue is null, I try to get cell.Value, but that throws an Exception "Circular Reference".

The cell D87 in sheet "E-Modul" contains a formula: "=IF($B$2=1;P10;IF($B$2=2;P29;IF($B$2=3;Y48;IF($B$2=4;J67;"Ebene wählen"))))"

What am I doing wrong?

Thanks!

Created 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 CentralGUI.UI.Controls.ShowViewReportCountPerStopTable.ViewReportCountPerStopTableControl.ViewReportCountPerStopExportExcelButton_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)

New Comment on "Conditional Formatting"

$
0
0
Hi!! How can I add another conditional format? Something like this code: ws.RangeUsed().AddConditionalFormat().WhenBetween(2, 3).Fill.SetBackgroundColor(XLColor.Red); ws.RangeUsed().AddConditionalFormat().WhenEquals(1).Fill.SetBackgroundColor(XLColor.Green); I need to add multiple conditional formats...thanks for your advance!!

New Post: How to Share a spreadsheet?

$
0
0
The above link tells how to share a workbook using OpenXML.

Is this feature available with ClosedXML. If yes, can any one share the sample code.

New Post: The 'br' start tag on line 19 position 30 does not match the end tag of 'u'.

$
0
0
Hello,

In the below code, I just tried to update the cell values, but, while saving back to excel i got the exception. May anyone know the reason for it. Thanks in advance.

CODE:
var workBook = new XLWorkbook(fileName);
            workBook.CalculateMode = XLCalculateMode.Auto;
            IXLWorksheet worksheet = null;
            workBook.Worksheets.TryGetWorksheet("Transverse", out worksheet);
            if (worksheet != null)
            {
                var firstDataCell = worksheet.Cell("A8");
                var lastDataCell = worksheet.LastCellUsed();
                var rngData = worksheet.Range(firstDataCell.Address, lastDataCell.Address);
                string value = string.Empty;
                IXLCells cells = rngData.CellsUsed(p => p.ValueCached != null && p.ValueCached.ToString().ToLower().Equals("12799"));
                if (cells.Any())
                {
                    foreach (var xlCell in cells)
                    {
                        int rowNumber = xlCell.WorksheetRow().RowNumber();
                        worksheet.Row(rowNumber).Cells(p => p.Address.ColumnLetter.Equals("B")).Value = "Karthik";
                        worksheet.Row(rowNumber).Cells(p => p.Address.ColumnLetter.Equals("D")).Value = 200;
                        worksheet.Cells("D" + rowNumber).Style.Alignment.WrapText = true;
                        worksheet.Range("D" + rowNumber + ":" + "D" + (rowNumber + 1)).Column(1).Merge();
                    }
                }
                workBook.SaveAs("C:\\Users\\20003522\\Desktop\\Combine_1.xlsx");
EXCEPTION:

at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
at System.Xml.XmlTextReaderImpl.ThrowTagMismatch(NodeData startTag)
at System.Xml.XmlTextReaderImpl.ParseEndElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at System.Xml.Linq.XDocument.Load(XmlReader reader)
at ClosedXML.Excel.XDocumentExtensions.Load(Stream stream)
at ClosedXML.Excel.XLWorkbook.DeleteComments(WorksheetPart worksheetPart, XLWorksheet worksheet, SaveContext context)
at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document)
at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath)
at ClosedXML.Excel.XLWorkbook.SaveAs(String file)
at ClosedXMLTEST.Form1.ReadAndUpdateExcel(String fileName) in D:\Rnd\Learning\ClosedXMLTEST\Form1.cs:line 56
Viewing all 1877 articles
Browse latest View live


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