Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all 2707 articles
Browse latest View live

New Post: 13 digit numbers get rounded in Excel 5 format

$
0
0
32-bit or 64-bit versions? Is this really an integer number, or a float or is it a string?

That value exceeds the limits of 32-bit Excel for integers, so it should be maintained as a string in the xls file if maintaining precision is needed, so _readNumber() should never be called.

Can you please provide an example file that demonstrates this problem, together with the script that you are using to test it.

New Post: ROUND Function getCalculatedValue() error

$
0
0
All I can suggest is that you apply a formatting mask to the cell: this looks to be a case of floating point accuracy when trying to represent decimal numbers in binary

New Post: ROUND Function getCalculatedValue() error

$
0
0
Hi Mark

Thank you for your response. I have tried adding:
$objPHPExcel->getActiveSheet()->getStyle('A1')->getNumberFormat()->setFormatCode("#,##0.00");
$objPHPExcel->getActiveSheet()->getStyle('A1')->getNumberFormat()->setFormatCode("0.00");
before and after setting the cell value, but with no success I'm afraid. I also tried using apostrophes rather than quotation marks around the format code. I am not sure if this is the correct approach for setting the mask as suggested or if you would suggest something else?

I tried a few other tests to try to identify where the cause lies and got an interesting result. If I run an echo ROUND(96.239,2); on a blank php page the rounding works fine. However, once I include the phpexcel files, initialise a new instance and run the same pure PHP ROUND function it will make the same floating point error. So something during the initialising of a new phpexcel instance is causing the PHP ROUND function to behave differently... I'm not sure if this gives anyone any ideas?


Rounding error occurs:
require_once('phpexcel/Classes/PHPExcel.php');
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

echo "<br />".ROUND(96.239,2);
No Rounding error:
require_once('phpexcel/Classes/PHPExcel.php');

echo "<br />".ROUND(96.239,2);

// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
Tim

New Post: ROUND Function getCalculatedValue() error

$
0
0
You'll need to use getFormattedValue() rather than getCalculatedValue() if you're using a format mask; and this will return a PHP string: it's the equivalent of number_format() in PHP.

Note that PHPExcel emulates the functionality of Excel's ROUND() function, which isn't the same as PHP's round() function.

PHPExcel's calculation engine sets the precision to 14dp, and it may be this difference that is causing an issue. However, adjusting that value may lead to reduced accuracy elsewhere with other functions

However, this looks like a standard computer floating point precision issue: and (as such) is way outside the scope of PHPExcel to fix; but feel free to take a look at the ROUND() function and see if you have any bright ideas.

New Post: 13 digit numbers get rounded in Excel 5 format

$
0
0
i'm using a 64 bits version of windows 7 with php 5.3.

the column is in "general" format, is there a way phpexcel can handle this values?

i tried using an import programe made in fox and used the exact same file and the result is okay, so obviously there's a difference on how phpexcel and fox import excel files. is tehre a way to replicate this behaviour?

the excel file i'm using is this

http://www.drogbarracas.com.ar/excel.xls

by the way i also used this library to generate excel files and it works wornderfull

New Post: ROUND Function getCalculatedValue() error

$
0
0
Thanks Mark. With your change I have been able to override the formatting of the round result. Unfortunately, I am not able to apply that solution to my site at the moment as I do not wish to force any specific formatting on the user. I will have to look to expand my code to allow the user to apply number formatting to individual cells...

Back to the ROUND issue itself, I was not able to find PHPExcel's ROUND function. In the Calculation.php file the ROUND function call appears to be:
'functionCall'      =>  'round',
rather than what I would have expected:
'functionCall'      =>  'PHPExcel_Calculation_MathTrig::ROUND',
Perhaps someone can give me a better idea on where to find the PHPExcel ROUND function. For now I have added a new function in Calculation > MathTrig.php which makes use of BC math (and registered a function Call for this in Calculation.php).
function BCROUND($number, $scale=0) {
                $fix = "5";
                for ($i=0;$i<$scale;$i++) $fix="0$fix";
                $number = bcadd($number, "0.$fix", $scale+1);
                return    bcdiv($number, "1.0",    $scale);
}
This gets around the problem, but is not ideal as any other use of ROUND elsewhere in my application will default to the broken version and not my new function. I have reported this to my server host to see if this can be fixed via apache.

