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

New Post: Why is the cell data duplicated in each column?

$
0
0
I'm new to PHPExcel and somehow I got the same data duplicated in the Excel spreadsheet using the following code:
$roster_sql = "SELECT * FROM EMPLOYEE";
$roster_result = mysql_query($roster_sql) or die(mysql_error());

//Populate 2D Array
$kcount = 0;
while($sheet_array = mysql_fetch_array($roster_result))
{
$sheet[$kcount] = $sheet_array;
$kcount++ ;
}
$rowID = 1;
foreach($sheet as $rowArray)
{
$columnID = 'A';
foreach($rowArray as $columnValue)
{
  $objPHPExcel->getActiveSheet()->setCellValue($columnID.$rowID, $columnValue);
  $columnID++;
}
$rowID++;
}

The generated spreadsheet has each cell value duplicated in the column. Did I populate the array incorrectly or is there something wrong when I write out the array?

Further, how do I write the header row in the same spreadsheet without hard coding the column names from the SQL?

Thanks for your help.

New Post: Why is the cell data duplicated in each column?

$
0
0
mysql_fetch_array($roster_result)
This return a array with string keys (fields name) AND numeric keys. Use MYSQL_ASSOC or MYSQL_NUM as 2nd param, not the default MYSQL_BOTH.
With MYSQL_ASSOC, you have the names for yours column headers...

Note : MySQL extension isn't recommended for writing new code.

New Post: Why is the cell data duplicated in each column?

$
0
0
Thank you so much, LWol! The duplicate data issue is resolved right away!
Could you help me on getting the header row info and how to write it to the same spreadsheet?

New Post: Why is the cell data duplicated in each column?

$
0
0
There are several ways to do this...
Considering that you ask mysql_fetch_array you return an associative array, you can retrieve the field names using array_keys then iterate in this array to write your headers.
Use a flag to do so only once when you course records.
$rowID=2//header in row 1, so first data in row 2
$writeHeader=true;
foreach($sheet as $rowArray)
{
    if($writeHeader){
        $hArray=array_keys($rowArray);
        $ColumnIdx=0; //column A, row for header hardcoded to 1
        foreach($hArray as $aHeader){
            $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($ColumnIdx++, 1, $aHeader);
        }
        $writeHeader=false;
    }
    $columnID = 'A';
    foreach($rowArray as $columnValue)
    {
      $objPHPExcel->getActiveSheet()->setCellValue($columnID.$rowID, $columnValue);
      $columnID++;//Warning: if you go after Z, this don't work
    }
    $rowID++;
}
Not tested :-)
I use setCellValueExplicitByColumnAndRow for two reasons:
-Explicit because I consider that the header is composed only of strings (which is the implicit type of explicit ;-)
-ByColumnAndRow: to avoid (bad) calculations on the column.
As I indicated in note in the code, increment the column when it is in the form of letter can lead to errors. If it is necessary to have as well, use the functions of support of PHPExcel (PHPExcel_Cell::columnIndexFromString and PHPExcel_Cell::stringFromColumnIndex) to convert the string to integer, make operations, convert the integer to string.

In doing so, if the table is empty, there is not any header.

New Post: Why is the cell data duplicated in each column?

$
0
0
LWol:
Many thanks again for your great help. It works beautifully!
As for the $columnID++ increment, it actually works for me. I'm able to save all my data in the proper columns beyond "Z", up to column "AO" in my case.

New Post: getValue from .xls returning mangled text

$
0
0
I believe this file is originally a binary excel workbook (.xlsb) and that is the reason it cannot be read using the phpexcel module. I'm digging around to see if I can convert it programatically into .xls before processing it in PHP.

Thanks

New Post: PDF Rendering with mPDF

$
0
0
HI there
I have encountered the similar problems with you.I tried to render a PDF files.And i tried to do it using my present PDF processing tool.But it can not work effectively.
I don't know why.I want to know that if there is a powerful PDF tool which supports to do that directly.And it would be better if it also supports to save or process PDF files.Thanks for any suggestions.

New Post: Format Error by opening File in Excel 2010 generated with ExcelWriter2007

$
0
0
Hi,

I developed a little export function by using PHPExcel latest version 1.7.9
The problem is that I have in a column data values which looks like
12345.10
12345.B
Generating the excel table by using SetCellValue() setting the format by getStyle()->getNumberFormat()->setFormatCode() seems to convert the dot to comma, so when opening the generated file the values are looking that way:
12345,10
12345,B
I used the IOFactory.php and also the PHPExcel_Writer_Excel2007 to instanciate a writer for excel 2007 but open it in Excel 2010.
Is this a possible failure or do I something wrong?

Many thanks

New Post: Format Error by opening File in Excel 2010 generated with ExcelWriter2007

$
0
0
I do not think either PHPExcel making change, but rather Excel.
Two solutions: set these values to a string (by setCellValueExplicit) or achieve with Excel a whole little workbook with a value formatted as you want, watch how Excel notes this format internally (*) and use it with PHPExcel.
(*) You can determine this by directly reading the xml files or by loading this file with PHPExcel and then asking to show you the format of the affected cell.

New Post: Format Error by opening File in Excel 2010 generated with ExcelWriter2007

$
0
0
Hi, thank you for answers.
By reading the file generated with excel the Format type of the cell is "General". When I'm Using setCellValueExplicit(), I can't choose TYPE_GENERAL, so it has to be TYPE_STRING I think?!
But by using this variation, I get an error by opening the PHPExcel file in Excel 2010, that sounds like that:
Excel detected unreadable content in 'file.xlsx' ...
and I can't open my file.

By using
getStyle(...)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_GENERAL);
instead, I have the same problem as described above.

What can I do wrong?!
For better understanding, here the method, which fills the cells by using setCellValueExplicit:
    public function process() {

        $iRowNumber = 2;
        $oSheet = $this->Excel->getActiveSheet();

        while ( $dsRow = $this->Statement->fetch(PDO::FETCH_OBJ) ) {

            $oSheet->setCellValueExplicit( 'A' . $iRowNumber, $dsRow->Reference, PHPExcel_Cell_DataType::TYPE_STRING);
            $oSheet->setCellValueExplicit( 'B' . $iRowNumber, $dsRow->EAN, PHPExcel_Cell_DataType::TYPE_NUMERIC);
            $oSheet->setCellValueExplicit( 'C' . $iRowNumber, $dsRow->Condition, PHPExcel_Cell_DataType::TYPE_STRING);
            $oSheet->setCellValueExplicit( 'D' . $iRowNumber, $dsRow->Stock, PHPExcel_Cell_DataType::TYPE_STRING);
            $oSheet->setCellValueExplicit( 'E' . $iRowNumber, $dsRow->Price, PHPExcel_Cell_DataType::TYPE_STRING);
            $oSheet->setCellValueExplicit( 'F' . $iRowNumber, $dsRow->DeliveryCode, PHPExcel_Cell_DataType::TYPE_STRING);
            $oSheet->setCellValueExplicit( 'G' . $iRowNumber, $dsRow->OfferDescription, PHPExcel_Cell_DataType::TYPE_STRING);

            $iRowNumber++;

        }
        
        return $this;

    }
btw.: same problem by using TYPE_INLINE...
I don't see any mistake.

New Post: Problem with fonts

$
0
0
Hello
I have a problem with font in generated excel file.
in template file I set a font on cells for example Bnazanin.
when excel file generated, the font is not Bnazanin, although when we point curcer to cells, see the font is Bnazanin, but we view the default fonts and when we double click on cell, the font go true.

New Post: Format Error by opening File in Excel 2010 generated with ExcelWriter2007

$
0
0
Ok, it seems to be an error occuring by opening in excel.
The generated file has dots in it and when opening in excel 2007 or 2010, the dots are converted to comma.

No big help for my problem, but thats not an error by the PHPExcel class.

Sorry and thanks.

New Post: Format Error by opening File in Excel 2010 generated with ExcelWriter2007

