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

New Post: How do I get formatted cell values, according to the excel cell format definitions?

$
0
0
Hello,
I have problems reading formatted cell values from an existing excel file.

In my excel sheet I have cells formatted for numbers with "Decimal places: 1".
In a certain cell the visible value is "0,1". When I read the cell value I receive "0.10000000000000009".
I checked the Style property (of XLCell) and found several format settings (e.g. for Border or Font) I could also find in the excel file. But taking a look at Style.NumberFormat.Format I only see "0.0".
I need to get the formatted values from the excel file because I must create a xml file containing exactly the original "visible" cell values! I also need to get the same decimal marker. In my case a comma instead of the point!
Is there any way to achieve this? I also tried with GetFormattedString but there was no difference.

Regards,
Christian

New Post: Columns().AdjustToContents leaving extra padding

$
0
0
I'm adjusting a series of columns and rows. It is working and I can see that the columns widths have been adjusted. However, they are not adjusting to the same width as it would if I were to manually select all the columns and rows and select Format > AutoFit Column Width. It almost seems that its adding some padding or allowing for some padding in the Columns().AdjustToContents logic (see attached image for an example). Is there another setting that needs to be applied or am I using ws.Columns().AdjustToContents(startRow, endRow) incorrectly?
Image

Source code checked in, #79749

$
0
0
Fixed issue with numbers reported as text

Released: ClosedXML 0.69.1 (Aug 14, 2013)

$
0
0
New on v0.69.1:

Many small fixes.

Created Release: ClosedXML 0.69.1 (Aug 14, 2013)

$
0
0
New on v0.69.1:

Many small fixes.

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

__See my comment for new description of the problem.__
Comments: ** Comment from web user: MDeLeon **

Pick up the latest version and let me know if you're still having problems. Note that Excel formula parameters are separated by commas (",") and not semicolons (";")

New Post: ClosedXML Excel File

$
0
0
Iterate through the rest of the sheets?

Updated Wiki: Evaluating Formulas

$
0
0

Evaluating Formulas

If you call cell.Value ClosedXML will try to resolve the formula and give you the result.

For example:

    var wb = new XLWorkbook();
    var ws = wb.AddWorksheet("Sheet1");
    ws.Cell("A1").SetValue(1).CellBelow().SetValue(1);
    ws.Cell("B1").SetValue(1).CellBelow().SetValue(1);

    ws.Cell("C1").FormulaA1 = "\"The total value is: \" & SUM(A1:B2)";

    var r = ws.Cell("C1").Value;
    Assert.AreEqual("The total value is: 4", r.ToString());

    // It also works if you use: ws.Cell("C1").GetString()

You can even resolve your own formulas without using cells. For Example:

If you're not referencing a worksheet you can use:
  var sum = XLWorkbook.EvaluateExpr("SUM(1,2,3)");
  // sum = 6
  // SUM(Sheet1!A1:B2) will fail because it doesn't know which workbook to use


If you're not referencing a range without a worksheet you can use:
  var sum = workbook.Evaluate("SUM(Sheet1!A1:B2)");
  // SUM(A1:B2) will fail because it doesn't know which sheet to use


If you have the worksheet you can evaluate at your heart's content:
  var sum = worksheet.Evaluate("SUM(A1:B2)");

Very important:

  • Not all formulas are included and you'll probably get a nasty error if the formula isn't supported or if there's an error in the formula. Please test your formulas before going to production.
  • I'm adding new formulas all the time but if your formula isn't included please let me know via the Issue Tracker. I'll do my best to include the formula asap.

Supported functions

