How to use NPOI to get user defined format from a cell in xlsx file? - xlsx

Background: I have a Date cell with the following user defined format ggge"年"m"月"d"日". However, if I call cell.CellType on this cell, the return value would be Numeric.
I need to distinguish it from other Numeric cells, but DateUtil.isCellDateFormatted(cell) returns false in this case (I believe it is because this is not a built-in Date format).
So I'm thinking if I can get the format of each cell, I can use it to determine if a cell is a Date cell or not. However, cell.CellStyle.DataFormat would only return a number code. Is there any way to get the format ggge"年"m"月"d"日 from NPOI's ICell object?

Related

Google Sheets: Sum, Query, other Formulas Treating Values (Formatted as NUMBERS) as Zeroes in Formulas - Unclear why

I have 15 Google Workbooks that import into 1 Workbook tab through an Importrange + Query combo function. The data is then queried and transformed across several other tabs, but the problem definitely begins on this tab.
Although I've manually forced a format change to "Number" in each workbook source AND in Columns CO:CQ (where the problematic data lands), all functions see the data as zero or null. Here is what happens when I set a random cell (CW33) equal to a cell in one of the trouble columns (CO33)
However, when I wrap the cell in an =sum(), the workbook returns "0":
I have no idea how to force the workbook to see the values in these rows as numbers without creating an entirely new column - does anyone have any ideas on how to fix it while preserving the column structure?
Thanks!
try:
=SUM(CO33*1)
for multiple cells it would be:
=ARRAYFORMULA(SUM(CO33:CO34*1))
or:
=SUMPRODUCT(CO33:CO34)
AFAIK, in Sheets, a Number formatted cell displays contents right-aligned and Plain-Text are left-aligned. The highlighted cell looks like a text cell.
Try changing the format of cell or column manually to 'Number' from the 'Format' tab.

SSRS Format Numeric not summarizing in excel

I need to set a format for a column when the column "KPI" has a value with '%' I need that the value has the format for a percentage otherwise the currency format, so I have something like this:
=IIF(InStr(Fields!KPI.Value,"%")>0,Format(Fields!DIA.Value, "P"),Format(Fields!DIA.Value, "C"))
That expression works properly, but when I try to export that report to excel, that column is not summarizing when I select several columns as you will see in this picture:
As you can see excel is recounting but not summarizing, I have tried formatting each field from SQL Server and with this formula:
=IIF(InStr(Fields!KPI.Value,"%")>0,Format(Fields!DIA.Value, "###.#%"),Format(Fields!DIA.Value, "###,###,###,###.##"))
But the same happend when I export that report to excel, is there another way to handle this?
In order to make sure that Excel interprets a value as numeric, you can use the RenderFormat global variable to detect when the report is being rendered for Excel and not include the problematic formatting characters:
=IIF(InStr(Fields!KPI.Value,"%")>0,Format(Fields!DIA.Value, "###.#%"),IIF(OR(Globals!RenderFormat.Name="EXCELOPENXML",Gl‌​obals!RenderFormat.N‌​ame="EXCEL"),Fields!‌​DIA.Value,Format(Fie‌​lds!DIA.Value, "###,###,###,###.##")))
If its critical that you display a thousands separator in your generated output you can use the Language global variable to detect the user's region and use the appropriate character. That check would take the general form Globals.Lanuage="en-US", depending on what particular regions are involved.
Here's an example of using the RenderFormat.Name variable to check the renderer in VS2013:
When doing a preview of the report, the format will show that the render type is RPL:

Format numbers in data field of SSRS Matrix with two different number types using an expression

So, I have an SSRS report with a matrix. The columns, rows and data field are fed by expressions that refer to parameters. Effectively giving the report a pivot table style effect.
The data field has two values in the #prmDataField parameter to pick from when running the report. One is called LengthOfStayand in the databse is all integers. The second is called FinalCostand in the real world would be currency (GBP in this case) but of course in the database it's just a float.
There's a 4th parameter to apply an aggregate function to the data in the data field that's as follows;
=SWITCH
(
Parameters!prmFunction.Value="Avg",AVG(Fields(Parameters!prmDataField.Value).Value)
,Parameters!prmFunction.Value="Sum",SUM(Fields(Parameters!prmDataField.Value).Value)
,Parameters!prmFunction.Value="Max",MAX(Fields(Parameters!prmDataField.Value).Value)
,Parameters!prmFunction.Value="Min",MIN(Fields(Parameters!prmDataField.Value).Value)
)
My problem: I'm hoping there's a way to enter an expression into the Number format property of the data field textbox of the matrix so the data on the report will format depending on which of the datafield parameter values have been selected to run the report with. So if you pick LengthOfStaythe report will display the numbers as appropriately formatted integers. If you pick FinalCostthe report will display the numbers as currency instead.
I attempted this;
=SWITCH
(Parameters!prmDataField.Value=Fields!Length_of_Stay.Value,"G-int32"
,Parameters!prmDataField.Value=Fields!Spell_Final_Cost.Value,"C")
But it didn't work and I got the following warning back once the report had run;
Warning 1 [rsRuntimeErrorInExpression] The Format expression for the textrun ‘Textbox17.Paragraphs[0].TextRuns[0]’ contains an error: Input string was not in a correct format.'
Is it even possible to have two different number types for formatting depending on a parameter value or any other value?

VB.Net - Excel application get showing values of an range

I'm trying get an Excel Range and copy into an array of objects with Vb.Net.
This is not a problem. I use the following code:
Dim vValues(,) As Object = ExcelApp.Range(vRange).Value
And works fine; but I have a the following case:
In the column "C"; the value has a specific format and internally has another value.
My question is:
Somebody know the way to get the information exact as the user see?
I'm trying to get the information without use a For ... Each or some kind of cycle.
I'm also tried to avoid use "text to columns" function.
Both seems right solutions, but would impact the performance with a lot of data.
FYI: Also I can get the information through the ODBC connection; but I'm searching the solution using a Range
Exactly what the user sees is the Text property. But you cannot have an array of that, you will have to query each cell individually.
You are getting a Double value in your array instead of a DateTime value because you have "Time" formatting applied in Excel. If you had a format from the "Date" category, Excel would instead send a proper Variant/Date, not a Double that represents it.
Another option would be constructing the DateTime objects on the .NET side, provided you know in which columns they should be.

isdate function in ssis derived component

Is there any way to check Date(like isDate function in TSQL) column in SSIS package derived column expression after extraction from Sourcefile before loading to target dtabase?
Thanks
there is no built in function but you can run a script task and use vb.net code to check if the column is a date and operate on it as you wish...
I had a similar issue. I had a date/time in a text file, but the field had a dash between the date and the time. I created a derived column to do a replace on the dash:
REPLACE([TimeField], "- ", "")
I then added a convert column to convert the field to a date. I chose to ignore errors. I then added another Derived Column to check if the converted field was NULL, indicating that it could not convert the value. If it was, I had it set to the current date.
There is a a data conversion task you can drop in. Then redirect the rows as needed, either failing the import entirely or redircting the rows that don't work.
Or you could try a conditional split wher eyou cast the field to a date data type and then send the failures along another path (either deleting the records or nulling out the field would be the common action.)
See also http://www.sqlis.com/sqlis/post/Expression-Date-Functions.aspx > "IsDate workaround" for a technique that can be adapted
You can check whether your variable has a date or not using a conditional statement like this:
testDateVariable?true:false
For example, if date > 2 then it is true (and put the date, or format the date as you wish). If it is false, put null (you replace true with the date format and false with null).
All this is in a drived column in SSIS.

Resources