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

New Post: Cannot open xlsx with comments generated by LibreOffice

$
0
0
Hello,

I'm experiencing an odd issue with ClosedXML: I cannot open an xlsx workbook if it contains comments on any cell AND has been saved by LibreOffice.
Comments saved by Microsoft Excel are fine, but if I take the same file, save it again (even without modifications) with LibreOffice, then the workbook cannot be opened anymore. Removing the comment with LibreOffice solves the issue.

It fails at the following line:
XLWorkbook workbook = new XLWorkbook(m_excelPath);

The error I get is the following:
'type' is a duplicate attribute name. Line 1, position 525.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.AttributeDuplCheck()
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
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.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName)
at ClosedXML.Excel.XLWorkbook.Load(String file)
at ClosedXML.Excel.XLWorkbook..ctor(String file, XLEventTracking eventTracking)
at ClosedXML.Excel.XLWorkbook..ctor(String file)


Right now we decided not to use comments, but it would be great if this could work as well.

Thanks in advance,

Martin

New Post: Issue while copying worksheets

$
0
0
I apologize. Indeed the worksheet does not exist.
I ran the sample code by cooper360 and the exception appears to take place in ClosedXml.Excel.XLRowsCollection.Add().
It also throws the exception when trying to copy to a brand new empty workbook.
It's interesting that it fails on the XLRowsCollection.Add() and not in the XLWorksheetsCollection.Add().

Here is the stack trace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary
2.Add(TKey key, TValue value)
at ClosedXML.Excel.XLRowsCollection.Add(Int32 key, XLRow value)
at ClosedXML.Excel.XLWorksheet.<>c__DisplayClass3d.<CopyTo>b__39(KeyValuePair2 kp)
at ClosedXML.Excel.EnumerableExtensions.ForEach[T](IEnumerable
1 source, Action`1 action)
at ClosedXML.Excel.XLWorksheet.CopyTo(XLWorkbook workbook, String newSheetName, Int32 position)
at ClosedXML.Excel.XLWorksheet.CopyTo(XLWorkbook workbook, String newSheetName)
at ClosedXML_Test.Form2.button1_Click(Object sender, EventArgs e) in C:\Users\rtanenbaum\Documents\Downloads\ClosedXML_TestCopyTo\Form2.cs:line 33

New Post: Issue while copying worksheets

$
0
0
MDeLeon wrote:
There's already a sheet with the same name in the workbook.
Please try the simple code and it's interesting.

New Post: How to determine if two cells are merged together

$
0
0
Thanks! Your ClosedXML is great! And this fix is in proper time for me. You saved me from much pain.

New Post: Copy the worksheet to another workbook throw exception but the name not exist.

$
0
0
https://closedxml.codeplex.com/discussions/549543

Issue:
XLWorksheet.cs
  Internals.RowsCollection.ForEach(kp => targetSheet.Internals.RowsCollection.Add(kp.Key, new XLRow(kp.Value)));

I'm not sure that there need a check for some key maybe has exist .

e.g. Code:
( http://www.liuzhiyong2012.cn/dl/ClosedXML_0626.rar )

I don't know why case the difference between the same code but different name in this examle code. And if you have time ,please help and try run the example.
Tanks for you greatly power tools.

New Post: Copy the worksheet and the style is different?

$
0
0
Hi,
I have pick up the latest souce, and try copy worksheet to another workbook.
So,I created a new and clear workbook and copy the worksheet which I created by manual.

Then I found the result file's style is different between the source file.
like, some colomns auto create some backcolor or some cell auto create thier borders , and
this is not the supposed work.

I put my demo here:
(http://www.liuzhiyong2012.cn/dl/ClosedXML_0630.rar)

I'm sorry recently I have put forward a lot of problems . :-D

New Post: Copy the worksheet and the style is different?

$
0
0
After many tests,I found that cause the reason is the template own style issue but it looks well in the open excel.
╮(╯_╰)╭

Commented Issue: How to Filter on a Table? [7732]

$
0
0
The following works (but if I use "SetAutoFilter()" then the workbook is corrupt, I'll fix that). In the meantime just use "table.AutoFilter" instead: var wb = new XLWorkbook();
var ws = wb.Worksheets.Add("Sheet1");

ws.FirstCell().SetValue("Categories")
.CellBelow().SetValue("A")
.CellBelow().SetValue("B")
.CellBelow().SetValue("A")
.CellBelow().SetValue("B");
 
var table = ws.RangeUsed().CreateTable();
table.AutoFilter.Column(1).AddFilter("A");
Comments: I have the same issue... I can't set more than one filter. Do you have any solution about how can you set multiple filter?

Created Unassigned: Cannot set multiple filters [9335]

$
0
0
sheet.RangeUsed().SetAutoFilter().Column(1).AddFilter<string>("testfilter1");
sheet.RangeUsed().SetAutoFilter().Column(2).AddFilter<string>("testfilter2");

Both filters are visible on the dropdown, but only last filter takes effect on the rows.

Commented Unassigned: Named Reference Conaining Table or Formula Produces Ranges Exception [9334]

$
0
0
If I have defined a name that refers to a table range or formula, the ranges property produces an "Invalid Operation Exception"

For example

Name -> ProductionNightDay
RefersTo -> ProductionTable[[Nightshift]:[Dayshift]]
Ranges -> See Exception below
Is there a way to catch this without an exception?


System.InvalidOperationException was unhandled
HResult=-2146233079
Message=Sequence contains no matching element
Source=System.Core
StackTrace:
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
at ClosedXML.Excel.XLNamedRange.<get_Ranges>b__6(<>f__AnonymousType4`2 <>h__TransparentIdentifier2)
at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at ClosedXML.Excel.XLNamedRange.get_Ranges()
at ClosedXML.Excel.XLWorksheet.Range(String rangeAddressStr)
at ClosedXML.Excel.XLWorksheet.ClosedXML.Excel.IXLWorksheet.Range(String rangeAddress)
at TestBid.Program.Main(String[] args) in C:\Users\user\Documents\Visual Studio 2010\Projects\Test\Test\Program.cs:line 34
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Comments: Attach the file.

