Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    inserting sql output rows to excel file

    hi,

    i have 150 rows and 40 columns in a sql table..i am displaying the entire table in a web page..now,what i want to do is create a link on that web page that will take the entire table and insert it in an excel file(dosn't matters if it creates a new excel file,or modifies sum exisiting one)...now i can do it manually by using(PHPExcel library)," objPHPExcel->setCellValue('C5', $v) "...but i would have to write this like 40 times(change '$v' variable in every statment) nd its inside a loop that will run 150 times..hence i dont wanna do it this way..

    now i wanted to know if i can insert the table,row by row in the excel sheet..like when i insert a row,it will insert the entire cells of d row..that way it will be pretty easy..so i wanted to know if there any specific commands for doing this..

    if not,wat other alternatives do i have of doing this..all i want to do is to export the entire sql table to an excel file using php..

  • #2
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you need to do bit of excel cell programming i.e you need to adjust cell value using loop for the column first that can be done by using loop 1 to 40. now column in excel are alpha numeric. so there is a trick which you can use here for column . each alphabet has ascii value. so from 65 to 91 (A-Z ) you can run loop for (i= 1; i<= 40; i++){ if (i< 26) {objPHPExcel->setCellValue(Concatenate(Char(i+64),5) , $v); } else{ objPHPExcel->setCellValue(Concatenate(Concatenate('A',Char(i+64)),5);}}. You can convert ascii to character/number using char() function. also you convert back from character to ascii using asc() function. if you want to navigate through rows simply separate alphabet part from numeric part in the loop and increment or decrement the numeric part then concatenate back the alphabet part with numeric part.

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    So where is the code? This forum is for sharing code that works so that others can use it to do the same. It is not for asking questions.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,090
    Thanks
    2
    Thanked 23 Times in 23 Posts
    I have moved this thread to the PHP forum.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •