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

Reviewed: ClosedXML 0.76.0 (Aug 03, 2016)

$
0
0
Rated 5 Stars (out of 5) - Super easy to use :)

Commented Unassigned: Datetime is 1 day off [9497]

$
0
0
Greetings,

I'm trying to write a datetime to a cell using ClosedXML. I set the IXLCell DataType to be XLCellValues.DateTime, and the value to be a new DateTime. I also set the number format id to 14 (mm/dd/yyyy)

When I look at the excel sheet, the date displayed is always one day larger than anticipated. When I read the cell value using ClosedXML (in a unit test), the value read from the file matches the value I wrote, but the actual excel sheet does not show the correct value.

Is this a bug in ClosedXML or am I missing something?

Thanks!
-Adam
Comments: I found the issue. https://msdn.microsoft.com/en-us/library/system.datetime.tooadate(v=vs.110).aspx ToOADate stores dates as days since 30 december 1899, but excel stores them as days since 31 december 1899. Therefore, we need to subtract 1 from the ToOADate value when writing to an excel file, and add 1 to the value when reading from the file.

New Post: How to get just cell value?

$
0
0
I want to get just cell value.

nothing anymore just get value?

How do i get?

and How to validation formula?

Thank you

New Post: Styles

$
0
0
Something wrong is happening

I create a range and procedure to set styles for it.
Something like this xlsRange.Style=SetStyle(xlsRange.Style, ws["Style"].ToString());
No styles were set. In debug window, I see following:
....
lStyle.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
but in local variables window still
lStyle
  Alignment
   ....
     Horzontal       General
What I'm doing wrong&

New Post: Filter on Text Color

$
0
0
Hi,

It's been a while since I had a question, but this may be something others could use. I have some PDFs converted to Excel workbooks. Some of the text is in red or yellow to indicate a change from the last version. Is it possible to use ClosedXML to set an AutoFilter, to filter on just those rows? I have done this manually, but I don't see examples where filtering is set on Font Color using ClosedXML. Is there any way to determine if a font color (red) occurs in a range, or on a sheet? Is it possible to set a custom auto filter and apply it to the column to see if there are any matching rows?

Thanks.

Steve

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

$
0
0
Hi,I am using the above code which is working perfectly fine. But not able to remove the default styles using below lines ws.Rows().Style.Border.BottomBorderColor = XLColor.NoColor; ws.Rows().Style.Border.TopBorderColor = XLColor.NoColor; Please help me on the same.

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

$
0
0
Hi,I am using the above code which is working perfectly fine. But not able to remove the default styles using below lines ws.Rows().Style.Border.BottomBorderColor = XLColor.NoColor; ws.Rows().Style.Border.TopBorderColor = XLColor.NoColor; Please help me on the same. I am using Datatable to add data to worksheet.

New Comment on "Adding DataTable as Worksheet"

$
0
0
Hello guys,I am facing same problem not able to remove the blue background and the border. Tried using below lines ws.Rows().Style.Border.BottomBorderColor = XLColor.NoColor; ws.Rows().Style.Border.TopBorderColor = XLColor.NoColor; but of no use. Please help me on the same if u all have found some altenative. Thank You.

New Post: Filter on Text Color

$
0
0
Also, I have this working:
        if (row.Cell(2).Style.Font.FontColor == XLColor.Red)
        {
            //do some stuff
        }
However, some of the text is black, and part of it is red- that does not seem to get matched. AutoFilter on Text Color will pick up partial matching in a cell; I just need to have a ClosedXML way to do it.

Thanks

Created Unassigned: Error doing data validation from another sheet [9498]

$
0
0
When using closedxml to add data validation to a file, all validations are written in the <x:dataValidations> element. However, this is not how excel saves data validation from other sheets.

Here's how closed xml saves it:

```
<x:dataValidations count="3">
<x:dataValidation type="list" errorStyle="warning" operator="between" allowBlank="0" showDropDown="0" showInputMessage="1" showErrorMessage="1" errorTitle="" error="" promptTitle="" prompt="" sqref="B6:B6">
<x:formula1>"Foo,Bar,FooBar"</x:formula1>
<x:formula2></x:formula2>
</x:dataValidation>
<x:dataValidation type="list" errorStyle="warning" operator="between" allowBlank="0" showDropDown="0" showInputMessage="1" showErrorMessage="1" errorTitle="" error="" promptTitle="" prompt="" sqref="C6:C6">
<x:formula1>'HiddenDataValSheet'!$A$1:$A$1000</x:formula1>
<x:formula2></x:formula2>
</x:dataValidation>
<x:dataValidation type="list" errorStyle="warning" operator="between" allowBlank="0" showDropDown="0" showInputMessage="1" showErrorMessage="1" errorTitle="" error="" promptTitle="" prompt="" sqref="D6:D6">
<x:formula1>'HiddenDataValSheet'!$B$1:$B$1000</x:formula1>
<x:formula2></x:formula2>
</x:dataValidation>
</x:dataValidations>

```

And here's how excel saves it:

```
<extLst>
<ext uri="{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main">
<x14:dataValidations count="2" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">
<x14:dataValidation type="list" errorStyle="warning" showInputMessage="1" showErrorMessage="1">
<x14:formula1>
<xm:f>HiddenDataValSheet!$A$1:$A$1000</xm:f>
</x14:formula1>
<xm:sqref>C6</xm:sqref>
</x14:dataValidation>
<x14:dataValidation type="list" errorStyle="warning" showInputMessage="1" showErrorMessage="1">
<x14:formula1>
<xm:f>HiddenDataValSheet!$B$1:$B$1000</xm:f>
</x14:formula1>
<xm:sqref>D6</xm:sqref>
</x14:dataValidation>
</x14:dataValidations>
</ext>

```

I'll need to modify the closed xml code to be able to read the data validations from the <extLst> element and treat them like normal data validations.

Commented Unassigned: Error doing data validation from another sheet [9498]

$
0
0
When using closedxml to add data validation to a file, all validations are written in the <x:dataValidations> element. However, this is not how excel saves data validation from other sheets.

Here's how closed xml saves it:

```
<x:dataValidations count="3">
<x:dataValidation type="list" errorStyle="warning" operator="between" allowBlank="0" showDropDown="0" showInputMessage="1" showErrorMessage="1" errorTitle="" error="" promptTitle="" prompt="" sqref="B6:B6">
<x:formula1>"Foo,Bar,FooBar"</x:formula1>
<x:formula2></x:formula2>
</x:dataValidation>
<x:dataValidation type="list" errorStyle="warning" operator="between" allowBlank="0" showDropDown="0" showInputMessage="1" showErrorMessage="1" errorTitle="" error="" promptTitle="" prompt="" sqref="C6:C6">
<x:formula1>'HiddenDataValSheet'!$A$1:$A$1000</x:formula1>
<x:formula2></x:formula2>
</x:dataValidation>
<x:dataValidation type="list" errorStyle="warning" operator="between" allowBlank="0" showDropDown="0" showInputMessage="1" showErrorMessage="1" errorTitle="" error="" promptTitle="" prompt="" sqref="D6:D6">
<x:formula1>'HiddenDataValSheet'!$B$1:$B$1000</x:formula1>
<x:formula2></x:formula2>
</x:dataValidation>
</x:dataValidations>

```

And here's how excel saves it:

```
<extLst>
<ext uri="{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main">
<x14:dataValidations count="2" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">
<x14:dataValidation type="list" errorStyle="warning" showInputMessage="1" showErrorMessage="1">
<x14:formula1>
<xm:f>HiddenDataValSheet!$A$1:$A$1000</xm:f>
</x14:formula1>
<xm:sqref>C6</xm:sqref>
</x14:dataValidation>
<x14:dataValidation type="list" errorStyle="warning" showInputMessage="1" showErrorMessage="1">
<x14:formula1>
<xm:f>HiddenDataValSheet!$B$1:$B$1000</xm:f>
</x14:formula1>
<xm:sqref>D6</xm:sqref>
</x14:dataValidation>
</x14:dataValidations>
</ext>

```

I'll need to modify the closed xml code to be able to read the data validations from the <extLst> element and treat them like normal data validations.
Comments: It turns out that the XLWorkBook_Load.cs completely ignores the WorksheetExtensions node, which is the cause of this bug. The fix is to add the following on line 172: if (reader.ElementType == typeof (WorksheetExtensionList)) LoadWorksheetExtensions((WorksheetExtensionList)reader.LoadCurrentElement(), ws); Then implement the LoadWorksheetExtensions function, which I'm working on now.

