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

Created Unassigned: IXCell.DataType isn't set DateTime type when the cell contains VLOOKUP formula [8939]

$
0
0
Into a worksheet, a column has VLOOKUP formula to obtain a date from another sheet in the same workbook. But when checking the IXCell.DataType property, I get the Text data type instead of Date data type.

I attach the sample project containing a excel sample file.

Closed Unassigned: IXCell.DataType isn't set DateTime type when the cell contains VLOOKUP formula [8939]

$
0
0
Hi there!

First, thank you for your hard work and ongoing support!

My issue is the following. Into a worksheet, a column has VLOOKUP formula to obtain a date from another sheet in the same workbook. But when checking the IXCell.DataType property, I get the Text data type instead of Date data type.

I'm using ClosedXML 0.68.1

I attach the sample project containing a excel sample file.

Thanks in advanced.
Comments: There's nothing to do. The file does have text values in that column but they're *formatted* as dates. See: http://stackoverflow.com/questions/6151886/generating-openxml-excel-file-doesnt-apply-date-formatting

Created Unassigned: Add QuickStyles [8940]

$
0
0
Allow the use of quick styles.

myStyle is an IXLStyle instance.

wb.QuickStyles.add("My Custom QuickStyle",myStyle) or wb.QuickStyles.add("My Custom QuickStyle")
wb.QuickStyles("My Custom QuickStyle").Style


rng.StyleName="My Custom QuickStyle"




Excel macro code clicking on different quick styles:

```
Selection.Style = "Normal"
Selection.Style = "Bad"
Selection.Style = "Normal"
Selection.Style = "Good"
Selection.Style = "Neutral"
Selection.Style = "Calculation"
Selection.Style = "Heading 2"
Selection.Style = "Accent2"
```

Commented Unassigned: IXCell.DataType isn't set DateTime type when the cell contains VLOOKUP formula [8939]

$
0
0
Hi there!

First, thank you for your hard work and ongoing support!

My issue is the following. Into a worksheet, a column has VLOOKUP formula to obtain a date from another sheet in the same workbook. But when checking the IXCell.DataType property, I get the Text data type instead of Date data type.

I'm using ClosedXML 0.68.1

I attach the sample project containing a excel sample file.

Thanks in advanced.
Comments: ** Comment from web user: george_knight **

MDeLeon,

Thanks you so much!!!

I'll be working to set the proper values in the cells.

A last question. How did you knew that the column has text values?

Regards,

Commented Unassigned: IXCell.DataType isn't set DateTime type when the cell contains VLOOKUP formula [8939]

$
0
0
Hi there!

First, thank you for your hard work and ongoing support!

My issue is the following. Into a worksheet, a column has VLOOKUP formula to obtain a date from another sheet in the same workbook. But when checking the IXCell.DataType property, I get the Text data type instead of Date data type.

I'm using ClosedXML 0.68.1

I attach the sample project containing a excel sample file.

Thanks in advanced.
Comments: ** Comment from web user: MDeLeon **

I debugged the LoadCells method and it showed that the OpenXML file had strings.

Reviewed: ClosedXML 0.68.1 (Aug 09, 2013)

$
0
0
Rated 5 Stars (out of 5) - I'm using it for something really small and simple right now, and this library helped me keep it small and simple. Great stuff!

Source code checked in, #79742

Closed Unassigned: Array Formula crashes ClosedXml on Save [8934]

$
0
0
Hi there!

First, thank you for your hard work and ongoing support! After fiddling with OOXML myself "manually" for about a month and compiling numerous helper functions I really, really appreciate your effort ;-)

Now I've stumbled upon a rather complex array formula that works fine in Excel 2010 but throws a null reference exception on save() using ClosedXml.

In German this array formula looks like
```
=TEILERGEBNIS(9;INDIREKT("B02:B"&MAX(WENN(ISTLEER(#BEZUG!:B);"";ZEILE(B:B)))))
```
and results in
```
System.NullReferenceException: Object reference not set to an instance of an object.
at ClosedXML.Excel.XLWorkbook.GenerateWorksheetPartContent(WorksheetPart worksheetPart, XLWorksheet xlWorksheet, SaveContext context) in ...\ClosedXML\Excel\XLWorkbook_Save.cs:line 4096
at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document) in ...\ClosedXML\ClosedXML\Excel\XLWorkbook_Save.cs:line 189
at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath) in ...\ClosedXML\Excel\XLWorkbook_Save.cs:line 91
at ClosedXML.Excel.XLWorkbook.Save() in ...\ClosedXML\Excel\XLWorkbook.cs:line 413
```
upon save().


