Results 1 to 2 of 2

Thread: QT equivalency of perl's pack to EXCEL binary file

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QT equivalency of perl's pack to EXCEL binary file

    I wand to try to stream binary as excel file from a QAbstractItemModel whitout activex on linux.
    people dont like import CSV data... on excel on new Office excel this is a long way, only OpenOffice can import faster csv.


    i found this php/perl way:

    How i can Encapsulate this on a file?


    Qt Code:
    1. ////// write function as perl/php
    2.  
    3. function xlsBOF() {
    4. echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
    5. return;
    6. }
    7.  
    8. function xlsEOF() {
    9. echo pack("ss", 0x0A, 0x00);
    10. return;
    11. }
    12.  
    13. function xlsWriteNumber($Row, $Col, $Value) {
    14. echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
    15. echo pack("d", $Value);
    16. return;
    17. }
    18.  
    19. function xlsWriteLabel($Row, $Col, $Value ) {
    20. $L = strlen($Value);
    21. echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
    22. echo $Value;
    23. return;
    24. }
    To copy to clipboard, switch view to plain text mode 


    compose excel

    Qt Code:
    1. // Query Database
    2. $result=mysql_db_query($dbname,"select id,prename,name,sname,grade from appdata where course='$courseid' and sec='$section'")
    3.  
    4. // Send Header
    5. header("Pragma: public");
    6. header("Expires: 0");
    7. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    8. header("Content-Type: application/force-download");
    9. header("Content-Type: application/octet-stream");
    10. header("Content-Type: application/download");;
    11. header("Content-Disposition: attachment;filename=$courseid-$sec.xls ");
    12. header("Content-Transfer-Encoding: binary ");
    13.  
    14. // XLS Data Cell
    15.  
    16. xlsBOF();
    17. xlsWriteLabel(1,0,"Student Register $semester/$year");
    18. xlsWriteLabel(2,0,"COURSENO : ");
    19. xlsWriteLabel(2,1,"$courseid");
    20. xlsWriteLabel(3,0,"TITLE : ");
    21. xlsWriteLabel(3,1,"$title");
    22. xlsWriteLabel(4,0,"SETION : ");
    23. xlsWriteLabel(4,1,"$sec");
    24. xlsWriteLabel(6,0,"NO");
    25. xlsWriteLabel(6,1,"ID");
    26. xlsWriteLabel(6,2,"Gender");
    27. xlsWriteLabel(6,3,"Name");
    28. xlsWriteLabel(6,4,"Lastname");
    29. $xlsRow = 7;
    30. while(list($id,$prename,$name,$sname,$grade)=mysql_fetch_row($result)) {
    31. ++$i;
    32. xlsWriteNumber($xlsRow,0,"$i");
    33. xlsWriteNumber($xlsRow,1,"$id");
    34. xlsWriteLabel($xlsRow,2,"$prename");
    35. xlsWriteLabel($xlsRow,3,"$name");
    36. xlsWriteLabel($xlsRow,4,"$sname");
    37. $xlsRow++;
    38. }
    39. xlsEOF();
    40. exit();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QT equivalency of perl's pack to EXCEL binary file


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.