As a final point, I would note that PHPExcel alters the functioning of the native ROUND PHP function. If PHPExcel is not initialised the rounding issue does not exist. So if anyone knows how PHPExcel changes the functioning of native functions that could be really helpful.

Many thanks once again Mark.

Tim

New Post: Line Chart : another y axis

$
0
0
I am also looking this functionality too. Please let us know when this is possible.

New Post: 13 digit numbers get rounded in Excel 5 format


New Post: 13 digit numbers get rounded in Excel 5 format

$
0
0
Unless you have a 64-bit version of PHP, it can't handle 64-bit integer values, so PHPExcel can't either: if you're running 64-bit PHP, then it shouldn't be an issue

New Post: When using PHPExcel, why is the autosize stretching my image?

$
0
0
I am creating a spreadsheet using the PHPExcel Class. I have several columns of data. I am using the autosize method in order to have them take the size of the longest data value in each column.
// Forces the spreadsheet to take the size of the longest value             
for ($col = 'A'; $col != 'F'; $col++) { //Runs through all cells between A and E and sets to autosize
    $objPHPExcel->getActiveSheet()->getColumnDimension($col)->setAutoSize(true);
}
Next, I am adding an image, but it stretches across 4 columns, which it shouldn't.
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Paid');
$objDrawing->setDescription('Paid');
$objDrawing->setPath('../../Examples/images/paid.png');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
This is what is occuring (It should only be as wide as the first column):
enter image description here

I have removed the autosize method and it takes the correct size, so I know it is affecting the size of the image.

How can I remove the autosize from the image but leave it applied for the columns of data?

New Post: When using PHPExcel, why is the autosize stretching my image?

$
0
0
Try adding
$objDrawing->setResizeProportional(false); 

New Post: Avoiding memory exhaustion writing to xlsx file

$
0
0
Hello,

PHP 5.4
PHPExcel 1.7.8
FreeBSD 9 i386

I need to dump a MySQL database into an xlsx file and I'm hitting memory limits. I'm hitting vm.kmem_size_max, 512M I think, which requires a reboot to change, which isn't easy in production (I'm running on a test box now)... My script runs a few statements, clearing memory in between, creating Excel files for each result set. The biggest one is ~180k rows but the script is breaking before that on a ~100k statement in which I select nine small columns. If it's 1 KB per cell, which I've read, it should be roughly 900 MB? This is on a 32-bit VM. This is the error:

Fatal error: Allowed memory size of 402653184 bytes exhausted (tried to allocate 36 bytes) in /.../CachedObjectStorage/CacheBase.php on line 142

This is using phpTemp cache; I've tried most of them. I'm using the built-in Excel2007 writer.

I found another thread that had interesting stuff in it, but that was about reading from a large Excel file and writing into a database--my problem is in the opposite direction. The script basically runs a select statement and then iterates through each row, passing the data through a number of filters which do things like sanitize data, count rows, etc., one of which (the last one) is PHPExcel. In the PHPExcel filter it writes that row to the worksheet. In the filter destructor, PHPExcel saves the sheet to a file. In other words:
foreach filter (
    init (create PHPExcel object)
}
foreach row {
    foreach filter {
        run filter on row (set cell value and advance row iterator)
    }
}
foreach filter (
    finish (save file)
}
Is there any way to unset a row once it's written, or something else I can do, aside from selecting fewer rows? If I comment out the PHPExcel filter, it runs fine just outputting or counting rows. Reorganizing the script isn't as big a problem as rebooting.

Thanks,
Josh

New Post: Avoiding memory exhaustion writing to xlsx file

$
0
0
Ugh, false alarm. I found a latter memory_limit setting buried in another script. Raising that made the error go away. Sorry!

New Post: PhpExcel stops working after setting 20 cell types

$
0
0
I have a script that generates a little xls table (~25x15). It contains percentages and strings and i have an if operator that sets the current cell as percentage type with this code:

$this->objPHPExcel->getActiveSheet()->getStyle($coords)->getNumberFormat()->setFormatCode('0.00%');

