VC中对office的操作(5)
CArray<int,int&> maxcolwidarr;
for(i = 0; i < colNum; i++)
...{
int maxwid = tablestr[0][i].GetLength();
maxcolwidarr.Add(maxwid);
for(j = 0; j < rowNum; j++)
...{
if(tablestr[j][i].GetLength() > maxcolwidarr[i])
maxcolwidarr[i] = tablestr[j][i].GetLength();
}
}
//填写标格
for(int row = 1; row < rowNum+1; row++)
...{
for(int col = 1; col < colNum+1; col++)
...{
iCell = sheet.GetCells();
iCell.SetItem(COleVariant((short )(row)),
COleVariant((short )(col)),
COleVariant(tablestr[row-1][col-1]));
//iCell.SetColumnWidth(COleVariant((short)(maxcolwidarr[col-1])));
}
}
//设置宽度
for (int z = 0; z < maxcolwidarr.GetSize(); z++)
...{
iCell.AttachDispatch(range.GetItem
(COleVariant((long)1),COleVariant((long)(z+1))).pdispVal);
iCell.SetColumnWidth (COleVariant((long)maxcolwidarr[z]));
}
//保存文件
wbook.SaveAs(COleVariant(strOutExcelFile),
COleVariant((short )(-4143)),
COleVariant(""),
COleVariant(""),
COleVariant((short )(FALSE)),
COleVariant((short )(FALSE)),
0L,
COleVariant((short )(NULL)),
COleVariant((short )(NULL)),
COleVariant((short )(NULL)),
COleVariant((short )(NULL)));
//return
app.Quit();
app.ReleaseDispatch();
wbook.ReleaseDispatch();
wbooks.ReleaseDispatch();
sheet.ReleaseDispatch();
sheets.ReleaseDispatch();
range.ReleaseDispatch();
iCell.ReleaseDispatch();
win.ReleaseDispatch();
}
- 上一篇:VC中的常用的20个方法
- 下一篇:VC6.0编写C/S消息传送程序