Thanks for your help and best regards,
Thomas
Comments: Pick up the latest check-in. It now loads and saves array formulas correctly. Including yours :)

Thanks for the help.

Released: ClosedXML 0.69.0 (Aug 09, 2013)

$
0
0
New on v0.69.0:

Many small fixes.

Created Release: ClosedXML 0.69.0 (Aug 09, 2013)

$
0
0
New on v0.69.0:

Many small fixes.

New Post: 17 MB a WB with only one WS having 29 rows and 11 columns???

$
0
0
The problem is that you're explicitly formatting 1M+ cells (cells which ClosedXML needs to create). You have to either format the entire column or only format the cells used. There are many ways you can do this but here are some examples:
        ws.Column(3).Style.NumberFormat.Format = "$ #,##0.00";

        ws.RangeUsed().Column(3).Style.NumberFormat.Format = "$ #,##0.00";

        ws.Column(3).Column(2, ws.LastRowUsed().RowNumber()).Style.NumberFormat.Format = "$ #,##0.00";

        ws.Range(2, 3, ws.LastRowUsed().RowNumber(), 3).Style.NumberFormat.Format = "$ #,##0.00";

Commented Issue: Adjusting to Content does not work on Windows Azure Websites [8602]

$
0
0
Adjusting column widths based on content fails on Windows Azure Websites because it seems that the functionality provided by [System.Windows.Forms.TextRenderer](http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer.aspx), which is used for measuring string widths, is missing. TextRenderer returns arbitrary output (width > 1,000,000 for the string "hello") instead of real values.

