BCB中,图片导出到EXCEL不同版本效果不同,求救!!!
我要达到的目的是:记录都是数据库中有的,图片是从某个机器下载后放在本机的固定目录中,然后将记录和对应的图片导出到EXCEL中,但是,在WINXP+EXCEL2003中图片放置的很吻合对应的单元格,而在WIN7+EXCEL2007中,某些图片吻合单元格,某些图片高度不受控制的超出了对应的单元格很多。请妖哥等高手帮忙看看是什么问题。部分代码如下:
//打开固定模板
vExcelApp.OlePropertyGet("Workbooks").OleFunction("Open", WideString(strXlsFile1));
Variant vSheet = vExcelApp.OlePropertyGet("ActiveWorkbook")
.OlePropertyGet("Sheets", 1);
//根据记录数,用复制粘贴某行的方法扩大模板的行数
int xcount = 0,xpos = 0;
xcount = cxQry->RecordCount;
xpos = xcount;
while (xpos >=3){
vSheet.OlePropertyGet("Rows","3:3").OleProcedure("Select");
vExcelApp.OlePropertyGet("Selection").OleProcedure("Copy");
vExcelApp.OlePropertyGet("Selection").OleProcedure("Insert",-4121);
xpos--;
}
AnsiString jestr = 0,sTemp = "";
cxQry->First();
for (int i=0;i<xcount;i++){
frmMain->xOpenImage(cxQry->FieldByName("wpbm")->AsString.Trim()+".jpg","0");//下载图片的函数
sTemp = frmMain->sPath+"photo\\"+cxQry->FieldByName("wpbm")->AsString.Trim()+".jpg";
//导出图片的代码
if (FileExists(sTemp)){
vSheet.OlePropertyGet("Cells",3+i,8).OleProcedure("Select");//选择某个格子
vShapeRange = vSheet.OlePropertyGet("Cells",3+i,8);//设置区域为选定的格子
vShape = vSheet.OlePropertyGet("Pictures").OleFunction("Insert",WideString(sTemp));//设定图片对象
vShape.OlePropertySet("Top",vShapeRange.OlePropertyGet("Top"));//设置图片对象
vShape.OlePropertySet("Left",vShapeRange.OlePropertyGet("Left"));
vShape.OlePropertySet("Height",vShapeRange.OlePropertyGet("Height"));
vShape.OlePropertySet("Width",vShapeRange.OlePropertyGet("Width"));
}
//导出数据的代码
vSheet.OlePropertyGet("Cells",3+i,1).OlePropertySet("Value",cxQryorder_no->AsString.Trim().c_str());
vSheet.OlePropertyGet("Cells",3+i,2).OlePropertySet("Value",cxQryxiadanriqi->AsString.Trim().c_str());
cxQry->Next();
}
cxQry->First();
vExcelApp.OlePropertySet("Visible", true);
//打开固定模板
vExcelApp.OlePropertyGet("Workbooks").OleFunction("Open", WideString(strXlsFile1));
Variant vSheet = vExcelApp.OlePropertyGet("ActiveWorkbook")
.OlePropertyGet("Sheets", 1);
//根据记录数,用复制粘贴某行的方法扩大模板的行数
int xcount = 0,xpos = 0;
xcount = cxQry->RecordCount;
xpos = xcount;
while (xpos >=3){
vSheet.OlePropertyGet("Rows","3:3").OleProcedure("Select");
vExcelApp.OlePropertyGet("Selection").OleProcedure("Copy");
vExcelApp.OlePropertyGet("Selection").OleProcedure("Insert",-4121);
xpos--;
}
AnsiString jestr = 0,sTemp = "";
cxQry->First();
for (int i=0;i<xcount;i++){
frmMain->xOpenImage(cxQry->FieldByName("wpbm")->AsString.Trim()+".jpg","0");//下载图片的函数
sTemp = frmMain->sPath+"photo\\"+cxQry->FieldByName("wpbm")->AsString.Trim()+".jpg";
//导出图片的代码
if (FileExists(sTemp)){
vSheet.OlePropertyGet("Cells",3+i,8).OleProcedure("Select");//选择某个格子
vShapeRange = vSheet.OlePropertyGet("Cells",3+i,8);//设置区域为选定的格子
vShape = vSheet.OlePropertyGet("Pictures").OleFunction("Insert",WideString(sTemp));//设定图片对象
vShape.OlePropertySet("Top",vShapeRange.OlePropertyGet("Top"));//设置图片对象
vShape.OlePropertySet("Left",vShapeRange.OlePropertyGet("Left"));
vShape.OlePropertySet("Height",vShapeRange.OlePropertyGet("Height"));
vShape.OlePropertySet("Width",vShapeRange.OlePropertyGet("Width"));
}
//导出数据的代码
vSheet.OlePropertyGet("Cells",3+i,1).OlePropertySet("Value",cxQryorder_no->AsString.Trim().c_str());
vSheet.OlePropertyGet("Cells",3+i,2).OlePropertySet("Value",cxQryxiadanriqi->AsString.Trim().c_str());
cxQry->Next();
}
cxQry->First();
vExcelApp.OlePropertySet("Visible", true);
...全文
相关推荐
c++ builder (BCB) Oracle 导出 Excel 表
通过 odac 访问 oracle 数据库,并将制定的表导出到excel表,通过ole方式导出。
FlexCel FullSource在Delphi/BCB下Excel报表实践
在企业级应用开发中,服务端生成带样式、公式和合并单元格的Excel报表是高频需求。xlsx本质上是一个包含多个XML文件的zip包,直接解析与封装该结构,可以绕开Office依赖。TMS FlexCel Studio正是基于这一原理的成熟组件,支持Delphi和C++Builder,能够高效读写xls/xlsx并导出PDF。其FullSource完整源码包不仅便于调试与定制,也是企业审计的加分项。以TMS.FlexCel.Studio.v6.0.2.0.for.Delphi.BCB.FullSource为例
BCB读取EXCEL文件实例
BCB读取EXCEL文件实例,直接从EXCEL里面读取出信息并显示出来!
bcb.rar_bcb EXCEL_bcb word_listview excel_word bcb
如何把listview里的内容导出到word和excel中(转载)
BCB调用EXCEL方法及实例
BCB调用EXCEL方法及实例