But when i export and look at the file I see it only managed to set type and style about 20 cells. And all the rest are with default settings. I debugged it and realized the problem isn't in my logic. I read about increasing php cache memory - tried it but it didn't work. Please help because i need to export at least 15 times larger table. Thanks in advance!

New Post: PhpExcel stops working after setting 20 cell types

$
0
0
As PHPExcel doesn't impose any limit on the number of styles (though Excel itself does, it's well above 20), and a number of our demo scripts in the /Examples folder use more than 20 different styles, can you please provide a working example of code that demonstrates this problem. It may be that the problem is in a particular style that you are setting rather than after a number of styles.

New Post: Problem Graph doesn't display

$
0
0
Hello,

I try to display a pie graph in my excel sheet, I take the code example because I didn't find documentation about this, all sheet work well but not the graph, I put the code below can help me and see me what is wrong.
Thanks a lot for your help
$objPHPExcel->getActiveSheet()->setCellValue('B5', $row_tissus[0]);
$objPHPExcel->getActiveSheet()->setCellValue('B6', '300');
$objPHPExcel->getActiveSheet()->setCellValue('B9', $row_tissus[1]);
$objPHPExcel->getActiveSheet()->setCellValue('B10', $row_tissus[2]);
$objPHPExcel->getActiveSheet()->setCellValue('B11', $row_tissus[3]);
$objPHPExcel->getActiveSheet()->setCellValue('B12', $row_tissus[4]);
$objPHPExcel->getActiveSheet()->setCellValue('B13', $row_tissus[5]);
$objPHPExcel->getActiveSheet()->setCellValue('B14', $row_tissus[6]);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getStyle('A5:B14')->applyFromArray($styleArray);


$dataseriesLabels1 = array(
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$9', NULL, 1)
);

$xAxisTickValues1 = array(
        new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$9:$A$14', NULL, 6)  
);

$dataSeriesValues1 = array(
        new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$9:$B$14', NULL, 6)
);

$series1 = new PHPExcel_Chart_DataSeries(
        PHPExcel_Chart_DataSeries::TYPE_PIECHART,               // plotType
        PHPExcel_Chart_DataSeries::GROUPING_STANDARD,           // plotGrouping
        range(0, count($dataSeriesValues1)-1),                  // plotOrder
        $dataseriesLabels1,                                     // plotLabel
        $xAxisTickValues1,                                      // plotCategory
        $dataSeriesValues1                                      // plotValues
);

$layout1 = new PHPExcel_Chart_Layout();
$layout1->setShowVal(TRUE);
$layout1->setShowPercent(TRUE);

$plotarea1 = new PHPExcel_Chart_PlotArea($layout1, array($series1));

$legend1 = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);

$title1 = new PHPExcel_Chart_Title('Répartition des tissus');

$chart1 = new PHPExcel_Chart(
        'chart1',       // name
        $title1,        // title
        $legend1,       // legend
        $plotarea1,     // plotArea
        true,           // plotVisibleOnly
        0,              // displayBlanksAs
        NULL,           // xAxisLabel
        NULL            // yAxisLabel       - Pie charts don't have a Y-Axis
);

$chart1->setTopLeftPosition('C5');
$chart1->setBottomRightPosition('H20');

$objWorksheet->addChart($chart1);

New Post: Problem Graph doesn't display

$
0
0
When saving, are you using
$objWriter->setIncludeCharts(TRUE);
and using the Excel2007b Writer?

New Post: Problem Graph doesn't display

New Post: PhpExcel stops working after setting 20 cell types

$
0
0
I managed to extract only the functionality that handles exports and pass it sample data. Here is a sample code http://pastebin.com/wjWuX8J0 . When i uncomment cell-border settings export breaks, if i uncomment set-cell-to-percent functionality it breaks earlier. It seems the more styling and/or cell types i'm using the earlier export stops working. I'd be happy if you can give me any advice! Thanks in advance.

P.S. (by stop working i mean it stops styling and setting cell types, but it manages to fill in the whole data).

New Post: 13 digit numbers get rounded in Excel 5 format

$
0
0
is there a way we can tell phpexcel to force read as string even when the excel value is integer?
Viewing all 2707 articles
Browse latest View live


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