Commented Unassigned: Cannot set multiple filters [9335]

$
0
0
sheet.RangeUsed().SetAutoFilter().Column(1).AddFilter<string>("testfilter1");
sheet.RangeUsed().SetAutoFilter().Column(2).AddFilter<string>("testfilter2");

Both filters are visible on the dropdown, but only last filter takes effect on the rows.
Comments: As far as I know Excel's autofilter only works with one column at a time.

New Post: Issue while copying worksheets

$
0
0
Okay good people, I've got some good news and some bad news.

The good news is that I just committed a quick fix to the ws copying issue. I don't have your file manjunathg88 so test it.

cooper,

The rows and columns are copied because they contain information like height and width.

In your case you would also want to copy the workbook's named ranges. You can do it with the following code (after copying the worksheets)
foreach (var r in wbSource.NamedRanges.Where(nr => nr.Name != "CellHasFormula"))
{
    wbTarget.NamedRanges.Add(r.Name, r.Ranges);
}
The reason why I'm excluding the CellHasFormula range is because it refers to "NOT(GET.CELL(48,INDIRECT("rc",FALSE)))" and I have no clue how to deal with this kind of named range (the bad news).

So pick up the lates code and let me know if you guys have questions.

/Manuel

New Post: Issue while copying worksheets

$
0
0
Hi MDeLeon, tanks for copying worksheet issue has been fixed .

And do u find the copy worksheet's style is different between the source worksheet in my last example code?
Looks like auto created more boders or background colors in the worksheet named "Travel".

And I used the code that you provide to copy the workbook's named ranges, it's OK. :-D

But it looks like not beautiful in my mind.
e.g.
"wbSource.NamedRanges.Where(nr => nr.Name != "CellHasFormula")) "
And I think this code packaging a extend method maybe look better or deal in the NamedRanges Property . :-D
This is just my own opinion and maybe not better.

Created Unassigned: _themeTint default value must be 0 instead of 1 [9336]

$
0
0
Hi,

In the class XLColor_Internal.cs on line 53, _themeTint is currently initialized with the value 1.
However, the default value should be 0, hence:
___themeTint = 0;__

_themeTint will receive a value between -1 and 1:
"1.0 means 100% lighten. Also, _0.0 means no change_."
http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.tabcolor.aspx


I do see some checks on ThemeTint != 1 throughout the code which I belief are not required if the initialization of _themeTint is fixed.

Created Unassigned: Reading names from name manager [9337]

$
0
0
Hi,

Copyto function is not copying names which are available in the excelsheet.

Is there any way to read/access the names from name manager using closedxml.

Please see the attachment.

Regards,
Manju



New Comment on "Named Ranges"

$
0
0
How can we read names/named ranges from a existing excelsheet/workbook? can anyone help me in this regard?

New Post: How to read names/named ranges from a existing excelsheet/workbook

$
0
0
How can we read names/named ranges from a existing excelsheet/workbook?

can anyone help me in this regard?

Created Unassigned: Cannot change the category from "General" to "Numbers" in format cells while exporting from datatable to Excel [9338]

$
0
0
While exporting from Datatble to excel ..even though the generated spreadsheet contains numbers as right -aligned the category in Format cells is set to "General" and not "Numbers".
I have checked the datatable columns datatype and changed the datatype of cells accordingly.
e.g
if (col.Value == "Int32")
{
cell.DataType = CellValues.Number;
cell.CellValue = new CellValue(rowtext);
}

I formatted the Date cells using custom format by adding stylesheet and setting NumberFromatId and FormatCode. Now in the generated sheet category in Format cells is set to "Custom" and not "General".

Then why doesnt it change for numbers??

Created Unassigned: cell.DataType = cellValues.Date does not work!! Using built-in NumberFormatId=15 displays only the day part of entire date. [9339]

$
0
0
i am trying to export a datatable to excel ..for columns with int datatype changing cell.DataType= cellvalues.Numbers works . but cell.DataType= cellvalues.Date does not work.

Plus using custom formatting and setting NumberFormatId=15 (built in format) displays only the date part of entire date i.e 14-Mar-2014 is displayed as 14.

Commented Unassigned: cell.DataType = cellValues.Date does not work!! Using built-in NumberFormatId=15 displays only the day part of entire date. [9339]

$
0
0
i am trying to export a datatable to excel ..for columns with int datatype changing cell.DataType= cellvalues.Numbers works . but cell.DataType= cellvalues.Date does not work.

Plus using custom formatting and setting NumberFormatId=15 (built in format) displays only the date part of entire date i.e 14-Mar-2014 is displayed as 14.

Comments: pls do reply. cannot find any solution.
Viewing all 1877 articles
Browse latest View live