ce.RegisterFunction("DATE", 3, Date); // Returns the serial number of a particular date
ce.RegisterFunction("DATEVALUE", 1, Datevalue); // Converts a date in the form of text to a serial number
ce.RegisterFunction("DAY", 1, Day); // Converts a serial number to a day of the month
ce.RegisterFunction("DAYS360", 2, 3, Days360); // Calculates the number of days between two dates based on a 360-day year
ce.RegisterFunction("EDATE", 2, Edate); // Returns the serial number of the date that is the indicated number of months before or after the start date
ce.RegisterFunction("EOMONTH", 2, Eomonth); // Returns the serial number of the last day of the month before or after a specified number of months
ce.RegisterFunction("HOUR", 1, Hour); // Converts a serial number to an hour
ce.RegisterFunction("MINUTE", 1, Minute); // Converts a serial number to a minute
ce.RegisterFunction("MONTH", 1, Month); // Converts a serial number to a month
ce.RegisterFunction("NETWORKDAYS", 2, 3, Networkdays); // Returns the number of whole workdays between two dates
ce.RegisterFunction("NOW", 0, Now); // Returns the serial number of the current date and time
ce.RegisterFunction("SECOND", 1, Second); // Converts a serial number to a second
ce.RegisterFunction("TIME", 3, Time); // Returns the serial number of a particular time
ce.RegisterFunction("TIMEVALUE", 1, Timevalue); // Converts a time in the form of text to a serial number
ce.RegisterFunction("TODAY", 0, Today); // Returns the serial number of today's date
ce.RegisterFunction("WEEKDAY", 1, 2, Weekday); // Converts a serial number to a day of the week
ce.RegisterFunction("WEEKNUM", 1, 2, Weeknum); // Converts a serial number to a number representing where the week falls numerically with a year
ce.RegisterFunction("WORKDAY", 2, 3, Workday); // Returns the serial number of the date before or after a specified number of workdays
ce.RegisterFunction("YEAR", 1, Year); // Converts a serial number to a year
ce.RegisterFunction("YEARFRAC", 2, 3, Yearfrac); // Returns the year fraction representing the number of whole days between startdate and enddate
ce.RegisterFunction("AND", 1, int.MaxValue, And);
ce.RegisterFunction("OR", 1, int.MaxValue, Or);
ce.RegisterFunction("NOT", 1, Not);
ce.RegisterFunction("IF", 3, If);
ce.RegisterFunction("TRUE", 0, True);
ce.RegisterFunction("FALSE", 0, False);
ce.RegisterFunction("ABS", 1, Abs);
ce.RegisterFunction("ACOS", 1, Acos);
ce.RegisterFunction("ACOSH", 1, Acosh);
ce.RegisterFunction("ASIN", 1, Asin);
ce.RegisterFunction("ASINH", 1, Asinh);
ce.RegisterFunction("ATAN", 1, Atan);
ce.RegisterFunction("ATAN2", 2, Atan2);
ce.RegisterFunction("ATANH", 1, Atanh);
ce.RegisterFunction("CEILING", 1, Ceiling);
ce.RegisterFunction("COMBIN", 2, Combin);
ce.RegisterFunction("COS", 1, Cos);
ce.RegisterFunction("COSH", 1, Cosh);
ce.RegisterFunction("DEGREES", 1, Degrees);
ce.RegisterFunction("EVEN", 1, Even);
ce.RegisterFunction("EXP", 1, Exp);
ce.RegisterFunction("FACT", 1, Fact);
ce.RegisterFunction("FACTDOUBLE", 1, FactDouble);
ce.RegisterFunction("FLOOR", 1, Floor);
ce.RegisterFunction("GCD", 1, 255, Gcd);
ce.RegisterFunction("INT", 1, Int);
ce.RegisterFunction("LCM", 1, 255, Lcm);
ce.RegisterFunction("LN", 1, Ln);
ce.RegisterFunction("LOG", 1, 2, Log);
ce.RegisterFunction("LOG10", 1, Log10);
ce.RegisterFunction("MDETERM", 1, MDeterm);
ce.RegisterFunction("MINVERSE", 1, MInverse);
ce.RegisterFunction("MMULT", 2, MMult);
ce.RegisterFunction("MOD", 2, Mod);
ce.RegisterFunction("MROUND", 2, MRound);
ce.RegisterFunction("MULTINOMIAL", 1, 255, Multinomial);
ce.RegisterFunction("ODD", 1, Odd);
ce.RegisterFunction("PI", 0, Pi);
ce.RegisterFunction("POWER", 2, Power);
ce.RegisterFunction("PRODUCT", 1, 255, Product);
ce.RegisterFunction("QUOTIENT", 2, Quotient);
ce.RegisterFunction("RADIANS", 1, Radians);
ce.RegisterFunction("RAND", 0, Rand);
ce.RegisterFunction("RANDBETWEEN", 2, RandBetween);
ce.RegisterFunction("ROMAN", 1, 2, Roman);
ce.RegisterFunction("ROUND", 2, Round);
ce.RegisterFunction("ROUNDDOWN", 2, RoundDown);
ce.RegisterFunction("ROUNDUP", 1, 2, RoundUp);
ce.RegisterFunction("SERIESSUM", 4, SeriesSum);
ce.RegisterFunction("SIGN", 1, Sign);
ce.RegisterFunction("SIN", 1, Sin);
ce.RegisterFunction("SINH", 1, Sinh);
ce.RegisterFunction("SQRT", 1, Sqrt);
ce.RegisterFunction("SQRTPI", 1, SqrtPi);
ce.RegisterFunction("SUBTOTAL", 2, 255, Subtotal);
ce.RegisterFunction("SUM", 1, int.MaxValue, Sum);
ce.RegisterFunction("SUMIF", 2, 3, SumIf);
ce.RegisterFunction("SUMSQ", 1, 255, SumSq);
ce.RegisterFunction("TAN", 1, Tan);
ce.RegisterFunction("TANH", 1, Tanh);
ce.RegisterFunction("TRUNC", 1, Trunc);
ce.RegisterFunction("AVERAGE", 1, int.MaxValue, Average);
ce.RegisterFunction("AVERAGEA", 1, int.MaxValue, AverageA);
ce.RegisterFunction("COUNT", 1, int.MaxValue, Count);
ce.RegisterFunction("COUNTA", 1, int.MaxValue, CountA);
ce.RegisterFunction("COUNTBLANK", 1, int.MaxValue, CountBlank);
ce.RegisterFunction("COUNTIF", 2, CountIf);
ce.RegisterFunction("MAX", 1, int.MaxValue, Max);
ce.RegisterFunction("MAXA", 1, int.MaxValue, MaxA);
ce.RegisterFunction("MIN", 1, int.MaxValue, Min);
ce.RegisterFunction("MINA", 1, int.MaxValue, MinA);
ce.RegisterFunction("STDEV", 1, int.MaxValue, StDev);
ce.RegisterFunction("STDEVA", 1, int.MaxValue, StDevA);
ce.RegisterFunction("STDEVP", 1, int.MaxValue, StDevP);
ce.RegisterFunction("STDEVPA", 1, int.MaxValue, StDevPA);
ce.RegisterFunction("VAR", 1, int.MaxValue, Var);
ce.RegisterFunction("VARA", 1, int.MaxValue, VarA);
ce.RegisterFunction("VARP", 1, int.MaxValue, VarP);
ce.RegisterFunction("VARPA", 1, int.MaxValue, VarPA);
ce.RegisterFunction("ASC", 1, Asc); // Changes full-width (double-byte) English letters or katakana within a character string to half-width (single-byte) characters
ce.RegisterFunction("CHAR", 1, _Char); // Returns the character specified by the code number
ce.RegisterFunction("CLEAN", 1, Clean); // Removes all nonprintable characters from text
ce.RegisterFunction("CODE", 1, Code); // Returns a numeric code for the first character in a text string
ce.RegisterFunction("CONCATENATE", 1, int.MaxValue, Concat); // Joins several text items into one text item
ce.RegisterFunction("DOLLAR", 1, 2, Dollar); // Converts a number to text, using the $ (dollar) currency format
ce.RegisterFunction("EXACT", 2, Exact); // Checks to see if two text values are identical
ce.RegisterFunction("FIND", 2, 3, Find); //Finds one text value within another (case-sensitive)
ce.RegisterFunction("FIXED", 1, 3, Fixed); // Formats a number as text with a fixed number of decimals
ce.RegisterFunction("LEFT", 1, 2, Left); // LEFTB Returns the leftmost characters from a text value
ce.RegisterFunction("LEN", 1, Len); //, Returns the number of characters in a text string
ce.RegisterFunction("LOWER", 1, Lower); // Converts text to lowercase
ce.RegisterFunction("MID", 3, Mid); // Returns a specific number of characters from a text string starting at the position you specify
ce.RegisterFunction("PROPER", 1, Proper); // Capitalizes the first letter in each word of a text value
ce.RegisterFunction("REPLACE", 4, Replace); // Replaces characters within text
ce.RegisterFunction("REPT", 2, Rept); // Repeats text a given number of times
ce.RegisterFunction("RIGHT", 1, 2, Right); // Returns the rightmost characters from a text value
ce.RegisterFunction("SEARCH", 2, Search); // Finds one text value within another (not case-sensitive)
ce.RegisterFunction("SUBSTITUTE", 3, 4, Substitute); // Substitutes new text for old text in a text string
ce.RegisterFunction("T", 1, T); // Converts its arguments to text
ce.RegisterFunction("TEXT", 2, _Text); // Formats a number and converts it to text
ce.RegisterFunction("TRIM", 1, Trim); // Removes spaces from text
ce.RegisterFunction("UPPER", 1, Upper); // Converts text to uppercase
ce.RegisterFunction("VALUE", 1, Value); // Converts a text argument to a number
ce.RegisterFunction("HYPERLINK", 1, Hyperlink);

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

