将数据导出到EXCEL时如何设定单元格的公式

xiao163liu 2006-02-22 09:03:10
我在将数据导出到 EXCEL 时有些单元格需要设定公式,不知道如何操作?请指教,
能够详细告诉bcb如何操纵EXCEL更好。
...全文
258 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
TR@SOE 2006-02-22
  • 打赏
  • 举报
回复
是啊,公式的输入就是字符串输入而已。
lurel 2006-02-22
  • 打赏
  • 举报
回复
其实定义公式,就是把该表格是值写成公式就行了
例如:
sht.OlePropertyGet("Cells",j+2,i+1).OlePropertySet("Value","=SUM(A:A)");
下面是从一个Grid取数是导入Excel的代码
if(bsSkinSaveDialog1->Execute())
{
Variant ex,wk,sht,Range; //ole万能变量,定义excel对象使用

try
{
ex=CreateOleObject("Excel.Application"); //启动Excel
wk=ex.OlePropertyGet("ActiveWorkBook");//创建工作簿对象
ex.OlePropertyGet("WorkBooks").OleFunction("Add");//添加一个工作薄
sht=ex.OlePropertyGet("ActiveSheet");//创建工作区
}
catch(...)
{
MessageDlg("无法启动Excel,可能尚未安装或文件已经损坏!",mtError,TMsgDlgButtons()<<mbYes,0);
return;
}



ex.OlePropertySet("Caption","查询结果转入EXCEL:");
ex.OlePropertySet("StatusBar"," 电话:xxxxx mail:xxxx");
sht.OlePropertySet("Name", "应缴汇总");
bsSkinDBGrid1->DataSource->DataSet->First();
int j=0;
for(int i=0;i<bsSkinDBGrid1->Columns->Count;i++)
{
sht.OlePropertyGet("Cells",j+1,i+1).OlePropertySet("Value",bsSkinDBGrid1->Columns->Items[i]->Title->Caption.c_str());
}
while(!bsSkinDBGrid1->DataSource->DataSet->Eof)
{
for(int i=0;i<bsSkinDBGrid1->Columns->Count;i++)
{
sht.OlePropertyGet("Cells",j+2,i+1).OlePropertySet("NumberFormatLocal","@");
sht.OlePropertyGet("Cells",j+2,i+1).OlePropertySet("Value",bsSkinDBGrid1->Columns->Items[i]->Field->AsString.c_str());
}
j++;
bsSkinDBGrid1->DataSource->DataSet->Next();
}


// Range .OlePropertySet("RowHeight", 20); //行高

sht.OleFunction("SaveAs",bsSkinSaveDialog1->FileName.c_str()); //表格保存

ex.OlePropertySet("Visible",(Variant)true); //使Excel可见
}

13,826

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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