$
0
0
Check your MS Excel locale settings, it's likely that they're set to a "continental" format, which shows a decimal point as a comma

New Post: Format Error by opening File in Excel 2010 generated with ExcelWriter2007

$
0
0
'General' is a number format, the String type is a data type.
However, for setCellValueExplicit, it is the String type to which I thought. And in this case, there is no number to indicate format: Excel displays the data literally. And it will not seek to change the display depending on the locale.
I don't see any obvious errors in your code, but something bothers Excel. It 'just' to identify the problem. For example by generating the problem field with a number reduced records to analyze the result.

If Excel transforms the points by commas (by applying a locale, probably), is that the relevant values are considered as numbers by Excel, which certainly generates errors if this is not the case.

New Post: data .xlsx corrupt because error output only 0kb

$
0
0
PHPExcel me no problems when exported but when I open in Ms.Excel2007, it can not be opened because it is corrupt or invalid format,
because when i want to download it output only 0kb

This sample code themselves:
// redirect output to client browser
            header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
            header('Content-Disposition: attachment;filename="backup_categories_products.xlsx"');
            header('Cache-Control: max-age=0');
            $objWriter = PHPExcel_IOFactory::createWriter($workbook,'Excel2007');           
            $objWriter->save('$filename');

            // Clear the spreadsheet caches
            $this->clearSpreadsheetCache();
            exit;
Please help me to resolve this problem
thanks

New Post: data .xlsx corrupt because error output only 0kb

$
0
0
So what's the value of '$filename' and why is it quoted? That will literally try to save the file to a file called $filename (not the value of the $filename variable, but actually called $filename) on your server.

Save to 'php://output' if you want to send the file to the browser

New Post: Excel Problem (Template Sheet)

$
0
0
Hi

well...

I have 3 colunns...
Colunn A = Enter hour format( yy:mm)
Colunn B = Enter hour format (yy:mm)
colunn C = Automatic calculation of time.


There is a possibility of the second time be shorter than the first time ... I have problens in this possibility.

When i put in colunn A, and colunn B one example in PHP EXCEL
A --> 17:47
B --> 03:11
ITS WORKS.

Other example:
A --> 17:47
B --> 3:11 ---> (IF hours < 10, then fill in this format)...
IT DOESN'T WORK.


If i click in the sheet (after save), and press F2 in the cell, soon press Enter... This fix the problem...

Image


is there any possibility to include in the process a check to press F2 soon press enter in the cell?

observation: When i fill the sheet manualy, the cell self adjusts automatically.
I set (03:11), then the cell self adjust to (3:11) .

When i fill in PHPExcel, the cells doesn't adjust automatically.

New Post: data .xlsx corrupt because error output only 0kb

$
0
0
but if I set it to Save to 'php :/ / output' message "failed to open the Save to 'php :/ / output'"

explanation please

New Post: How can I export data from multiple MySQL table to Excel

$
0
0
I am totally new to PHPExcel tool, but aware of import and export system by PHP. I know how to import and export data from MySQL to CSV and CSV to MySQL, but now I need something more advance and I found PHPExcel but unfortunately I am not getting any concrete database example with PHPExcel.
I saw few discussion here but they are not actually meeting my requirement.
like - Discussion of PHPExcel
My requirement - I have 5 tables out of 5 I need some selective columns from 4 tables only to be exported in Excel file then 3 more columns will be added in that excel file and data will be filled in those columns after that that excel file will be uploaded to the 5th table of MySQL.

Any guidance or suggestion will help me to accomplish my work.

Thank you all.

New Post: How can I export data from multiple MySQL table to Excel

$
0
0
That data come from a table or four, the technique is the same. As with other types of output, it is preferable to have all of the data retrieved by a single query if they are intended to supply the same stream (here, the same sheet), otherwise, it must implement a mechanism to align.

To read the file completed, one of the examples in the chapter 4.5.5 is a base. Instead of displaying the result, should build the proper query to populate the table.

The main difficulties concern the formatting of data, in particular the dates/times.
Viewing all 2707 articles
Browse latest View live


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