New Post: How do I get formatted cell values, according to the excel cell format definitions?

$
0
0
How can I reproduce it? The following works fine (I get "0.1")
            var wb = new XLWorkbook();
            var ws = wb.AddWorksheet("Sheet1");
            ws.Cell("A1").SetValue(0.09).Style.NumberFormat.SetFormat("0.0");
            var s = ws.Cell("A1").GetFormattedString();
btw, how did you get 0.10000000000000009 into Excel? The most I can put in is 0.100000000000009

New Post: Columns().AdjustToContents leaving extra padding

$
0
0
Well, that is the best I can do for that function ^_^

The problem is that I have to take into account text length, size, font, weight, orientation, and I don't remember what else to come up with a size that "will most likely" fit the text.

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

__See my comment for new description of the problem.__
Comments: ** Comment from web user: Raidri **

The test file is working with the new version. In my real file I found one small issue still:

Excel saved the formula as "=ROUND('Anlage'!C48, 2)" with the single quotes around "Anlage" (the sheet name). These give an error in ClosedXML (the "Identifier expected." exception) but can safely be removed so that it works. If you use the simple formula "='Anlage'!C48" it works both with and without the single quotes. Only inside the ROUND function they give the error.
This issue will come back if you have a sheet name with a space in it, than ClosedXML will throw a "Syntax Error" exception.

