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

Created Unassigned: ws.PageSetup.Footer.Right.AddText does not work , when read xlsx file. [9441]

$
0
0
```
XLWorkbook wb = new XLWorkbook(templateFullName);
IXLWorksheet ws = wb.Worksheet(1);
ws.PageSetup.Footer.Right.AddText("created:" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));

```
does not work.

```
XLWorkbook wb = new XLWorkbook();
IXLWorksheet ws = wb.Worksheets.Add("Sheet1");
ws.PageSetup.Footer.Right.AddText("created:" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));

```
works well.

Thank you.


New Post: Shared Workbook - notify users that changes occured

$
0
0
Hello,

consider multiple users having the same shared workbook open on their workstations.
I need some automated process to be applyed on this shared workbook.

When i use ClosedXML to update some cells, cells are updated, but users do not get notified by the change, and when someone does any action, the change operated by my ClosedXML action is erased.

The scenario i tested to get it work is that users have to close Excel and reopen the file to get the changes, which is not viable.

Is there a way or something to do to notify other open instances that ClosedXML has made a change ?

Thank you for your help,
Xavier.

New Post: How to expand the Range of a Work Table?

$
0
0
Hi Team,

I have a work table in a worksheet that has items and being used by other worksheet, however the calculations are wrong since I am not able to extend range of the data table. Can somebody shed me some light using closedXML, as my only work around at the moment is use excel interop, Resize like this
var range = xlSheet.get_Range("A1", oMissing).get_Resize(xlListItem.ListRows.Count + 1, xlListItem.ListColumns.Count);
xlListItem.Resize(range);
var workbook = new clsXML.XLWorkbook(localPath);
var worksheet = workbook.Worksheet("Raw Metrics Data");
var worktable = worksheet.Table("MetricsLogging");

Console.WriteLine("Number of items in Excel at START: " + worktable.RowCount());
if (data.Count > 0)
{
       var lastrow = worktable.LastRow().Cell("F").Value; // Created Date
       DateTime lastUpdate = DateTime.Now.AddYears(-2); // Default Value, 2 years before last run
       if (lastrow.ToString().Length > 0)
              lastUpdate = (DateTime)lastrow;
       Console.WriteLine("Last Updated: " + lastUpdate.ToLongDateString());

       var metrics = from m in data where m.CreatedDate > lastUpdate orderby m.CreatedDate ascending select new { m.LogType, m.Category, m.Item, m.UDC, m.CreatedBy.LookupValue, m.CreatedDate, m.VisitingUrl.Url, region = m.CreatedBy.LookupValue.Substring(0, m.CreatedBy.LookupValue.IndexOf("\\")) };
        var tableWithData = worktable.Cell(worktable.RowCount() + 1, 1).InsertData(metrics.AsEnumerable()); // Insert the Data in Worksheet (not in worktable)


         workbook.SaveAs(localPath);

         Console.WriteLine("Number of items in Excel at END: " + worktable.RowCount());
}
Thanks in advance

Regards,
Wendel

New Post: How to expand the Range of a Work Table?

$
0
0
Did a little workaround, but not sure if this is the best practice... anyway.. :) hopefully somebody will make good use of this in the future. :)
var metrics = from m in data where m.CreatedDate > lastUpdate orderby m.CreatedDate ascending select new { m.LogType, m.Category, m.Item, m.UDC, m.CreatedBy.LookupValue, m.CreatedDate, m.VisitingUrl.Url, region = m.CreatedBy.LookupValue.Substring(0, m.CreatedBy.LookupValue.IndexOf("\\")) };
var nextRow = worktable.RowCount() + 1;
Console.WriteLine("Number of items to be added: " + metrics.Count());
if (metrics.Count() != 0)
{
         worktable.InsertRowsBelow(metrics.Count(), true);
         var tableWithData = worktable.Cell(nextRow, 1).InsertData(metrics.AsEnumerable());
         workbook.SaveAs(localPath);
}

New Post: Excel Formatting and worksheet initialization

