I concluded that getOldCalculatedValue() returns already calculated formula if a cell contains a formula, or value if a cell does not contain a formula. My assumption is confirmed by Mark Baker's post (althought this post is from year 2011):
$value = $objPHPExcel->setActiveSheetIndex(0)
->getCell('G'.$i)
->getValue();
Will return the actual formula if the cell contains a formula, or the
value if the cell contains a value.
$value = $objPHPExcel->setActiveSheetIndex(0)
->getCell('G'.$i)
->getCalculatedValue();
Will return the calculated value if the cell contains a formula, or the value
if the cell contains a value.
$value = $objPHPExcel->setActiveSheetIndex(0)
->getCell('G'.$i)
->getOldCalculatedValue();
Will return the previous result of a calculation if the cell contains a formula,
or the value if the cell contains a value.
I created xlsx (Excel 2007) with one cell A1. A1's content is string 'foo'. When I call
$reader = new PHPExcel_Reader_Excel2007();
$excel = $reader->load(Input::file("pricelist")->getRealPath());
$worksheet = $excel->setActiveSheetIndex(0);
var_dump($worksheet->getCell('A1')->getOldCalculatedValue());
it prints NULL. If I change function to getCalculatedValue() or getValue() it works ok. I'm using PHPExcel 1.8.0.
It isn't strictly true, there are several reasons why getOldCalculatedValue() may return a NULL, even for a cell that contains a formula.
The main reasons are:
Not all spreadsheet formats support maintaining the last calculated value
Even for formats that do support maintaining the last calculated value, the application that created the file may not have written the value to the file
Automatic calculation may have been disabled in Excel (assuming that Excel was used to create the file
The last may be even more of an issue if automatic calculation was disabled at some point after the formula was entered, but there have been subsequent data changes which affect the formula, because they won't be reflected in the old calculated value
Related
I have an update policy which populates a target table column of dynamic type. The update policy logic for populating the dynamic column is as:-
project target_calculated_column = pack("key1",src_col1,
"key2",src_col2,
"key3",src_col3,
.
.
"keyN",src_colN)
The columns src_col1,src_col2,...,src_colN are fixed number of columns coming from a specific table which is source for the update policy. These columns are of various datatypes, mostly some of them are strings and others are integers. Also the main thing here is that these columns may or may not contain any values for the input rows. What this means is that for integer columns values could be null or in case of string columns it could be blank. Now the issue here is that the update policy function is obviously written before hand and hence it can't know which rows will have nulls or blanks etc. That's something that will only be known when update policy starts running. So when the update policy starts running we end up with the following type of data in the target column target_calculated_column , showing one sample value from target row:-
{
"key1":"sometext",
"key2":30,
"key3":null,
"key5":"hello",
"key6":"",
"key7":112,
"key8":"",
"key9":"",
.
.
"keyN":10
}
This demonstrates the problem. I don't want to keep the key value pairs as part of target_calculated_column which are empty (nulls, blanks etc.). I think what I am asking for is a conditional version of pack() that can ignore key value pairs with empty values, but I don't think such an option is there. Is there way I can postprocess target_calculated_column so that I can eliminate such key value pairs? Basically in case of this example I should be getting the following output:-
{
"key1":"sometext",
"key2":30,
"key5":"hello",
"key7":112,
.
.
"keyN":10
}
pack_all([ignore_null_empty]) function allows you to ignore nulls/empty values. If you want to remove some columns you can use the bag_remove_keys() function. The pack() function itself does not provide this option.
I am trying to import a .csv file to match the records in the database. However, the database records has leading zeros. This is a character field The amount of data is a bit higher side.
Here the length of the field in database is x(15).
The problem I am facing is that the .csv file contains data like example AB123456789 wherein the database field has "00000AB123456789" .
I am importing the .csv to a character variable.
Could someone please let me know what should I do to get the prefix zeros using progress query?
Thank you.
You need to FILL() the input string with "0" in order to pad it to a specific length. You can do that with code similar to this:
define variable inputText as character no-undo format "x(15)".
define variable n as integer no-undo.
input from "input.csv".
repeat:
import inputText.
n = 15 - length( inputText ).
if n > 0 then
inputText = fill( "0", n ) + inputText.
display inputText.
end.
input close.
Substitute your actual field name for inputText and use whatever mechanism you are actually using for importing the CSV data.
FYI - the "length of the field in the database" is NOT "x(15)". That is a display formatting string. The data dictionary has a default format string that was created when the schema was defined but it has absolutely no impact on what is actually stored in the database. ALL Progress data is stored as variable length length. It is not padded to fit the display format and, in fact, it can be "overstuffed" and it is very, very common for applications to do so. This is a source of great frustration to SQL reporting tools that think the display format is some sort of length limit. It is not.
I am using PHPExcel library to read spread sheet data. This library is giving me trouble reading the 'DATE' values.
Question:
How to instruct the PHPExcel to read the 'DATE' values properly even if 'setReadDataOnly' is set as 'false'?
Description:
PHPExcel version: 2.1, Environment: Ubuntu 12
Here is the code block:
$objReader = \PhpExcel\PHPExcel_IOFactory::createReaderForFile($spreadSheetFullFilePathString);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($spreadSheetFullFilePathString);
$objWorksheetObject = $objPHPExcel->getActiveSheet();
Am getting 'integer' values for the 'DATE' column values by default.
I found that, the line '$objReader->setReadDataOnly(true)' is causing the trouble.
So, Changed it as '$objReader->setReadDataOnly(false)'.
I am getting the Date column value properly after this change. But now the reader is reading ALL the ROWS + COLUMNS found in the excel.
Any help would be greatly appreciated.
If $objReader->setReadDataOnly(true);, then the only reader that can identify dates is the Gunumeric Reader. A date value can only be identified by the number format mask, and setReadDataOnly(true) tells the Reader not to read the formatting, so dates cannot subsequently be identified (Gnumeric is the exception, because it was written after the problem was identified, but none of the other Readers have yet been modified to read this information regardless of the setReadDataOnly value. If you need to identify dates, then the only option at this point is $objReader->setReadDataOnly(false);
However, for date cells, you shouldn't get an integer value; you should get a float: it's the decimal that identifies the time part of the Excel datetime serialized value.
If you know which cells contain dates, then you can convert them to unix timestamps or PHPExcel DateTime objects using the helper functions defined in the PHPExcel_Shared_DateTime class (and can then use all the standard PHP date handling functions).
You say that the reader is now reading ALL the ROWS + COLUMNS found in the excel: it should, irrespective of the setReadDataOnly value. If you don't want to read all the rows and columns, then you need to set a Read Filter.
In PhpExcel library when i am assigning values to IW4 the assigned value not generatted there
Steps:
We are using The code to generate the Value to cell in PHPExcel
**$objPHPExcel->getActiveSheet()->setCellValue('A1', 'cell value here');**
When i am using it to generate value to IW4 cell the value not getting generatted
**$objPHPExcel->getActiveSheet()->setCellValue('IW4', 'cell value here');**
Please Help me to find the solution
BIFF format Excel files only allow 256 columns (up to IV), OfficeOpenXML allows more.
If you set a value in a column beyond the limit, PHPExcel only knows it's invalid at the point where you save (when it knows whether you're saving as an Excel5 or Excel2007 file), Rather than trigger an exception at that point (which would be much more frustrating if it was a long running script), it silently discards the invalid columns or rows.
This is similar behaviour to Excel itself, if you open an xlsx file in an earlier version of Excel that doesn't support as many rows and columns.
So, I have created a variable "batch" with datatype datetime. Now my OLEBD source has a column "addDate" eg 2012-05-18 11:11:17.470 so does empty destination which is to be populated.
now this column addDate has many dates and I want to copy all dates which are "2012-05-18 11:11:17.470"
When I put value of the variable as this date, it automatically changes to mm/dd/yyyy hh;mm AM format and hence in my conditional split transformation, it couldn't match the date with the variable and hence no records are getting copied to the destination !!
Where exactly is the problem?
Thanks!
I had this issue and the best solution I found is not “pretty”.
Basically you need to change the “expression” of the variable and the “evaluate as expression” to true (otherwise it will ignore the value on expression).
The secret is (and kind of the reason I said it is not a pretty solution) to create a second variable to evaluate the expression of the first variable because you can’t change the value of a variable based on a expression.
So let’s say your variable is called “DateVariable” and you have 23/05/2012, create a variable called “DateVar2” for example and set its expression to
(DT_WSTR,4)YEAR(#[User::DateVariable]) + "/"+RIGHT("0" +
(DT_WSTR,2)MONTH(#[User::DateVariable]),2) + "/" + RIGHT("0" +
(DT_WSTR,2)DAY(#[User::DateVariable]),2)
That will give you 2012/05/23
Just keep going to get the date on the format you want
I found the easier solution. Select datatype as string. put any desired value.
Before conditional split, you need data conversion transformation.
convert it into DT_DBTIMESTAMP then run the package.
It works!