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

Commented Unassigned: After inserting a row in a table, the files grows very big [9461]

$
0
0
I have an excel file that has a table with range A:K and has few rows say 100. So the cells with A1..K100 has values. But the same sheet has values at some random cells like Q6000. The file was of 47KB. Now I do

```
var excelTable = wb.Worksheets.First().Tables.FirstOrDefault(t => string.Equals("Table", t.Name, StringComparison.Ordinal));
var row = excelTable.DataRange.InsertRowsBelow(1).First();
```
The excel file after the insertion grew to 270KB. When checked, I saw new cells added all through A101..Q6001 in the sheet.xml which is incorrect. Also, when we insert one row, all the cells below the new row gets pushed down by one row. Here only the cell columns that are part of table are considered which is incorrect. It should consider the MaxColumnUsed.

There are two issues
1. XLRangeAddress.InsertRowsAboveInternal() should not add new cells for old cells that are not present in the internal worksheet.
2. XLRangeAddress.InsertRowsAboveInternal() should use MaxColumnUsed when it is pushing the cell values down by number of rows being inserted.

The issue 1 is affecting the performance because saving big files to stream takes lot of time.
The issue 2 causes inconsistency after insertion
Comments: A small correction please. Both issues exist in __XLRangeBase.InsertRowsAboveInternal()__

Commented Unassigned: Worksheet.PivotTables is always empty [9378]

$
0
0
My .xlsx file contains a Pivot Table. But I can't get access to it via `Worksheet.PivotTables` property.

This is my sample code:

```
using (var excel = new XLWorkbook(sourceFile, XLEventTracking.Enabled))
{
var pivots = excel.Worksheets.SelectMany(ws => ws.PivotTables).ToList();
// pivots.Count == 0
}

```
The version of the ClosedXML library is 0.75.0 (got from NuGet)

The example of .xml file is attached.


Comments: I just noticed the same problem, I cannot load any pivot table that exists in a worksheet. Only adding a new PivotNable via the library seems to populate the PivotTables property. I guess it is impossibile at the moment to modify a pviot table that already exists in the Excel file. :(

Commented Unassigned: Worksheet.PivotTables is always empty [9378]

$
0
0
My .xlsx file contains a Pivot Table. But I can't get access to it via `Worksheet.PivotTables` property.

This is my sample code:

```
using (var excel = new XLWorkbook(sourceFile, XLEventTracking.Enabled))
{
var pivots = excel.Worksheets.SelectMany(ws => ws.PivotTables).ToList();
// pivots.Count == 0
}

```
The version of the ClosedXML library is 0.75.0 (got from NuGet)

The example of .xml file is attached.


Comments: (I'm using version 0.76 from Nuget but no change in this bug)

Created Unassigned: VTFileTime custom properties incorrectly set as unspecified kind at load [9462]

$
0
0
XLWorkbook_Load.cs, LoadSpreadsheetDocument, the section which loads date time values, uses:

DateTime.ParseExact(m.VTFileTime.Text, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture);

Which sets the DateTimeKind to Unspecified, which if saved again, is converted to UTC, changing the file time property each time the document is loaded and saved. This line should be:

DateTime.ParseExact(m.VTFileTime.Text, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);

to set the Kind to UTC.

Also, the unit test example class WorkbookProperties is incorrectly coded and does not match the example file, it should be setting the date value to

new DateTime(2011, 1, 2, 0, 0, 0, DateTimeKind.Utc)

, not:

new DateTime(2011, 1, 1, 17, 0, 0, DateTimeKind.Utc)

New Post: Pivot Table creation results in Corrupt Spreadsheet

Created Unassigned: Formula with NamedRange not working [9463]

$
0
0
I created named range for cel A1 with name "TEST.CELL" and in cel B1 created formula "=TEST.CELL*10"
it works in excel but when i try to read value from B1 i get

Exception {"Syntax error."}
at ClosedXML.Excel.CalcEngine.CalcEngine.Throw(String msg)
at ClosedXML.Excel.CalcEngine.CalcEngine.Throw()
at ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression)
at ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression)
at ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression)
at ClosedXML.Excel.XLWorksheet.Evaluate(String expression)
at ClosedXML.Excel.XLCell.get_Value()

If name is "TEST_CELL" it works, can this problem with "." be fixed.

__EXAMPLE__
var tWb = new XLWorkbook(tFile);
IXLWorksheet tWorksheet1;
tWb.Worksheets.TryGetWorksheet("Sheet1", out tWorksheet1);

tWorksheet1.Cell("A1").SetValue(1);
//var r1 = tWorksheet1.Cell("TEST.CELL").Value;
var r = tWorksheet1.Cell("B1").Value;

Thanks

Commented Unassigned: ClosedXML does not preserve style [9454]

