In my webpage, I am using PHPexcel 1.8 to generate excel files. Now I am facing an issue which describes below.
I have some date values in the format dd/mm/yyyy. The value is coming. But it shows with a single quote(') at the begining.
I tried many solutions. But none helps me out.
My sample code portion is given below
$cnt = 1;
foreach($gluuidArr as $uuid){
$this -> excel_180->getActiveSheet() ->setCellValue('A'.$cnt,$aVal);
$this -> excel_180->getActiveSheet() ->setCellValue('B'.$cnt,$bVal);
$this -> excel_180 -> getActiveSheet() -> setCellValue('C'.$cnt, $cVal);
$this -> excel_180->getActiveSheet() ->setCellValueExplicit('D'.$cnt,$dVal, PHPExcel_Cell_DataType::TYPE_STRING);
$this -> excel_180 -> getActiveSheet() -> setCellValue('E'.$cnt, $eVal);
$cnt += 1;
}
where $aVal, $bVal,.. are declaring inside the loop and $eval contains date in dd/mm/yyyy format
suppose the date is 20/05/2016, when click on the excel cell, it will show like '20/05/2016
I have tried
$this -> excel_180->getActiveSheet()->getStyle('E'.$cnt)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY);
But no luck.
Please help me to get rid of this issue. Any help could be appreciated.
That's because you're not storing a date, you're storing a string that happens to represent a date to human beings. MS Excel doesn't store dates as strings, but as floats, representing the number of days since 1st January 1900 (or 1st January 1904 on the Mac version)
If you want to store a date/time value in PHPExcel, then you need to convert that date/time to an MS Excel timestsamp value, and then set a format mask for the cell indicating how you want it to be displayed.
This is all explained in the PHPExcel Documentation and demonstrated in the Examples
Related
One of my first posts, so I'll do my best. I've tried searching this, which is how I got this far..but I could use some help converting some time data in the form mm:ss.000 (that's milliseconds at the end) to seconds with a fraction at the end. For example, 2:15.45 should come out to 135.45.
This works:
t <- "02:15.45" (as.numeric(as.POSIXct(strptime(t, format = "%M:%OS"))) - as.numeric(as.POSIXct(strptime("0", format = "%S"))))
But this one, where I'm trying to use a column of my dataframe (originally in character form) does not work:
starttimesFPsnapjumps <- FPsnapjumps$start (as.numeric(as.POSIXct(strptime(starttimesFPsnapjumps, format = "%M:%OS"))) - as.numeric(as.POSIXct(strptime("0", format = "%S"))))
Perhaps it's because my numbers in the column have an extra 0 - they are mm:ss.000. Any thoughts? Thanks in advance.
I'm new in Power BI and I'm more used to work with Excel. I try to translate following Excel formula:
=IF(A2="UPL";0;IF(MID(D2;FIND("OTP";D2)+3;1)=" ";"1";(MID(D2;FIND("OTP";D2)+3;1))))
in Power Bi as follows:
Algo =
VAR FindIT = FIND("OTP",Fixed_onTop_Data[Delivery Date],1,0)
RETURN
IF(Fixed_onTop_Data[Delivery Type] = "UPL", 0,
IF(FindIT = BLANK(), 1, MID(Fixed_onTop_Data[Delivery Date],FindIT+3,1))
)
Unfortunately I receive following error message:
Expressions that yield variant data-type cannot be used to define calculated columns.
My values are as follows:
Thank you so much for your help!
You cant mix Two datatypes in your output; In one part of if, you return an INT (literally 0/1), and is second you return a STRING
MID(Fixed_onTop_Data[Delivery Date],FindIT+3,1)
You must unify your output datatype -> everything to string or everything to INT
Your code must be returning BLANK in some cells therefore PowerBI isn't able to choose a data type for the column, wrap your code inside CONVERT(,INTEGER).
I have to change format to a single cell in a SAS table. That is, the column where the cell is, has format best12., while given that in the cell there is a date, for it I want to use YYMMDD10.
How can I fix?
Thanks in advance.
You can only associate a FORMAT with entire column. If you want cells that have mixed type formatted differently you need a character column that put PUT (function) values into.
To associate a different format with a column use.
proc datasets;
modify data-set-name;
format variables new-format.;
run;
quit;
Here is an example of what you can do if the data allows. Let's say that the earliest date in your data is 1st Jan 2000, this is stored as the number 14,610 in SAS (the number of days since 1st Jan 1960). Therefore if no non-date values exceed this number then you can achieve your goal by formatting all values up to 14,610 as best12. and all values greater than this as yymmdd10.
proc format;
value dtfmt low - 14609 = [best12.]
14610 - high = [yymmdd10.]
;
run;
data want;
input num;
format num dtfmt.;
datalines;
10
20
20514
30
;
run;
You can apply SUBSTR() in IF condition to check for first character and format your variable accordingly..using INPUT() or PUT()
I have following problem:
I need to write a begin and end date into a matrix. Where the matrix contains the yearly quarters (1-4) in the collumns and the rows are the year.
E.g.
Matrix:
Q1 Q2 Q3 Q4
2010
2011
Now the Date 01.01.2010 should be put in the first element and the date 09.20.2011 in the sixed element.
Thanks in advance.
You first have to consider that SAS does not actually have date/time/datetime variables. It just uses numeric variables formatted as date/time/datetime. The actual value being:
days since 1/1/1960 for dates
seconds since 00:00 for times
seconds since 1/1/1960 00:00 for datetimes
SAS does not even distinguish between integer and float numeric types. So a date value can contain a fractional part.
What you do or can do with a SAS numeric variable is completely up to you, and mostly depends on the format you apply. You could mistakenly format a variable containing a date value with a datetime format... or even with a currency format... SAS won't notice or complain.
You also have to consider that SAS does not even actually have matrixes and arrays. It does provide a way to simulate their use to read and write to dataset variables.
That said, SAS does provide a whole lot of formats and informats that allow you to implement date and time manipulation.
Assuming you are coding within a data step, and assuming the "dates" are in dataset numeric variables, then the PUT function can extract the datepart you need to calculate row, column of the matrix element to write to, like so:
DATA table;
ARRAY dm{2,4} dm_r1c1-dm_r1c4 dm_r2c1-dm_r2c4;
beg_row = PUT(beg_date, YEAR4.)-2009;
end_row = PUT(end_date, YEAR4.)-2009;
beg_col = PUT(beg_date, QTR1.);
end_col = PUT(end_date, QTR1.);
dm{beg_row,beg_col} = beg_date;
dm{end_row,end_col} = end_date;
RUN;
... or if you are using a one-dimensional array:
DATA table;
ARRAY da{8} da_1-da_8;
beg_index = 4 * (PUT(beg_date, YEAR4.)-2010) + PUT(beg_date, QTR1.);
end_index = 4 * (PUT(end_date, YEAR4.)-2010) + PUT(end_date, QTR1.);
da{beg_index} = beg_date;
da{end_index} = end_date;
RUN;
In my view which I am exporting to excel, I display the value of this variable
VeryGoodPercentage = subQst.Question.ReponseList.Where(
r => r.ReponseValeur == 4 &&
Model.SelectedGroupContactList.Select(c => c.ContaId).Contains(r.ContaId.Value)
).ToList().Count() * 100
/
denominator;
And I display this way
<td class=xl76 align=right width=69 style='width:52pt'>#Math.Round(VeryGoodPercentage)%</td>
When I display the view without exporting to excel, everything works just fine. But when I open the exported Excel file, I found the value of that variable not rounded.
For examlpe :
In the view : 36%
In the excel file : 0.36
I use this line to generate the file:
Response.AddHeader("Content-Type", "application/vnd.ms-excel");
As stated:
36% and 0.36 should be the same - just excel did not fomat this as a percentage or did indeed interpreted 36 as a percentage - which will result in 0.36 as a number.
I don't see that this is a rounding problem, it is formatting or input or both.
Depending on what values #Math.Round(VeryGoodPercentage) produce - 0.xx or XX.XX - with % sign or without, excel will interpret this differently.
Some examples:
=0.36 will result in a number of 0.36
=36 will result in a number of 36
no suprises so far, but now:
=0.36% will result to 0.0036
=36% will result to 0.36
BUT those were Formulars, now if you would just use F2 on an empty 'default' formatted cell and write into it:
36% -> you would format this as percentage, which would display this as 36%, but if you would format it as 'default', then it would be the number 0.36!
0.36% -> would behave like 36%
hope this clears more than it confuses ;) good luck to you!
edit: and to make this even more fuzzy, in my country . is the symbol for thounsands, so you would have to use , instead.
edit: with VBA you could setup your column or cell to use a specific numberformat like this:
Table1.Columns("A").NumberFormat = "0.00%"
I finally found the solution here
Format HTML table cell so that Excel formats as text?
just add this css param to the tag :
mso-number-format:Percent;