Closed Issue: Databars causing Unhandled Exception [8418]
Closed Issue: Range is invalid when saving a file [8406]
Closed Issue: "NaN" causes unreadable content error [8403]
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]
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]
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]
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]
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]
```
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]
```
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
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
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
Commented Issue: Workbook cannot be opened if it contains a table that is filtered by a date. [8581]
```
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
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
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??
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]
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"
New Post: How to Share a spreadsheet?
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'.
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