Commented Unassigned: Error doing data validation from another sheet [9498]

$
0
0
When using closedxml to add data validation to a file, all validations are written in the <x:dataValidations> element. However, this is not how excel saves data validation from other sheets.

Here's how closed xml saves it:

```
<x:dataValidations count="3">
<x:dataValidation type="list" errorStyle="warning" operator="between" allowBlank="0" showDropDown="0" showInputMessage="1" showErrorMessage="1" errorTitle="" error="" promptTitle="" prompt="" sqref="B6:B6">
<x:formula1>"Foo,Bar,FooBar"</x:formula1>
<x:formula2></x:formula2>
</x:dataValidation>
<x:dataValidation type="list" errorStyle="warning" operator="between" allowBlank="0" showDropDown="0" showInputMessage="1" showErrorMessage="1" errorTitle="" error="" promptTitle="" prompt="" sqref="C6:C6">
<x:formula1>'HiddenDataValSheet'!$A$1:$A$1000</x:formula1>
<x:formula2></x:formula2>
</x:dataValidation>
<x:dataValidation type="list" errorStyle="warning" operator="between" allowBlank="0" showDropDown="0" showInputMessage="1" showErrorMessage="1" errorTitle="" error="" promptTitle="" prompt="" sqref="D6:D6">
<x:formula1>'HiddenDataValSheet'!$B$1:$B$1000</x:formula1>
<x:formula2></x:formula2>
</x:dataValidation>
</x:dataValidations>

```

And here's how excel saves it:

```
<extLst>
<ext uri="{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main">
<x14:dataValidations count="2" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">
<x14:dataValidation type="list" errorStyle="warning" showInputMessage="1" showErrorMessage="1">
<x14:formula1>
<xm:f>HiddenDataValSheet!$A$1:$A$1000</xm:f>
</x14:formula1>
<xm:sqref>C6</xm:sqref>
</x14:dataValidation>
<x14:dataValidation type="list" errorStyle="warning" showInputMessage="1" showErrorMessage="1">
<x14:formula1>
<xm:f>HiddenDataValSheet!$B$1:$B$1000</xm:f>
</x14:formula1>
<xm:sqref>D6</xm:sqref>
</x14:dataValidation>
</x14:dataValidations>
</ext>

```

I'll need to modify the closed xml code to be able to read the data validations from the <extLst> element and treat them like normal data validations.
Comments: I got this working. Here's the code I added: ``` private static void LoadWorksheetExtensions(WorksheetExtensionList extensions, XLWorksheet ws) { if (extensions == null) return; // get each extension element foreach (WorksheetExtension we in extensions.Elements<WorksheetExtension>()) { // get data validations element var dataValidationList = we.Elements<DocumentFormat.OpenXml.Office2010.Excel.DataValidations>().ToList(); foreach (var dataValidations in dataValidationList) { LoadWorksheetExtensionDataValidations(dataValidations, ws); } } } ``` ``` private static void LoadWorksheetExtensionDataValidations( DocumentFormat.OpenXml.Office2010.Excel.DataValidations dataValidations, XLWorksheet ws) { if (dataValidations == null) return; // get each datavalidation element foreach (DocumentFormat.OpenXml.Office2010.Excel.DataValidation dv in dataValidations.Elements<DocumentFormat.OpenXml.Office2010.Excel.DataValidation>()) { // get the data validation object we want to modify based on the cell reference var txt = dv.ReferenceSequence.InnerText; if (XLHelper.IsNullOrWhiteSpace(txt)) continue; foreach (var dvt in txt.Split(' ').Select(rangeAddress => ws.Range(rangeAddress).DataValidation)) { if (dv.AllowBlank != null) dvt.IgnoreBlanks = dv.AllowBlank; if (dv.ShowDropDown != null) dvt.InCellDropdown = !dv.ShowDropDown.Value; if (dv.ShowErrorMessage != null) dvt.ShowErrorMessage = dv.ShowErrorMessage; if (dv.ShowInputMessage != null) dvt.ShowInputMessage = dv.ShowInputMessage; if (dv.PromptTitle != null) dvt.InputTitle = dv.PromptTitle; if (dv.Prompt != null) dvt.InputMessage = dv.Prompt; if (dv.ErrorTitle != null) dvt.ErrorTitle = dv.ErrorTitle; if (dv.Error != null) dvt.ErrorMessage = dv.Error; if (dv.ErrorStyle != null) dvt.ErrorStyle = dv.ErrorStyle.Value.ToClosedXml(); if (dv.Type != null) dvt.AllowedValues = dv.Type.Value.ToClosedXml(); if (dv.Operator != null) dvt.Operator = dv.Operator.Value.ToClosedXml(); if (dv.DataValidationForumla1 != null) dvt.MinValue = dv.DataValidationForumla1.InnerText; if (dv.DataValidationForumla2 != null) dvt.MaxValue = dv.DataValidationForumla2.InnerText; } } } ```