$
0
0
[Coding Lang : C#]

Question :1
I'm using following code for getting "new line" in a cell and then adjusting rows height to properly display the cell content. Although the new line functionality is working properly but row height is not proper (Only the first line is visible).

IXLWorksheet ws = _Workbook.AddWorksheet("test");
ws.Cell(1,1).FormulaA1 = "=" + "\"New\"" + "&CHAR(10)&" + "\"Line\"";
ws.Style.Alignment.WrapText = true;
ws.Rows().AdjustToContents();

Question :2
As we can initialize a worksheet by a DataTable as follows:
var ws = _Workbook.Worksheets.Add(data_table, "sheet_name");
I need to initialize a worksheet from multiple data_tables (all having different structure) stacked side by side.

Created Unassigned: Using SUMIF results in a "Syntax error." exception [9442]

$
0
0
Using

```
SUMIF(A1:A10,">0")
```

results in a "Syntax error." exception.


Code ends up in the ParseAtom() method with the _token.Type of TKTYPE.COMPARE, which is unsupported at that moment.

Created Unassigned: SetRowsToRepeatAtTop for OpenOffice, LibreOffice [9443]

$
0
0
Document created with using SetRowsToRepeatAtTop function does not repeat rows for OpenOffice or LibreOffice.

Commented Unassigned: SetRowsToRepeatAtTop for OpenOffice, LibreOffice [9443]

$
0
0
Document created with using SetRowsToRepeatAtTop function does not repeat rows for OpenOffice or LibreOffice.
Comments: It looks like that mistake is in this row of inner file (workbook.xml) ``` <x:definedName name="_xlnm.Print_Titles" localSheetId="0">'Export'!1:2</x:definedName> ``` It is enough to change 'Export'!1:2 to 'Export'!$1:$2 and it start working in OO.

New Comment on "How do I deliver an Excel file in ASP.NET?"

$
0
0
Initially, I was not able to get an export to Excel procedure working. I had virtually the same functionality working on a different page, so I was stumped for a while. The problem ended up being trying to execute code from a button located inside an asp:UpdatePanel. I took the button out of the UpdatePanel and it's all working just dandy now.

New Comment on "Inserting and Deleting Rows"

$
0
0
It appears to be a bug, I have the same issue. If you select rows using the IXLRows predicate function and want to delete them, it instead deletes all data in the worksheet. If you use clear however, it removes only the data you have selected and leaves the other rows untouched. Using that, you can iterate over the rows and delete the empty ones, more time costly, but I'm not aware of a better way to do it.

Created Unassigned: Date value as text in excel file [9444]

$
0
0
I am trying to set a text value to one of my columns.
Text value is 2015/06/03 15:15

Below is the code, that I use to set this column

excelWorkSheet.Cell(j + 1, k).SetDataType(XLCellValues.Text);
excelWorkSheet.Cell(j + 1, k)
.Style.NumberFormat.SetNumberFormatId(0);
excelWorkSheet.Cell(j + 1, k).Value = cellValue;

This is converting my string as a number.

How could I show this value as a text(Not as date time or a number)

Commented Issue: WorkBook opening exception [8506]

$
0
0
When I trying to open workbook I catch exception.
Code:
using (var mem = new MemoryStream())
{
mem.Write(document.DocumentByteArray, 0, document.DocumentByteArray.Length);
using (XLWorkbook wb = new XLWorkbook(mem))

System.ArgumentException was unhandled
Message=An item with the same key has already been added.
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at ClosedXML.Excel.XLWorkbook.LoadAutoFilterColumns(AutoFilter af, XLAutoFilter autoFilter)
at ClosedXML.Excel.XLWorkbook.LoadAutoFilter(AutoFilter af, XLWorksheet ws)
at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
at ClosedXML.Excel.XLWorkbook.LoadSheets(Stream stream)
at ClosedXML.Excel.XLWorkbook.Load(Stream stream)
at ClosedXML.Excel.XLWorkbook..ctor(Stream stream, XLEventTracking eventTracking)
at EPAM.USPS.DocumentProcessor.Masha.Parsers.Excel.ExcelParser.Parse(SmlDocument document) in d:\EPM-USPP\epm-uspp11\EPAM.USPS.DocumentProcessor\Masha\Parsers\Excel\ExcelParser.cs:line 77
at EPAM.USPS.DocumentProcessor.Masha.QuestionnaireParserManager.ParseT[T](T document) in d:\EPM-USPP\epm-uspp11\EPAM.USPS.DocumentProcessor\Masha\QuestionnaireParserManager.cs:line 53
at EPAM.USPS.DocumentProcessor.Masha.QuestionnaireParserManager.Parse(OpenXmlPowerToolsDocument document) in d:\EPM-USPP\epm-uspp11\EPAM.USPS.DocumentProcessor\Masha\QuestionnaireParserManager.cs:line 39
at EPAM.USPS.DocumentProcessor.Tests.DocProcessor.ParseWithTemplate() in d:\EPM-USPP\epm-uspp11\EPAM.USPS.DocumentProcessor.Tests\Programcs.cs:line 64
at EPAM.USPS.DocumentProcessor.Tests.Program.Main(String[] args) in d:\EPM-USPP\epm-uspp11\EPAM.USPS.DocumentProcessor.Tests\Programcs.cs:line 25
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Comments: Hi, i have the same issue. Actualy, with the file i'm trying to use, sometimes it works, sometimes not. But i have no idea of the reason. What do you mean by Custom Worksheet ? I noticed that when i change a Celle value from ClosedXML, the new time i want to open triggers this Error. I then open the file in excel and click save; then it works. I attached another file that i try to use, which does not work at all (always have this error on open). Could you tell me if there is something wrong ? Thank you for your help, i'm really strugling with this for a few days

Commented Unassigned: Loading a new workbook fails under mono [9413]

$
0
0
I am unable to do one of the most basic things, open a new workbook under Ubuntu running monodevelop. The following code:
```
XLWorkbook wb = new XLWorkbook("input.xlsx");

```
throws an exception:

```
System.IO.IOException: Operation not valid when package is read-only
at System.IO.Packaging.Package.CheckIsReadOnly () [0x00000] in <filename unknown>:0
at System.IO.Packaging.PackagePart.CreateRelationship (System.Uri targetUri, TargetMode targetMode, System.String relationshipType, System.String id, Boolean loading) [0x00000] in <filename unknown>:0
at System.IO.Packaging.PackagePart.LoadRelationships (System.Collections.Generic.Dictionary`2 relationships, System.IO.Stream stream) [0x00000] in <filename unknown>:0
at System.IO.Packaging.PackagePart.get_Relationships () [0x00000] in <filename unknown>:0
at System.IO.Packaging.PackagePart.GetRelationships () [0x00000] in <filename unknown>:0
at DocumentFormat.OpenXml.Packaging.PackagePartRelationshipPropertyCollection..ctor (System.IO.Packaging.PackagePart packagePart) [0x00000] in <filename unknown>:0
at DocumentFormat.OpenXml.Packaging.OpenXmlPart.Load (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart parent, System.Uri uriTarget, System.String id, System.Collections.Generic.Dictionary`2 loadedParts) [0x00000] in <filename unknown>:0
at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart sourcePart, DocumentFormat.OpenXml.Packaging.RelationshipCollection relationshipCollection, System.Collections.Generic.Dictionary`2 loadedParts) [0x00000] in <filename unknown>:0
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load () [0x00000] in <filename unknown>:0
```

The file has all rwx permissions. Is Linux not supported somehow? Am I making some n00b mistake?

Comments: There is a possible bug in Mono http://lists.ximian.com/pipermail/mono-bugs/2011-February/109577.html In another project there's an issue very similar to ours trying to use the OpenXML 2.5 library calling C# from Javascript through a thing called Edge.js (this is what I'm actually trying to do as well) https://github.com/OfficeDev/Open-XML-SDK/issues/39 I've forked the repo and am experimenting with changing the call to SpreadsheetDocument.Open to use FileAccess.ReadWrite instead of FileAccess.Read.

Commented Unassigned: While Writing to Excel file its throwing an error "'.', hexadecimal value 0x00, is an invalid character." [9421]

$
0
0
Hi All,

While Writing to Excel File using the ClosedXML facing an issue. Above is the error mentioned into caption which I am getting.

Have attached the Excel File which I am trying to Write by passing the DataSet.

Please Reply ASAP.

Thanks,
Samir.
Comments: Pull request opened with potential fix. See https://closedxml.codeplex.com/SourceControl/network/forks/NickNack2020/ClosedXml/contribution/8268

Commented Unassigned: Syntax Error with VLookUp and/or Concatenate [9174]

$
0
0
Hi,

I've been using ClosedXML to read an Excel file (2010 version), and I get an error while reading the content of a cell containing this formula :

In Excel (french version) :
=RECHERCHEV(CONCATENER(D2;"-";F2;"-";H2;"-";I2;"-";J2;"-";K2);Buy!$A:$S;17;0)

In Visual Studio :
?oSht.Cell(idxRow, 12).FormulaA1
"VLOOKUP(CONCATENATE(D2,"-",F2,"-",H2,"-",I2,"-",J2,"-",K2),Buy!$A:$S,17,0)"

When I try to read the cell value, I get an error.

The error returned is this one : "Syntax Error" with no more comments.

The stack trace is :

à ClosedXML.Excel.CalcEngine.CalcEngine.Throw(String msg)
à ClosedXML.Excel.CalcEngine.CalcEngine.Throw()
à ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression)
à ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression)
à ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression)
à ClosedXML.Excel.XLWorksheet.Evaluate(String expression)
à ClosedXML.Excel.XLCell.get_Value()

HResult : -2146233088

Is there a known problem with the VLOOKUP function, or CONCATENATE ?

Thanks in advance for your help

Damien
Comments: I think the problem is we don't currently support localized formulas. Are your formulas the french versions?

Commented Unassigned: Pivot Tables Values Problem [9088]

$
0
0
Based on the example [Pivot Tables](https://closedxml.codeplex.com/wikipage?title=Pivot%20Table%20example) , do the following steps to reproduce the problem

Excellent example . It works perfect, but if you add more than one value will have a problem . Here I leave an example to reproduce the problem . Suppose Pastry class has one more property called "Amount" int

Step 1. Add two values

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

// Another value ( THIS IS THE ONE THAT CAUSE THE PROBLEM )
pt.Values.Add ("Amount" ) ;

```


Step 2. Save the excel file

Step 3. Open the excel file , and throw the following message

We found a problem with Content ' Patry.xlsx ' . Do you want to try to recover as much content as possible ? If trusts origin of this book , please click yes .

Click yes, and I'll get the following message :

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


Step 4. Final result , the pivot table is not generated

aTTACH project C# for reproduce problem.

Please expect your help to solve this problem .. thank you very much
Comments: I have started to do research into this issue, but I am not 100% sure the best way to fix this. The problem is because in Excel as soon as you add more then 1 field to values, Excel generates an automatic "Values Label" We need to generate this field, and update the Pivot Cache. The reason, I am hesitant to do anything at the moment, is because That Field can be moved between the Rows and Columns Categories. I am not super familiar with Excel Pivot Tables, and do not know how this would affect the API. Hopefully my research will help another developer who is more familiar with this part. It should be noted that the values field has a field index value < 0 in my case I observed it was -2. This is how you can tell the values field apart from an regular Pivot Field. See attached screenshot.

Commented 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....
Comments: Can you provide a reproduction case. I can't reproduce this. How are you getting the worksheet? Do you have a handle on correct worksheet. Note: The worksheet position is 1 based. So var x = workbook.Worksheets.Worksheet(2).PivotTables.Count(); will actually return the SECOND worksheet in the workbook. Make sure you getting a handle on the correct worksheet.

New Post: Setting the color of text inside a cell

$
0
0
Is it posible with closedXml to have a cell with different Forecolor.
For example for the text
"January, february, March"
Can I have the whole word "february" in a separate color than the rest.

New Post: XLWorkbook.Save causes spreadsheet to lose data

$
0
0
I have written some code using ClosedXML that should open a spreadsheet, change the range of a table, and save it, and when I debug the methods everything looks great. But when I open the spreadsheet after saving, the contents of several columns have vanished.

Here are two versions of my method I've written:
    private void UpdateTableRange(string filePath)
    {
        var spreadsheet = new XLWorkbook(filePath);
        var worksheet = spreadsheet.Worksheets.FirstOrDefault(s => s.Name == "Usage");

        var range = worksheet.Range(worksheet.FirstCell(), worksheet.LastCellUsed());
        worksheet.Tables.Remove("Usage");
        var table = range.AsTable("Usage");
        worksheet.Tables.Add(table);

        spreadsheet.Save();
    }

    private byte[] UpdateTableRange(byte[] file)
    {
        var stream = new MemoryStream();
        stream.Write(file, 0, file.Length);
        var spreadsheet = new XLWorkbook(stream);
        var worksheet = spreadsheet.Worksheets.FirstOrDefault(s => s.Name == "Usage");

        var range = worksheet.Range(worksheet.FirstCell(), worksheet.LastCellUsed());
        worksheet.Tables.Remove("Usage");
        var table = range.AsTable("Usage");
        worksheet.Tables.Add(table);

        spreadsheet.Save();

        return stream.ToArray();
    }
I thought that perhaps I was messing up the data by removing the table and adding a new one, but if I do nothing more than open the workbook and save it, having first made no changes, whatosever, I still lose the contents of some of the columns.

Can anybody think of a reason this might be happening? Is there some way data might be defined in a worksheet such that opening the spreadsheet in ClosedXML and saving it, without making changes, could nevertheless cause the contents of some columns to disappear? If it helps, the columns whose content vanishes are all non-numeric: dates, strings, etc.

New Post: XLWorkbook.Save causes spreadsheet to lose data

$
0
0
It looks like immediately after opening the spreadsheet using new XLWorkbook(...), the data in the original hasn't been loaded into memory:

(new System.Linq.SystemCore_EnumerableDebugView<ClosedXML.Excel.IXLWorksheet>(((ClosedXML.Excel.XLWorksheets)(spreadsheet.Worksheets)))).Items[10].Cell(2,1).Value

The above code returns an empty string, even though the original worksheet has a user's name in that cell. And so when I save the XLWorkbook, naturally the empty value gets saved resulting in the data loss about which I'm complaining.

Interestingly, ...Cell(1,1).Value returns "UserName" which is correct--it's the value of the cell serving as the column header.
Viewing all 1877 articles
Browse latest View live


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