描述:
现在需要用vc写一个读取指定的Excel模板,然后查找指定字符,进行替换,最后直接打印该页。注意不保存。
看过以前的帖子,应该不难,但是没有一个人能给出比较详细的例子,vckbase上的我都看过乐,并没有符合要求。
不知道哪位高手&热心人能给一段例程?谢谢了,分不够再加。
解决方案1:
COleVariant vtOptional((long)DISP_E_PARAMNOTFOUND,
VT_ERROR),vtTrue((short)TRUE),vtFalse((short)FALSE);
_Application *ExcelApp = new _Application;
ExcelApp->CreateDispatch("excel.application");
//设置为显示
ExcelApp->SetVisible(TRUE);
//得到WorkBooks
Workbooks ExcelBook=ExcelApp->GetWorkbooks();
Sheets ExcelSheet=ExcelBook.Add(vtOptional);
_Workbook workBook;
_Worksheet workSheet;
Range range;
workBook.AttachDispatch(ExcelApp->GetApplication());
ExcelSheet=workBook.GetSheets();
////////////////////////////////////////////
workSheet=ExcelSheet.GetItem(COleVariant((short)1));
workSheet.Activate();
Range myallrange=workSheet.GetRange(COleVariant("A1"),COleVariant("D1"));
//myallrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myallrange.SetHorizontalAlignment(COleVariant((short)3));
myallrange.Merge(COleVariant((short)1));
myallrange.SetValue(COleVariant("个人信息表"));
Range myrange=workSheet.GetRange(COleVariant("A2"),COleVariant("A2"));
myrange.SetValue(COleVariant("姓名"));
myrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myrange.SetHorizontalAlignment(COleVariant((short)3));
myrange.SetVerticalAlignment(COleVariant((short)2));
myrange.SetColumnWidth(COleVariant((short)15));
myrange=workSheet.GetRange(COleVariant("B2"),COleVariant("B2"));
myrange.SetValue(COleVariant("性别"));
myrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myrange.SetHorizontalAlignment(COleVariant((short)3));
myrange.SetVerticalAlignment(COleVariant((short)2));
myrange.SetColumnWidth(COleVariant((short)15));
myrange=workSheet.GetRange(COleVariant("C2"),COleVariant("C2"));
myrange.SetValue(COleVariant("QQ"));
myrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myrange.SetHorizontalAlignment(COleVariant((short)3));
myrange.SetVerticalAlignment(COleVariant((short)2));
myrange.SetColumnWidth(COleVariant((short)15));
myrange=workSheet.GetRange(COleVariant("D2"),COleVariant("D2"));
myrange.SetValue(COleVariant("Email"));
myrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myrange.SetHorizontalAlignment(COleVariant((short)3));
myrange.SetVerticalAlignment(COleVariant((short)2));
myrange.SetColumnWidth(COleVariant((short)17));
CString str;
for(int i=3;i<=5;i++)
{
str.Format("A%d",i);
Range myrange=workSheet.GetRange(COleVariant(str),COleVariant(str));
myrange.SetValue(COleVariant("相生昌"));
myrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myrange.SetHorizontalAlignment(COleVariant((short)3));
myrange.SetVerticalAlignment(COleVariant((short)2));
str.Format("B%d",i);
myrange=workSheet.GetRange(COleVariant(str),COleVariant(str));
myrange.SetValue(COleVariant("男"));
myrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myrange.SetHorizontalAlignment(COleVariant((short)3));
myrange.SetVerticalAlignment(COleVariant((short)2));
str.Format("C%d",i);
myrange=workSheet.GetRange(COleVariant(str),COleVariant(str));
myrange.SetValue(COleVariant("16432884"));
myrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myrange.SetHorizontalAlignment(COleVariant((short)3));
myrange.SetVerticalAlignment(COleVariant((short)2));
str.Format("D%d",i);
myrange=workSheet.GetRange(COleVariant(str),COleVariant(str));
myrange.SetValue(COleVariant("superxsc@126.com"));
myrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myrange.SetHorizontalAlignment(COleVariant((short)3));
myrange.SetVerticalAlignment(COleVariant((short)2));
}
delete ExcelApp;
http://www.vckbase.com/document/viewdoc/?id=1168
至于打印,应该不是什么难事,没做过,懒得试试,望楼主见谅