#2
wube2015-01-12 02:26
|
程序代码:
void AAA(char *A1)
{
_Application app;
Workbooks books;
_Workbook book;
Worksheets sheets;
_Worksheet sheet;
Range range;
Font font;
Range cols;
::CoInitialize(NULL);
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
if( !app.CreateDispatch("Excel.Application") )
AfxMessageBox("Start EXCEL Fail!");
books=app.GetWorkbooks();
book=books.Add(covOptional);
sheets=book.GetSheets();
sheet=sheets.GetItem(COleVariant((short)1));
sheet.SetName("AAA");
range=sheet.GetRange(COleVariant("A1"),COleVariant("A1"));//<--改成指定格子
range.SetValue2(COleVariant("HELLO EXCEL!"));
font=range.GetFont();
font.SetBold(COleVariant((short)TRUE));
range=sheet.GetRange(COleVariant("A2"),COleVariant("A2"));//<--改成指定格子
range.SetFormula(COleVariant("=RAND()*100000"));
range.SetNumberFormat(COleVariant("$0.00"));
cols=range.GetEntireColumn();
cols.AutoFit();
app.SetVisible(TRUE);
app.SetUserControl(TRUE);
}