PS: I had the semicolons because I copied the formulas from the German Excel version with uses them because the comma is the decimal separator (this is only in the frontend, the saved files have the default symbols).

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

__See my comment for new description of the problem.__
Comments: ** Comment from web user: MDeLeon **

I'll check the quotes in the sheet name issue tonight...

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

$
0
0
Hello MDeLeon,

thank you very much for your fast replay!

Regards,
Christian

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

$
0
0

Hello MDeLeon,

the difference to your test is that I’m reading an existing Excel sheet with format definitions.

In the attached image you can see a part of the sheet with the visible values.

The value “0,1” in cell T3 is calculated by the following formula:

=RUNDEN(R3/MIN(INDIREKT(VERKETTEN("R";VERGLEICH(J3;INDIREKT(VERKETTEN("J";VERGLEICH(G3;G:G;0);":J";VERGLEICH(G3;G:G)));0)+VERGLEICH(G3;G:G;0)-1;":R";VERGLEICH(J3;INDIREKT(VERKETTEN("J";VERGLEICH(G3;G:G;0);":J";VERGLEICH(G3;G:G))))+VERGLEICH(G3;G:G;0)-1)));1)-1

The value “22400” in cell S3 is calculated by the following formula:

=ABRUNDEN(MIN(INDIREKT(VERKETTEN("R"&VERGLEICH(G3;G:G;0)&":R"&VERGLEICH(G3;G:G))));-2)

