2

I have Excel Cell value and Cell position in the database table. Now I want to render these information from database table to web page.

Screenshot:

screenshot

example: database table fields are FieldValue FieldPosition

FieldValues | FieldPosition

100                 A1
200                 B1
username            C1
testing             A2

This is my table details.

Note:cell position is alpha numeric, so sorting will now works.

crusy
  • 1,424
  • 2
  • 25
  • 54
Bharanikumar
  • 25,457
  • 50
  • 131
  • 201
  • 6
    So have you looked at any of the libraries for working with Excel files in PHP such as PHPExcel (http://phpexcel.codeplex.com)? Or are you just hoping that somebody will write the code for you? – Mark Baker Jun 02 '13 at 09:35
  • 1
    Do you have Excel style information to work with? Or is it simply a set of references and values in a database table? – Mark Baker Jun 02 '13 at 09:36
  • Select the data from your database ordered by row than by column from `cellpostion`, then loop through that data echoing it into an HTML table, setting a new row every time the row reference changes – Mark Baker Jun 02 '13 at 09:38
  • I've used PHPExcel in an assignment.... that should work....it's quite a big library – pinkpanther Jun 02 '13 at 10:01
  • 1
    @MarkBaker:I dont want, some one get pain for me, i dont like as well. if you saying like these, then forums are not needed, forums is nothing but sharing thoughts/ideas. if some one know very much on that logic, then they dont come and ask. any way thanks for your nice suggestion, which you provided below. – Bharanikumar Jun 02 '13 at 10:03
  • @MarkBaker: i dont think order by will work, because order by will order the records like a1,2,a3,b1,b2,b3, if i am wrong please guide me. – Bharanikumar Jun 02 '13 at 10:05
  • 1
    @pinkpanther thanks for suggestion. PHPExcel will help us to dislay records from Excel into WEB only know. but my request is little different. i am have these cell values and cell position in the table. now i want display records from DB Table into web. – Bharanikumar Jun 02 '13 at 10:08
  • @Bharanikumar your question is not clear. Update your question describing your problem clearly. – pinkpanther Jun 02 '13 at 10:20
  • @pinkpanther as per request i have updated my question in short – Bharanikumar Jun 02 '13 at 10:31
  • @Bharanikumar Your question makes no sense. Why do you need that 2nd step with "DB Table"? Is there a need to change some data in DB or there is a need to display some data from DB in your web page? I see no difference between your Excel table and expected result. – Deele Jun 02 '13 at 11:08
  • @Deele he said excel file only lasts for few seconds in his server and cannot do that... – pinkpanther Jun 02 '13 at 11:10
  • A straight ORDER BY won't work, you need to split the cellpostion into row and column in your SQL query to use that method... alternatively, a library like PHPExcel will allow you to set each cell individually by its cellpostion, and then render to HTML – Mark Baker Jun 02 '13 at 11:21

2 Answers2

6

Using PHPExcel:

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

// Read data from the database and populate the PHPExcel object
$query = "SELECT cellposition, cellvalue FROM datatable";
if ($result = $mysqli->query($query)) {
    while ($row = $result->fetch_object()) {
        $objPHPExcel->getActiveSheet()
            ->setCellValue(
                $row->cellposition,
                $row->cellvalue
            );
    }
    /* free result set */
    $result->close();
}

// Write the PHPExcel object to browser as HTML
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save('php://output');
exit;
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
0

There are existing libraries for your needs:

PS: You know, this question has been answered previously, you should use search, before asking.

Deele
  • 3,728
  • 2
  • 33
  • 51