Показать сообщение отдельно
Старый 11.06.2004, 19:55   #5  
raz is offline
raz
NavAx
Аватар для raz
NavAx Club
Лучший по профессии 2014
Лучший по профессии 2009
 
1,495 / 1070 (38) ++++++++
Регистрация: 22.07.2003
Адрес: МО
http://www.navision.net/forum/topic.asp?TOPIC_ID=11002

PS. Процитирую, а то там сервер редко, но бывает недоступен.

PPS. Пути в примере содержать вместо одного бак слеша два (\\). Их форум съел.

PHP код:
NOTE 1it expects an image named c:\temp\hello.bmp to exist.
NOTE 2Be careful debugging this stuff, if execution is discontinued and
comWorkBooks.close() and comApplication.quit() are not called,
you will need to manually kill the EXCEL.EXE process in the task manager.

COM comApplication;
COM comWorkbooks;
COM comWorkbook;
COM comWorksheet;
COM comShapes;

COMVariant variant = new COMVariant();
COMVariant xpos = new COMVariant();
COMVariant ypos = new COMVariant();
COMVariant state = new COMVariant();
COMVariant width = new COMVariant();
COMVariant height = new COMVariant();

SysExcelWorksheet excelWorksheet;
SysExcelCells excelCells;
;

//Create the Excel app and grab the workbooks
comApplication = new COM('Excel.application');
comWorkBooks comApplication.workbooks();

//Wrap the rest in an exception to make sure excel is closed
try
{
//Create a new workbook and get a reference to it
variant.int(-4167);
comWorkBook comWorkBooks.add(variant);
comWorkSheet comApplication.activeSheet();
//Add some text to the worksheet
excelWorksheet SysExcelWorkSheet::construct(MSOfficeVersion::Office2000comWorksheet);
excelCells excelWorksheet.cells();
excelCells.item(10,1).value("Hello world");

//Set up image parameters
variant.bStr("c:\\temp\\hello.bmp");
xpos.int(1);
ypos.int(1);
state.int(1);
width.int(100);
height.int(100);
//Add the image to the worksheet
comShapes comWorkSheet.shapes();
comShapes.addPicture(variant,xpos,ypos,state,state,width,height);

//Autofitt and protect the sheet
excelworksheet.columns().autoFit();
excelWorksheet.protect('',true,true);

//Save the sheet and close the app
comWorkBook.saveas("c:\\temp\\hello.xls");
comWorkBooks.close();
comApplication.quit();
}
catch(
Exception::Error)
{
//Force app to quit
comWorkBook.saveas("c:\\temp\\hello.xls");
comWorkBooks.close();
comApplication.quit();