Forum Moderators: coopster

Message Too Old, No Replies

Help with PHP Form from CSV

         

bhansel

3:08 pm on Apr 13, 2009 (gmt 0)

10+ Year Member



Hi,

I need some expert php advice! I'm tasked with taking data from a csv file and using php to create a report that will print to the printer.

Should I build a web page with fields to accomplish this?

Sorry...I'm new to php.

Any suggestions would be greatly appreciated?

Thanks!
Beth

Demaestro

4:08 pm on Apr 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Does it print to a printer available to the server or does it print on a remote user's printer?

eelixduppy

4:13 pm on Apr 13, 2009 (gmt 0)



Hello and Welcome to WebmasterWorld!

Here is a thread that could get you started...

[webmasterworld.com...]

rocknbil

4:22 pm on Apr 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboaurd bhasel, a google search for csv php site:webmasterworld.com [google.com] returns some promising results.

Basically you will have to:

- learn to upload a file
- learn to read that file in line by line
- on reading in the line, learn to split up the values if the line using explode() or split(). This can be a tricky one, depending on if the fields are or are not quote-qualified.
- Learn to output the data to the browser in an intelligible fashion
- usually, this task also entails entering the data correctly into a database, but doesn't sound like that's the case here.

You can get a start at W3c Schools [w3schools.com] and the full details of everything you'd need at PHP.net [php.net]

bhansel

4:41 pm on Apr 13, 2009 (gmt 0)

10+ Year Member



Thanks for the replies! Actually, since posting this I think I've found a good solution to what I need to do. I'm looking into using php to print to a word document. That sounds like it would work great but we'll see.

I have about 100 invoices with packing slips that need printing every day.

The printer is here in the office...on a network. I just want to automate our daily invoice printing. So I think I should be able to make a word template and pull the data with php...right?

Thanks!
Beth

eelixduppy

4:48 pm on Apr 13, 2009 (gmt 0)



MS Word classes exist [google.com] for PHP. It's a matter of using them correctly, but what you want should work.

Also, there is a series of printing functions that you may want to use to print: [php.net...]

bhansel

6:23 pm on Apr 13, 2009 (gmt 0)

10+ Year Member



Hi,

I'm working on a document that I need to develop in word using php.

Here is the code I tried as a test:
<?php
//1. Instanciate Word
$word = new COM("word.application") or die("Unable to instantiate Word");
//2. specify the MS Word template document (with Bookmark TODAYDATE inside)
$template_file = "C:/reminder.doc";
//3. open the template document
$word->Documents->Open($template_file);
//4. get the current date MM/DD/YYYY
$current_date = date("m/d/Y");
//5. get the bookmark and create a new MS Word Range (to enable text substitution)
$bookmarkname = "TODAYDATE";
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;
//6. now substitute the bookmark with actual value
$range->Text = $current_date;
//7. save the template as a new document (c:/reminder_new.doc)
$new_file = "c:/reminder_new.doc";
$word->Documents[1]->SaveAs($new_file);
//8. free the object
$word->Quit();
$word->Release();
$word = null;
?>

Here is the error I got:
Fatal error: Class 'COM' not found

What's wrong? Does this mean that Word isn't on the server? What if it's Godaddy...I wonder if they have word on the servers?

Thanks!
Beth

coopster

10:43 am on Apr 14, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Quite possible and you have run into an issue that must be taken into consideration. Rather than program your paper output processing to any particular platform why not use something more portable, such as the portable document format (PDF)? Also, perhaps in the future you may decide to email these invoices and/or packing slips. Most everyone is capable of opening a PDF but many will not be able to open the word doc formatted as you programmed. Just some food for thought.