By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

output to spreadsheet - how to use format?

P: n/a
I use OpenOffice but I suppose similar formatting rules apply to MS Excel.
For example, to format a cell for two digit numbering, the format code is:

#,##0.00

I can use formulas (=F$temp + 5) and there's likely a way to write
formatting strings in the output code, I just need a little help. Any
ideas?

My code is fairly typical to export to spreadsheet:
//get data from database
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"my-data.xls\"");
$data = "";
$temp = 0;
foreach($r as $row) {
$temp++;
$data .= $row['data1'].",".$row['some_number'].",=F$temp + 5\r\n";
};
echo $data;
Jun 7 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Paul wrote:
I can use formulas (=F$temp + 5) and there's likely a way to write
formatting strings in the output code, I just need a little help. Any
ideas?
I can't say I'm entirely sure what you're asking for, but I think
sprintf() might be able to help.

http://www.php.net/sprintf

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 104 days, 17:46.]

URLs in demiblog
http://tobyinkster.co.uk/blog/2007/05/31/demiblog-urls/
Jun 8 '07 #2

P: n/a
On Jun 7, 7:33 pm, "Paul" <l...@invalid.comwrote:
I use OpenOffice but I suppose similar formatting rules apply to MS Excel.
For example, to format a cell for two digit numbering, the format code is:

#,##0.00

I can use formulas (=F$temp + 5) and there's likely a way to write
formatting strings in the output code, I just need a little help. Any
ideas?

My code is fairly typical to export to spreadsheet:
//get data from database
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"my-data.xls\"");
$data = "";
$temp = 0;
foreach($r as $row) {
$temp++;
$data .= $row['data1'].",".$row['some_number'].",=F$temp + 5\r\n";};

echo $data;
I'm not sure OOo can do the same thing, but how I format for Excel is
pretty simple. What I do is create a new spreadsheet with some sample
data formatted to look how I want, then Save As... as XML. You can
then open the file up in any text editor to see the xml code and from
there you should be able to figure out how to format the way you
want.

In fact, this is the way I do all my excel stuff now, since it's much
easier this way. Just create a mock-up, then recreate the same thing
programmatically.

Jun 8 '07 #3

P: n/a
"Moot" <us****@mootsoft.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
On Jun 7, 7:33 pm, "Paul" <l...@invalid.comwrote:
>I use OpenOffice but I suppose similar formatting rules apply to MS
Excel.
For example, to format a cell for two digit numbering, the format code
is:

#,##0.00

I can use formulas (=F$temp + 5) and there's likely a way to write
formatting strings in the output code, I just need a little help. Any
ideas?

My code is fairly typical to export to spreadsheet:
//get data from database
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"my-data.xls\"");
$data = "";
$temp = 0;
foreach($r as $row) {
$temp++;
$data .= $row['data1'].",".$row['some_number'].",=F$temp + 5\r\n";};

echo $data;

I'm not sure OOo can do the same thing, but how I format for Excel is
pretty simple. What I do is create a new spreadsheet with some sample
data formatted to look how I want, then Save As... as XML. You can
then open the file up in any text editor to see the xml code and from
there you should be able to figure out how to format the way you
want.

In fact, this is the way I do all my excel stuff now, since it's much
easier this way. Just create a mock-up, then recreate the same thing
programmatically.
That's beautiful - thanks!
Jun 8 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.