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

New Post: Low-level Differences vs Native Format

$
0
0
I've found an ugly workaround to at least get us by for now.

Basically, I wrote a VBS script that will loop through the created Excel files, open them, and then re-save them to the same location. Definitely inelegant, and I'd much rather have a way of creating the file with whatever "native" bits are missing in the first place.

The workaround requires the COM function of PHP, and knowledge of the specific directory where these files are being created.

PHP Code:
($db.$i is a randomly-generated file name, incremented $loop times earlier in the code)
for ($i=1;$i<$loop;$i++){
    $runfile="wscript.exe D:\\htdocs\\Loadsheet\\output\\saveXLS.vbs \"D:\\htdocs\\Loadsheet\\output\\".$db.$i.".xls\"";
    $wait = true;  // similar to start /w in DOS, set to false for no wait
    $obj = new COM ( 'WScript.Shell' ); 

    if ( is_object ( $obj ) ) 
    { 
        $obj->Run ( 'cmd /C ' . $runfile, 0, $wait ); 
    } 
    else 
    { 
        echo 'can not create wshell object'; 
    } 

    $obj = null;
    }
saveXLS.vbs:
Set args = Wscript.Arguments
wit= args(0)
Dim SpreadSheet
SpreadSheet = wit
 
Set objExcel = CreateObject("Excel.Application") 
Set objWorkbook = objExcel.Workbooks.Open(Spreadsheet)  'open via passed parameter
 
Set objRange = objworkbook.worksheets(1).columns(1)  ' this does nothing, but sets focus so re-save works
 
objworkbook.save 
objexcel.quit 
It's definitely not the method I want, but it does the trick for now. Considering that this can generate 100+ XLS files per run, it's a huge timesaver from having to open & re-save each one!

If anyone has any better suggestions, please let me know.... thanks!

Viewing all articles
Browse latest Browse all 2707


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