VC6.0导出内容到excel的简单代码例子,具体方法没有记录

	// TODO: Add extra validation here
	_Application app;
	Workbooks books;
	_Workbook book;
	Worksheets sheets;
	_Worksheet sheet;
	Range range;
	Font font;
	Range cols;

	COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

	if (!app.CreateDispatch("Excel.Application"))
	{
		this->MessageBox("无法创建Excel应用!");
		return;
	}

	books = app.GetWorkbooks();
	book = books.Add(covOptional);
	sheets = book.GetSheets();
	sheet = sheets.GetItem(COleVariant((short)1));

	range = sheet.GetRange(COleVariant("A1"), COleVariant("A10"));
	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);

你可能感兴趣的:(VC6.0导出内容到excel的简单代码例子,具体方法没有记录)