delphi dbgrid中的数据如何导入到excel表中?
查了不少关於这方面的资料,始终没有找到一个能用的。能否有高手帮我一下,步骤说明尽可能的详细点。。。谢谢``,我笨着呢。。...
查了不少关於这方面的资料,始终没有找到一个能用的。
能否有高手帮我一下,步骤说明尽可能的详细点。。。
谢谢``,我笨着呢。。 展开
能否有高手帮我一下,步骤说明尽可能的详细点。。。
谢谢``,我笨着呢。。 展开
展开全部
这个问题很难,我粘贴一段我从excel中读数据的代码:
try
{
Variant v1;
ExcelApplication->Connect();
ExcelApplication->set_WindowState(0, xlMinimized);
//ExcelApplication->set_Visible(0, true);
try
{
Form5 = new TForm5(Application);
Form5->ShowModal();
delete Form5;
ExcelApplication->set_Visible(0, showexcel);
ExcelApplication->Workbooks->Open(StringToOleStr(OpenDialog1->FileName.c_str()));
ExcelApplication->set_Caption(StringToOleStr(OpenDialog1->FileName));
ExcelWorkbook->ConnectTo(ExcelApplication->Workbooks->get_Item(Variant(1)));
ExcelWorksheet->ConnectTo(ExcelWorkbook->Worksheets->get_Item(Variant(isheet)));
for(int i = 1; i < sRow; ++i)
for(int j = 1; j < sCol; ++j)
{
v1 = ExcelWorksheet->Cells->get_Item(Variant(i), Variant(j));
if(!v1.Empty())
StringGrid1->Cells[j][i] = VarToStr(v1);
}
openfile = true;
//Form2 = new TForm2(Application);
Form2->Show();
caled = false;
}
catch(Exception &exception)
{
ShowMessage("打开工作表错误!");
ExcelApplication->Quit();
ExcelApplication->Disconnect();
}
}
catch(Exception &exception)
{
ShowMessage("安装Excel了吗?");
}
try
{
Variant v1;
ExcelApplication->Connect();
ExcelApplication->set_WindowState(0, xlMinimized);
//ExcelApplication->set_Visible(0, true);
try
{
Form5 = new TForm5(Application);
Form5->ShowModal();
delete Form5;
ExcelApplication->set_Visible(0, showexcel);
ExcelApplication->Workbooks->Open(StringToOleStr(OpenDialog1->FileName.c_str()));
ExcelApplication->set_Caption(StringToOleStr(OpenDialog1->FileName));
ExcelWorkbook->ConnectTo(ExcelApplication->Workbooks->get_Item(Variant(1)));
ExcelWorksheet->ConnectTo(ExcelWorkbook->Worksheets->get_Item(Variant(isheet)));
for(int i = 1; i < sRow; ++i)
for(int j = 1; j < sCol; ++j)
{
v1 = ExcelWorksheet->Cells->get_Item(Variant(i), Variant(j));
if(!v1.Empty())
StringGrid1->Cells[j][i] = VarToStr(v1);
}
openfile = true;
//Form2 = new TForm2(Application);
Form2->Show();
caled = false;
}
catch(Exception &exception)
{
ShowMessage("打开工作表错误!");
ExcelApplication->Quit();
ExcelApplication->Disconnect();
}
}
catch(Exception &exception)
{
ShowMessage("安装Excel了吗?");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询