Managing Office Douments with PHP

I decided to write a class to manage office documents with PHP.


function write_word() {
	$word = new COM("word.application");
	$word->Visible = 0;
	$word->Selection->PageSetup->LeftMargin = '2"';
	$word->Selection->PageSetup->RightMargin = '2"';

	//Setup the font
	$word->Selection->Font->Name = 'Verdana';
	$word->Selection->Font->Size = 8;

	//Write some text
	$word->Selection->TypeText("This is a test document");
        //Insert an image

	//Save the document as DOC file

	//quit and release COM resources
	$word = null;


function write_excel() {
	$excel = new COM("excel.application");
	$excel->Visible = 0;

	//Create a new workbook
	$wkb = $excel->Workbooks->Add();
	$sheet = $wkb->Worksheets(1);

	//This code adds the text 'myvalue' on row 2, column 4
	$cell = $sheet->Cells(2, 4);
	$cell->value = 'myvalue';


	//close and free resources


function write_ppt() {

	$powerpnt = new COM("powerpoint.application");

	//Creating a new presentation
	$pres = $powerpnt->Presentations->Add();

	//Adds the first slide. "12" means blank slide
	$pres->Slides->Add(1, 12);

	//Adds another slide. "10" means a slide with a clipart and text
	$pres->Slides->Add(2, 10);

	//Adds a textbox
	$pres->Slides[1]->Shapes->AddTextbox(1, 20, 50, 300, 40);

	//Save the document as PPT file

	//free resources and quit powerpoint