$
0
0
So this is my code

```
using (var document = new XLWorkbook(root + outFolder + copied))
{
var sheet = document.Worksheets.First();
var allRows = sheet.Rows();
foreach (var currentRow in allRows)
{
var allCells = currentRow.Cells();
foreach (var cell in allCells)
{
var cVal = cell.Value.ToString();
if (dict.ContainsKey(cVal))
{
cell.Value = dict[cVal];
}
}
}
document.SaveAs(root + outFolder + copied);
}
```

This is how the Excel file looked before editing with ClosedXML: http://i.imgur.com/jjBWsUJ.png

This is how it looks after: http://i.imgur.com/qH8DrhO.png

As you can see, there are a bunch of styles it isn't saving. OpenXML does not do this.
Comments: Unfortunately I only have the correct one. Maybe you can tinker with it and remove the blueprint. (attached)

New Post: Removed part: /xl/calcChain.xml part with XML error

$
0
0
Hello,

I am using ClosedXML 0.76 in VB with VS2010, to generate a excel 1000 columns by 3000 rows

I get the following error: Removed part: /xl/calcChain.xml part with XML error. (Properties calculation) Catastrophic failure Line 1, column 121.

But I'm not using any formula, if I take the same data separately the error does not happen. The cell where I get the error contains simple text. Anyone can have an idea of what may be happening?

Thanks in advance

New Comment on "Using Rich Text"

$
0
0
Here's a function we wrote to convert a Cell with RichText or a hyperlink to HTML: public static string RichTextToHTML(IXLCell cell) { StringBuilder myString = new StringBuilder(); // Special case when the whole cell has a link vs. a http:// string in one of the rich text parts below in the loop if (cell.HasHyperlink && cell.Hyperlink.IsExternal) myString.Append("<a href='" + cell.Hyperlink.ExternalAddress + "'>"); foreach (var richText in cell.RichText) { myString.Append("<span style='"); // Start SPAN and CSS here then add to it below if (richText.Bold) myString.Append("font-weight: bold;"); if (richText.Strikethrough) myString.Append("text-decoration:line-through;"); if (richText.Italic) myString.Append("font-style: italic;"); if (richText.Underline == XLFontUnderlineValues.Single) myString.Append("text-decoration: underline;"); if (richText.FontName != "Arial") myString.Append("font-face: " + richText.FontName + ";"); if (richText.FontColor.Color.IsKnownColor) myString.Append("color: " + richText.FontColor.Color.Name + ";"); if (richText.FontSize != 10) myString.Append("font-size: " + richText.FontSize + ";"); myString.Append("'>"); // End the SPAN if (richText.Text.Contains("http")) myString.Append("<a href='" + richText.Text + "'>"); myString.Append(richText.Text.Replace("\r\n", "<br>")); if (richText.Text.Contains("http")) myString.Append("</a>"); myString.Append("</span>"); } if (cell.HasHyperlink && cell.Hyperlink.IsExternal) myString.Append("</a>"); return myString.ToString(); }

New Post: Convert range to table, treat all rows as data rows

$
0
0
Below is the code we use to convert a Range to a DataTable.
We had an issue with certain dateformats being the Julian # of days since 1/1/1900 so this tries to convert those. This also converts RichText to HTML:
public static DataTable RangeToDataTable(IXLRange range, bool firstLineHeadings = true)
{
    if (range.IsMerged())
    {
        range = range.Unmerge(); // Unmerge any merged cells
    }

    DataTable dt = new DataTable();
    // First just do headers (1st row in Range)
    int columnCnt = range.ColumnCount();
    for (int k = 1; k <= columnCnt; k++)
    {
        var name  = range.Row(1).Cell(k).Address.ColumnLetter;
        if (firstLineHeadings) name = range.Row(1).Cell(k).GetString();
        dt.Columns.Add(name);
    }

    bool firstRow = true;
    foreach (var myrow in range.RowsUsed()) // RowsUsed seems to also make merged called all report the same value (which we want)
    {
        if (firstRow && firstLineHeadings) { firstRow = false; continue; }
        if (myrow.IsEmpty()) continue;
        DataRow workRow = dt.NewRow();
        for (int j = 1; j <= columnCnt; j++)
        {
            IXLCell cellObj = myrow.Cell(j); // not 0 based
            var cellValue = cellObj.Value;
            var checkForDate = cellObj.GetFormattedString();
            if (checkForDate.Contains("-yy") && checkForDate.Contains("[$-"))
                cellValue = FromExcelSerialDate(cellValue);
            else
            {
                if (cellObj.HasHyperlink && cellObj.Hyperlink.IsExternal) cellValue = "<a href='" + cellObj.Hyperlink.ExternalAddress + "'>" + cellObj.Value + "</a>";
                if (cellObj.HasRichText) cellValue = RichTextToHTML(cellObj); // If the link is formatted this overwrites with the prettier link
            }
            workRow[j - 1] = cellValue; // 0 based in DataRow object for [] indexing
        }
        dt.Rows.Add(workRow);
    }
    return dt;
}