Commented Unassigned: Cell formating - missing [8876]

$
0
0
I'm using Closed XML (0.68.1) to read Template document and then to generate new documents from template, but problem is that formatting of cells (Border, colors, ...) is lost after first cycle.
Below my test code

for (int i = 0; i < 4; i++) {
byte[] tTemplate = File.ReadAllBytes("MyTemplate.xlsx");
var workbook = new XLWorkbook(new MemoryStream(tTemplate));

MemoryStream tOut = new MemoryStream();
workbook.SaveAs(tOut);
byte[] tOutData = tOut.ToArray();

string tOutDoc = string.Format("Ret_{0}.xlsx", DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss_fff"));
FileStream tFile = File.Create(tOutDoc);
tFile.Write(tActual, 0, tActual.Length);
tFile.Close();
}

Thanks
Comments: Having the same problem here, on a smaller scale. Blank rows with nothing but the fill set are losing their fill.

New Post: Detecting Hidden Rows / Columns / Cells

$
0
0
I've been given the task of importing several Excel files on a regular basis and everyone of them has hidden rows that need to be ignored.

Everything is working perfectly except that ClosedXML always returns the hidden rows too.

How do I detect hidden rows (or columns / cells) so I can avoid them ?

New Post: How to Select data from excel using column header in closedXML

$
0
0
Iam using this code for retrieve data from worksheet but i not able filter with column header in this
 var workbook = new XLWorkbook(filePath);
  IXLWorksheet ws1 = workbook.Worksheet(1);
 foreach (IXLRow row in ws1.Rows())
        {
            //Use the first row to add columns to DataTable.
            if (isRequiredHeader)
            {
                foreach (IXLCell cell in row.Cells())
                {
                    dt.Columns.Add(cell.Value.ToString());
                }
                isRequiredHeader = false;
            }
            else
            {
                //Add rows to DataTable.
                dt.Rows.Add();
                int i = 0;
                foreach (IXLCell cell in row.Cells())
                {
                    dt.Rows[dt.Rows.Count - 1][i] = cell.Value.ToString();
                    i++;
                }
            }
        }

It will return full columns, but i need only 2 and 4 th column data having name 'mobile' and 'pincode' how to get whole data for those two columns

Created Unassigned: Table Theme [9499]

$
0
0
Attached is an excel file with a custom Table Style. The loading of the table theme borks because enum.parse can't find a value. Recommend changing the theme to a string and using enum.tryparse. Have a helper that lets you get standard excel themes but still allows custom theme names.

New Comment on "Inserting Tables"

$
0
0
That would be a Select. your Ienumerable.select(x=> new Object[]{x.field1,x.Field2})

Commented Unassigned: Table Theme [9499]

$
0
0
Attached is an excel file with a custom Table Style. The loading of the table theme borks because enum.parse can't find a value. Recommend changing the theme to a string and using enum.tryparse. Have a helper that lets you get standard excel themes but still allows custom theme names.
Comments: [pull request](https://closedxml.codeplex.com/SourceControl/network/forks/vbjay/ClosedXML/contribution/8939)

New Post: Read vale from checkbox from excel sheet

$
0
0
Hello,
can someone tell me how I can read value from checkbox?? example in cell E50 I have checkbox control and this is checked and I want read/check this value and get something like true or false.. for right now I have null...

Example code
var instExcel = new XLWorkbook(file);
var sheet = instExcel.Worksheet("Ark1");
var cell = sheet.Cell("E50");
// or
var cell2 = sheet.Cell("E50").Value;

New Comment on "Named Ranges"

$
0
0
@manjunathg88 Try wb.NamedRanges.Count()
Viewing all 1877 articles
Browse latest View live


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