Is there any easy way to get the formatted cell values in ClosedXML?

Regards,

Christian

--

Christian Obser

Senior Specialist | Computational Statistics | Marketing Sciences

GfK SE | Nordwestring 101 | 90419 Nürnberg | Germany

T +49 911 395 2761

www.gfk.com

Visitor address: Schnieglinger Str. 57 | 90419 Nürnberg | Germany

Von: MDeLeon [email removed]
Gesendet: Donnerstag, 15. August 2013 04:43
An: Obser, Christian (GfK)
Betreff: Re: Problem reading cell values of cells with formula MTRANS. [closedxml:453397]

From: MDeLeon

TRANSPOSE is not supported and probably won't be until someone submits a patch for it. It's a nasty formula because it has many meanings depending on where it's used and it can be a regular or an array formula.

I updated https://closedxml.codeplex.com/wikipage?title=Evaluating%20Formulas with the list of functions supported.




GfK SE, Nuremberg, Germany, commercial register Nuremberg HRB 25014; Management Board: Matthias Hartmann (CEO), Pamela Knapp (CFO), Dr. Gerhard Hausruckinger, Debra A. Pruent; Chairman of the Supervisory Board: Dr. Arno Mahlert
This email and any attachments may contain confidential or privileged information. Please note that unauthorized copying, disclosure or distribution of the material in this email is not permitted.

New Post: How do I get formatted cell values, according to the excel cell format definitions?

$
0
0
The difference to your test is that I’m reading an existing Excel sheet with format definitions.
The value “0,1” in cell T3 is calculated by the following formula:
=RUNDEN(R3/MIN(INDIREKT(VERKETTEN("R";VERGLEICH(J3;INDIREKT(VERKETTEN("J";VERGLEICH(G3;G:G;0);":J";VERGLEICH(G3;G:G)));0)+VERGLEICH(G3;G:G;0)-1;":R";VERGLEICH(J3;INDIREKT(VERKETTEN("J";VERGLEICH(G3;G:G;0);":J";VERGLEICH(G3;G:G))))+VERGLEICH(G3;G:G;0)-1)));1)-1

Is there any easy way in ClosesXML to get the formatted cell values as they are?

Created Unassigned: Selecting Table Data/Columns by name. [8959]

$
0
0
Hi there,

Firstly, loving the library! Super-useful coming from the Office libraries!

One issue I had though, is that I'm unable to select a particular column within a table by name. In Excel the table columns are given unique names based on their columns;