public static DateTime FromExcelSerialDate(object serialDate)
{
    int excelNumber = int.Parse(serialDate.ToString());
    if (excelNumber > 59) excelNumber -= 1; //Excel/Lotus 2/29/1900 bug   
    return new DateTime(1899, 12, 31).AddDays(excelNumber);
}

public static string RichTextToHTML(IXLCell cell)
{
    StringBuilder myString = new StringBuilder();
    // Special case when the whole cell has a link vs. a http:// string in one of the rich text parts below in the loop
    if (cell.HasHyperlink && cell.Hyperlink.IsExternal) myString.Append("<a href='" + cell.Hyperlink.ExternalAddress + "'>");
    foreach (var richText in cell.RichText)
    {
        myString.Append("<span style='"); // Start SPAN and CSS here then add to it below

        if (richText.Bold) myString.Append("font-weight: bold;");
        if (richText.Strikethrough) myString.Append("text-decoration:line-through;");
        if (richText.Italic) myString.Append("font-style: italic;");
        if (richText.Underline == XLFontUnderlineValues.Single) myString.Append("text-decoration: underline;");
        if (richText.FontName != "Arial") myString.Append("font-face: " + richText.FontName + ";");
        if (richText.FontColor.Color.IsKnownColor) myString.Append("color: " + richText.FontColor.Color.Name + ";");
        if (richText.FontSize != 10) myString.Append("font-size: " + richText.FontSize + ";");
        myString.Append("'>"); // End the SPAN
        if (richText.Text.Contains("http")) myString.Append("<a href='" + richText.Text + "'>");

        myString.Append(richText.Text.Replace("\r\n", "<br>"));
        if (richText.Text.Contains("http")) myString.Append("</a>");
        myString.Append("</span>");
    }
    if (cell.HasHyperlink && cell.Hyperlink.IsExternal) myString.Append("</a>");
    return myString.ToString();
}

Created Unassigned: Formula ISNUMBER [9464]

$
0
0
Please can you add to formulas ISNUMBER()
Thanks

New Comment on "Conditional Formatting"

$
0
0
Is it possible change color in databar features? (solid fill instead)

New Comment on "Adding an AutoFilter to a Range"

$
0
0
Hi guys, Some oddness. When I use auto filter on an ClosedXML created workbook, then open that file in excel and start using the filter it is super slow, and says "x of 1048575 records found" where x is the row count of the filter, even though there's only 30 rows worth of data. Any tips to overcome this shortfall? Cheers,

New Post: Checkbox form control in Excel

$
0
0
Hello,

I have a few Excel files that contains checkbox forms controls (from Developer ribbon menu).

Unfortunately by using CopyTo() method those checkboxes aren't copied to new worksheet. Do any of you guys have any idea how to fix this issue?

New Post: VerticalPageBreak not working

$
0
0
Hi all, im trying to set Vertical Page Break, using PageSetup.AddVerticalPageBreak, Columns(colBreak,colBreak).AddVerticalPageBreaks() without results, is an issue or im doing something wrong?
Thanks!
(sorry for my bad english)

Reviewed: ClosedXML 0.76.0 (Nov 12, 2015)

$
0
0
Rated 5 Stars (out of 5) - Excellent Library! Super! I can't tell you how grateful I am for this perfect library.

New Comment on "Adding DataTable as Worksheet"

$
0
0
How do I remove the blue background on the header row? I've tried clearing the formats, setting the background to transparent, etc, but I can't get it change to black text on white background without manually doing it in Excel.

New Post: HTML inside cell

$
0
0
Hello!
I am exporting some data into excel, and one of my fields accepts HTML, and when I export it I see it like this:
<div class="someClass"><p><strong>Some Text<strong></p><p>Some Other Text</p></div>
Is there any way I can convert it to rich text and for example see a <p> like a paragraph and the <strong> like bold?
Or just see the plain text with no formatting?


Thank you!

New Comment on "Showcase"

$
0
0
This gives the output with the AutoFilter functionality. How to remove this default functionality? in the given example above is also showing the autofilter mode is enabled. I tried with the below code, but it didn't worked out: ws.AutoFilter.Enabled = false; Please help..

Reviewed: ClosedXML 0.76.0 (Nov 25, 2015)

$
0
0
Rated 5 Stars (out of 5) - It is a real joy to be able to interact with Excel server-side using such an intuitive API. It could not be easier!
Viewing all 1877 articles
Browse latest View live


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