vc下如何对excel文件进行读写操作

ljzcom 2003-01-15 05:24:21
vc下如何对excel文件进行读写操作
...全文
57 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyRaccoon 2003-01-16
  • 打赏
  • 举报
回复
找两个文件excel8.h;excel8.cpp(或者excel9.h;excel9.cpp)
_Application app;
Workbooks books;
_Workbook book;
Worksheets sheets;
_Worksheet sheet;

if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't start Excel and get Application object.");
return;
}

app.SetVisible(TRUE);
//app.SetVisible(FALSE);
books = app.GetWorkbooks();

book = books.Add (covOptional);

sheets =book.GetSheets();
//add sheet
sheet = sheets.GetItem(COleVariant((short)1));
sheet.SetName("报表");

int i;
Range range;
Font font;
Interior interior;
Borders borders;
Border border;

//单元格合并
range = sheet.GetRange(COleVariant("A1"), COleVariant("B1"));
range.Merge(COleVariant((short)TRUE));

range.SetRowHeight(COleVariant((short)40));
font = range.GetFont();
font.SetBold(covTrue);
for(i=0;i<linkCount;i++)
{
range = sheet.GetRange(COleVariant(link[i].startPos), COleVariant(link[i].endPos));
interior = range.GetInterior();
borders = range.GetBorders();
borders.SetWeight(COleVariant((short)2)); //xlThin = 2
range.SetColumnWidth(COleVariant((short)30));
//设置有边框,还是无边框
borders.SetLineStyle(COleVariant((short)link[i].borderStyle));


//是项目,字体加粗
font = range.GetFont();
font.SetBold(covTrue);
arvid_gs 2003-01-15
  • 打赏
  • 举报
回复
www.vckbase.net上面有例子

4,012

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