The issue can be resolved by using GDI+ instead of GDI, hence using [System.Drawing.Graphics.MeasureString](http://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurestring.aspx).

The following code snippet demonstrates a rough idea how text measuring using GDI+ could be implemented. Note however that always bold fonts are assumed and that rich text is not handled appropriately.

```
public static void AdjustToContentsGDIPlus(this IXLColumn column)
{
using (var bitmap = new Bitmap(1, 1))
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

var fontCache = new Dictionary<IXLFontBase, Font>();
var width = column.CellsUsed()
.Select(c => new {Font = GetFont(c.Style.Font, fontCache), Value = c.GetFormattedString()})
.Max(c => MeasureText(graphics, c.Value, c.Font));

column.Width = width;
}
}

private static Font GetFont(IXLFontBase fontBase, IDictionary<IXLFontBase, Font> fonts)
{
Font font;

if (!fonts.TryGetValue(fontBase, out font))
{
font = new Font(fontBase.FontName, (float) fontBase.FontSize, FontStyle.Bold);
fonts.Add(fontBase, font);
}

return font;
}

private static double MeasureText(Graphics graphics, string text, Font font)
{
var size = graphics.MeasureString(text, font, Int32.MaxValue, StringFormat.GenericTypographic);

// calculation taken from FontBaseExtensions.GetWidth method
var width = (((size.Width / (double)7) * 256) - (128 / 7)) / 256;
width = (double) Decimal.Round((decimal)width + 0.2M, 2);

return width;
}
```
Comments: ** Comment from web user: mhidinger **

I've also noticed issues with my project when deployed to Azure. Will try and to create a simple repro, but for now it's rendered ClosedXml usage completely useless, since the Excel report makes no sense with those arbitrary width.s

Commented Issue: Adjusting to Content does not work on Windows Azure Websites [8602]

$
0
0
Adjusting column widths based on content fails on Windows Azure Websites because it seems that the functionality provided by [System.Windows.Forms.TextRenderer](http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer.aspx), which is used for measuring string widths, is missing. TextRenderer returns arbitrary output (width > 1,000,000 for the string "hello") instead of real values.

The issue can be resolved by using GDI+ instead of GDI, hence using [System.Drawing.Graphics.MeasureString](http://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurestring.aspx).

The following code snippet demonstrates a rough idea how text measuring using GDI+ could be implemented. Note however that always bold fonts are assumed and that rich text is not handled appropriately.

```
public static void AdjustToContentsGDIPlus(this IXLColumn column)
{
using (var bitmap = new Bitmap(1, 1))
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

var fontCache = new Dictionary<IXLFontBase, Font>();
var width = column.CellsUsed()
.Select(c => new {Font = GetFont(c.Style.Font, fontCache), Value = c.GetFormattedString()})
.Max(c => MeasureText(graphics, c.Value, c.Font));

column.Width = width;
}
}

private static Font GetFont(IXLFontBase fontBase, IDictionary<IXLFontBase, Font> fonts)
{
Font font;

if (!fonts.TryGetValue(fontBase, out font))
{
font = new Font(fontBase.FontName, (float) fontBase.FontSize, FontStyle.Bold);
fonts.Add(fontBase, font);
}

return font;
}

private static double MeasureText(Graphics graphics, string text, Font font)
{
var size = graphics.MeasureString(text, font, Int32.MaxValue, StringFormat.GenericTypographic);

// calculation taken from FontBaseExtensions.GetWidth method
var width = (((size.Width / (double)7) * 256) - (128 / 7)) / 256;
width = (double) Decimal.Round((decimal)width + 0.2M, 2);

return width;
}
```
Comments: ** Comment from web user: MDeLeon **

How about using the GDI as fallback? Please see if you can make a repro project...

New Post: ClosedXML Excel File

$
0
0
I am using ClosedXML dll for exporting the Datatable content to a Excel file using .NET 4.0 . When i open the Excel file after exporting data, 1st row data are displayed with a dropdown menu for sort operation automatically.

How do i remove the dropdown menus from displaying automatically, I dont need them.

New Post: ClosedXML Excel File

$
0
0
worksheet.Tables.First().AutoFilter.Enabled = false;

New Post: ClosedXML Excel File

$
0
0
XLWorkbook wb = new XLWorkbook();
                
                foreach (DataTable dt in ds1.Tables)
                {
                    if (dt.Rows.Count > 0)
                        wb.Worksheets.Add(dt, dt.Rows[0]["TITLE"].ToString());
                }
Im using above code to add worksheet for each datatable in a dataset. I can't able to add the
worksheet..Tables.First().AutoFilter.Enabled = false;

where should i add the line?

Thnx for quick reply.. :)

New Post: ClosedXML Excel File

$
0
0
If i use ShowAutoFilter like this
XLWorkbook wb = new XLWorkbook();
wb.Worksheets.First().Tables.First().ShowAutoFilter = false;
I got the result for first sheet. But for the other sheets i add it shows the dropdown...
Pls help

Commented Unassigned: Evaluating Formulas with Round() [8877]

$
0
0
Hi,

ClosedXML doesn't evaluate formulas with the Round() function.

PS: Is their a list of supported / not supported functions?

Greetings,
Raidri
Comments: ** Comment from web user: Raidri **

I have done some testing and have narrowed down the problem. Attached is the skeleton from my Excel file which calculates some values on sheet 2 and displays the result on sheet 1 (with a letter whose addresses I removed).

The result from sheet 2 (named "Anlage") is in cell C48.
On sheet 1 I have 3 cells which should show that result:
U27 (Formula: "=Anlage!C48")
U28 (Formula: "=ROUND(U27; 2)")
U29 (Formula: "=ROUND(Anlage!C48; 2)")

My program:
```
static void Main(string[] args)
{
XLWorkbook wb = new XLWorkbook(@"c:\temp\test3.xlsx");
IXLWorksheet ws1 = wb.Worksheet(1);
var value1 = ws1.Cell("U27").GetDouble();
var value2 = ws1.Cell("U28").GetDouble();
var value3 = ws1.Cell("U29").GetDouble();
}
```

VS2010 Debugger gives:
ws1.Cell("U27").Value 36718.308000000005 object {double}
ws1.Cell("U28").Value 0.0 object {double}
ws1.Cell("U29").Value 0.0 object {double}

Both formulas with "ROUND" do not give me the right results.
Could you take a look at this and explain it?

PS: I found out some other things before getting to the above step:
- ClosedXML does not like the Dollar sign in cell addresses (like A$10). This error gave the stack trace from my first comment.
- If a formula with a "SUM" includes empty cells, ClosedXML gives an exception, Excel itself treats them as zero and sums up the rest just fine. Could this be included in ClosedXML?

Reopened Unassigned: Evaluating Formulas with Round() [8877]

$
0
0
Hi,

ClosedXML doesn't evaluate formulas with the Round() function.

PS: Is their a list of supported / not supported functions?

Greetings,
Raidri

New Post: Problem reading cell values of cells with formula MTRANS.

$
0
0
Hello,

I got problems with reading cell values from an existing excel file.

Within my Excel sheet the cell "C2" contains the formula "=MTRANS('Technical Data'!D6:IV6)" and the visible value is "Volkswagen". When accessing this cell the property HasFormula is true and I receive the visible value using ValueCached instead of Value which is null for this cell.
The cell "C3" in the next row also contains the formula "=MTRANS('Technical Data'!D6:IV6)" and the visible value is "Volkswagen". When accessing this cell the property HasFormula is now false, ValueCached is null and Value ist empty.

I already read that some formulas are not supported yet. Is there any documention on this topic with information about supported and unsupported topics?
Will the formula MTRANS be supported by ClosedXML soon?

Regards,
Christian
Viewing all 1877 articles
Browse latest View live


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