![Image](http://i.imgur.com/aMFmbG5.png)

This lets you select just the cells within that column, and subsequently apply DataValidations to them.

![Image](http://i.imgur.com/clBMrEZ.png)

Is there a way to mimic this functionality in ClosedXML? I can see the Field type, but it doesn't seem to have any link back to the actual range it refers too, and additionally no way to apply validations.

Something simple like;

```
var workbook = new ClosedXML.Excel.XLWorkbook();
var worksheet = workbook.AddWorksheet("Test");
worksheet.Cell(1,1).Value = "One";
worksheet.Cell(1,2).Value = "Two";
worksheet.Cell(1,3).Value = "Three";
worksheet.Cell(1,4).Value = "Four";
worksheet.Cell(1,5).Value = "Five";

var range = Worksheet.Range(1, 1, 5, 5);
var table = range.CreateTable("New Table");
var field = table.Field("One");

field.DataRange.DataValidations...
field.HeaderCell.


```

Regards,
Jake

Commented Unassigned: Selecting Table Data/Columns by name. [8959]

$
0
0
Hi there,

Firstly, loving the library! Super-useful coming from the Office libraries!

One issue I had though, is that I'm unable to select a particular column within a table by name. In Excel the table columns are given unique names based on their columns;

![Image](http://i.imgur.com/aMFmbG5.png)

This lets you select just the cells within that column, and subsequently apply DataValidations to them.

![Image](http://i.imgur.com/clBMrEZ.png)

Is there a way to mimic this functionality in ClosedXML? I can see the Field type, but it doesn't seem to have any link back to the actual range it refers too, and additionally no way to apply validations.

Something simple like;

```
var workbook = new ClosedXML.Excel.XLWorkbook();
var worksheet = workbook.AddWorksheet("Test");
worksheet.Cell(1,1).Value = "One";
worksheet.Cell(1,2).Value = "Two";
worksheet.Cell(1,3).Value = "Three";
worksheet.Cell(1,4).Value = "Four";
worksheet.Cell(1,5).Value = "Five";

var range = Worksheet.Range(1, 1, 5, 5);
var table = range.CreateTable("New Table");
var field = table.Field("One");

field.DataRange.DataValidations...
field.HeaderCell.


```

Regards,
Jake
Comments: ** Comment from web user: MDeLeon **

Use table.DataRange.Column("One")

table.Field is used to get/set the field total formulas.

Commented Unassigned: Selecting Table Data/Columns by name. [8959]

$
0
0
Hi there,

Firstly, loving the library! Super-useful coming from the Office libraries!

One issue I had though, is that I'm unable to select a particular column within a table by name. In Excel the table columns are given unique names based on their columns;

![Image](http://i.imgur.com/aMFmbG5.png)

This lets you select just the cells within that column, and subsequently apply DataValidations to them.

![Image](http://i.imgur.com/clBMrEZ.png)

Is there a way to mimic this functionality in ClosedXML? I can see the Field type, but it doesn't seem to have any link back to the actual range it refers too, and additionally no way to apply validations.

Something simple like;

```
var workbook = new ClosedXML.Excel.XLWorkbook();
var worksheet = workbook.AddWorksheet("Test");
worksheet.Cell(1,1).Value = "One";
worksheet.Cell(1,2).Value = "Two";
worksheet.Cell(1,3).Value = "Three";
worksheet.Cell(1,4).Value = "Four";
worksheet.Cell(1,5).Value = "Five";

var range = Worksheet.Range(1, 1, 5, 5);
var table = range.CreateTable("New Table");
var field = table.Field("One");

field.DataRange.DataValidations...
field.HeaderCell.


```

Regards,
Jake
Comments: ** Comment from web user: ShadowXVII **

Ah! There it is! I figured it must be possible just couldn't find an [explicit example](https://closedxml.codeplex.com/wikipage?title=Using%20Tables).

Everything else has been really intuitive, which is fantastic. Working in an environment without any .NET smarts or IDE is painful, so I've been relying on documentation :)

Closed Unassigned: Selecting Table Data/Columns by name. [8959]

$
0
0
Hi there,

Firstly, loving the library! Super-useful coming from the Office libraries!

One issue I had though, is that I'm unable to select a particular column within a table by name. In Excel the table columns are given unique names based on their columns;

![Image](http://i.imgur.com/aMFmbG5.png)

This lets you select just the cells within that column, and subsequently apply DataValidations to them.

![Image](http://i.imgur.com/clBMrEZ.png)

Is there a way to mimic this functionality in ClosedXML? I can see the Field type, but it doesn't seem to have any link back to the actual range it refers too, and additionally no way to apply validations.

Something simple like;

```
var workbook = new ClosedXML.Excel.XLWorkbook();
var worksheet = workbook.AddWorksheet("Test");
worksheet.Cell(1,1).Value = "One";
worksheet.Cell(1,2).Value = "Two";
worksheet.Cell(1,3).Value = "Three";
worksheet.Cell(1,4).Value = "Four";
worksheet.Cell(1,5).Value = "Five";

var range = Worksheet.Range(1, 1, 5, 5);
var table = range.CreateTable("New Table");
var field = table.Field("One");

field.DataRange.DataValidations...
field.HeaderCell.


```

Regards,
Jake
Comments: Another happy user :)
Viewing all 1877 articles
Browse latest View live


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