C++ builder 操作Excel方法(据网上资料整理)

2023-02-12,,,,

c++ builder 操作Excel方法,下面是从网上找到的一些不错的方法,学习一下:

 用OLE操作Excel(目前最全的资料)(04.2.19更新)

 本文档部分资料来自互联网,大部分是ccrun(老妖)在Excel中通过录制宏-->察看宏代码-->转为CB代码而来.本文档不断更新中.欢迎大家关注.

 要在应用程序中控制Excel的运行,首先必须在编制自动化客户程序时包含Comobj.hpp

 #include "Comobj.hpp"

 C++ Builder把Excel自动化对象的功能包装在下面的四个Ole Object Class函数中,应用人员可以很方便地进行调用。

 设置对象属性:void        OlePropertySet(属性名,参数……);

 获得对象属性:Variant     OlePropertyGet(属性名,参数……);

 调用对象方法:) Variant OleFunction(函数名,参数……);

              ) void     OleProcedure(过程名,参数……);

 在程序中可以用宏定义来节省时间:

 #define   PG   OlePropertyGet

 #define   PS   OlePropertySet

 #define   FN   OleFunction

 #define   PR   OleProcedure

 举例:

 ExcelApp.OlePropertyGet("workbooks").OleFunction("Add");

 可写为

 ExcelApp.PG("workbooks").FN("Add");

 C++ Builder中使用OLE控制Excel2000,必须掌握Excel2000的自动化对象及Microsoft Word Visual Basic帮助文件中的关于Excel的对象、方法和属性。对象是一个Excel元素,属性是对象的一个特性或操作的一个方面,方法是对象可以进行的动作。

 首先定义以下几个变量:

 Variant ExcelApp,Workbook1,Sheet1,Range1;

 、Excel中常用的对象是:Application,Workbooks,Worksheets等。

 ★创建应用对象★

        Variant ExcelApp;

        ExcelApp = Variant::CreateObject ("Excel.Application");

        或者

        ExcelApp = CreateOleObject ("Excel.Application");

 ★创建工作簿对象★

        Variant WorkBook1;

        WorkBook1 = ExcelApp.PG("ActiveWorkBook");

 ★创建工作表对象★

        Variant Sheet1;

        Sheet1 = WorkBook1.PG("ActiveSheet");

 ★创建区域对象★

        Variant Range;

        Range = Sheet1.PG("Range","A1:A10");    

        或者使用

        Excel.Exec(PropertyGet("Range")<<"A1:C1").Exec(Procedure("Select"));

 、常用的属性操作:

 ★使Excel程序不可见★

        ExcelApp.PS("Visible", (Variant)false);

 ★新建EXCEL文件★

     ◎ 新建系统模板的工作簿

        ExcelApp.PG("workbooks").FN("Add")      //默认工作簿

        ExcelApp.PG("workbooks").FN("Add", )   //单工作表

        ExcelApp.PG("workbooks").FN("Add", )   //图表 

        ExcelApp.PG("workbooks").FN("Add", )   //宏表 

        ExcelApp.PG("workbooks").FN("Add", )   //国际通用宏表

        ExcelApp.PG("workbooks").FN("Add", )   //与默认的相同

        ExcelApp.PG("workbooks").FN("Add", )   //工作簿且只有一个表

        或者使用ExcelApp的Exec方法

        Excel.Exec(PropertyGet("Workbooks")).Exec(Procedure("Add"));

     ◎ 新建自己创建的模板的工作簿

        ExcelApp.PG("workbooks").FN("Add", "C:\\Temp\\result.xlt");

 ★打开工作簿★

        ExcelApp.PG("workbooks").FN("open", "路径名.xls") 

 ★保存工作簿★

        WorkBook1.FN("Save");            //保存工作簿

        WorkBook1.FN("SaveAs", "文件名");//工作簿保存为,路径注意用"\\"

 ★退出EXCEL★

        ExcelApp.FN ("Quit");

        ExcelApp = Unassigned;

        或者

        ExcelApp.Exec(Procedure("Quit"));

 ★操作工作表★

     ◎ 选择选择工作表中第一个工作表

        Workbook1.PG("Sheets", ).PR("Select");

        Sheet1 = Workbook1.PG("ActiveSheet");

     ◎ 重命名工作表

        Sheet1.PS("Name", "Sheet的新名字");

     ◎ 当前工作簿中的工作表总数

 // 本文转自 C++Builder 研究 - http://www.ccrun.com/article.asp?i=529&d=0iezy5

        int nSheetCount=Workbook1.PG("Sheets").PG("Count");       

 ★操作行和列★

     ◎ 获取当前工作表中有多少行和多少列:

        Sheet1.PG("UsedRange").PG("Columns").PG("Count"); //列数

        Sheet1.PG("UsedRange").PG("Rows").PG("Count");    //行数

     ◎ 设置列宽

        ExcelApp.PG("Columns", ).PS("ColumnWidth", );

        或者

        Range = ExcelApp.PG("Cells", , );

        Range.PS("ColumnWidth", );      

     ◎ 设置行高

        ExcelApp.PG("Rows", ).PS("RowHeight", );

        或者

        Range = ExcelApp.PG("Cells", , );        

        Range.PS("RowHeight", );     

     ◎ 在工作表最前面插入一行

        Sheet1.PG("Rows", ).PR("Insert");        

     ◎ 删除一行

        ExcelApp.PG("Rows", ).PR("Delete"); //将第2行删除

        // 本文作者:ccrun ,如转载请保证本文档的完整性,并注明出处。

        // 欢迎光临 C++ Builder 研究 www.ccrun.com

        // 摘自:http://www.ccrun.com/doc/go.asp?id=529

 ★操作单元格★

     ◎ 设置单元格字体

         Sheet1.PG("Cells", , ).PG("Font").PS("Name", "隶书"); //字体

         Sheet1.PG("Cells", , ).PG("Font").PS("size", );     //大小

     ◎ 设置所选区域字体

        Range.PG("Cells").PG("Font").PS("Size", );

        Range.PG("Cells").PG("Font").PS("Color", RGB(, , ));

        其中参数的设置:

        Font   Name : "隶书"               //字体名称

               Size :                    //字体大小

              Color : RGB(*,*,*)           //颜色

          Underline : true/false           //下划线

              Italic: true/false           //斜体

     ◎ 设置单元格格式为小数百分比

        Sheet1.PG("Cells", , ).PS("NumberFormatLocal", "0.00%");

     ◎ 设定单元格的垂直对齐方式

        Range = ExcelApp.PG("Cells", , );

        // 1=靠上 2=居中 3=靠下对齐 4=两端对齐 5=分散对齐

        Range.PS("VerticalAlignment", );       

     ◎ 设定单元格的文本为自动换行

        Range = ExcelApp.PG("Cells", , );

        Range.PS("WrapText", true);

 ★单元格的合并★

     ◎ Range = Sheet1.PG("Range", "A1:A2");          //A1和A2单元格合并

        String strRange = "A" + IntToStr(j) + ":" + "C" + IntToStr(j); //比如:A1:C5

        Range1=Sheet1.PG("Range", strRange.c_str()); //可以用变量控制单元格合并

        Range1.FN("Merge", false);

 ★读写单元格★

     ◎ 指定单元格赋值

        String strValue = "abcdefg";

        Sheet1.PG("Cells", , ).PS("Value", strValue.c_str()); 

        Sheet1.PG("Cells", j, ).PS("Value", "总记录:" + String(j-));

        或者使用

        Excel.Exec(PropertyGet("Cells")<<<<).Exec(PropertySet("Value")<<);

     ◎ 所选区域单元格赋值

        Range.PG("Cells").PS("Value", );    

     ◎ 所选区域行赋值

        Range.PG("Rows",).PS("Value", ); 

     ◎ 工作表列赋值

        Sheet1.PG("Columns",).PS("Value", );

     ◎ 读取取值语句:

        String strValue = Sheet1.PG("Cells", , ).PG("Value");

 ★窗口属性★

     ◎ 显示属性

        ExcelApp.PS("Windowstate", );       //最大化显示

               ---------xlNormal            //正常显示

               ---------xlMinimized         //最小化显示

               ---------xlMaximized         //最大化显示

     ◎ 状态栏属性

        ExcelApp.PS("StatusBar", "您好,请您稍等。正在查询!");

        ExcelApp.PS("StatusBar", false);     //还原成默认值

     ◎ 标题属性:

        ExcelApp.PS("Caption", "查询系统");

 、操作图表

 ★添加图表

      Variant Chart; 

      Chart = ExcelApp.Exec(PropertyGet("Charts")).Exec(Function("Add"));

      ExcelApp.Exec(PropertySet("Visible") << true);

      Chart.Exec(PropertySet("Type") << -);

 ★滚动图表

      for(int nRotate=; nRotate <= ; nRotate += )

      {

           Chart.Exec(PropertySet("Rotation") << nRotate);

      }

      for (int nRotate = ; nRotate >= ; nRotate -= )

      {

           Chart.Exec(PropertySet("Rotation") << nRotate);

      }

 另外,为保证程序能正常运行,需要在程序中判断目标机器是否安装了Office;

 try

 {

     ExcelApp = Variant::CreateObject ("Excel.Application");

 }

 catch(...)

 {

     ShowMessage("运行Excel出错,请确认安装了Office");

     return;

 }

 #include "comobj.hpp"

 //---------------------------------------------------------------------------

 // 对指定Excel文件中的指定列进行排序

 // strExcelFileName : excel文件名

 // nCol : 指定的列号

 // nSortStyle : 1:升序,2:降序

 void SortExcelColumn(String strExcelFileName, int nCol, int nSortStyle)

 {

     Variant vExcelApp, vWorkbook, vRange;

     vExcelApp = Variant::CreateObject("Excel.Application");

     vExcelApp.OlePropertySet("Visible", false);

     vExcelApp.OlePropertyGet("WorkBooks").OleProcedure("Open", strExcelFileName.c_str());

     vWorkbook = vExcelApp.OlePropertyGet("ActiveWorkbook");

     vExcelApp.OlePropertyGet("Columns", nCol).OleProcedure("Select");

     vExcelApp.OlePropertyGet("ActiveSheet").OlePropertyGet("Cells", , nCol).OleProcedure("Select");

     vRange = vExcelApp.OlePropertyGet("Selection");

     vRange.Exec(Function("Sort")<<vExcelApp.OlePropertyGet("Selection")<<nSortStyle);

     vWorkbook.OleProcedure("Save");

     vWorkbook.OleProcedure("Close");

     vExcelApp.OleFunction("Quit");

     vWorkbook = Unassigned;

     vExcelApp = Unassigned;

     ShowMessage("ok");

 }

 void __fastcall TForm1::Button1Click(TObject *Sender)

 {

     // 对C:\123\123.xls文件中第一个Sheet的第四列进行升序排序

     SortExcelColumn("C:\\123\\123.xls", , );

 }

 excel打印页面设置

 //excel_app.OlePropertyGet("ActiveWindow").OlePropertySet("DisplayGridlines",False);   //不显示背景的网格线;   

       my_worksheet.OlePropertyGet("PageSetup").OlePropertySet("CenterHorizontally",/0.035);//页面水平居中:   

       my_worksheet.OlePropertyGet("PageSetup").OlePropertySet("PrintGridLines",true);//打印表格线;   

       my_worksheet.OlePropertyGet("PageSetup").OlePropertySet("Orientation",);   //Orientation=poLandscape;1;2为横向;   

       excel_app.OlePropertyGet("ActiveWindow").OlePropertyGet("SelectedSheets").OleFunction("PrintPreview");//打印预览

 给你个完整的例子:   

 #include   "comobj.hpp"   

 void   __fastcall   TForm1::Button1Click(TObject   *Sender)   

 {   

           Variant   vExcelApp,   vSheet;   

           AnsiString   strFileName   =   "C:\\123\\123.xls";   

           if(!FileExists(strFileName))   

                   return;   

           //   启动excel   

           vExcelApp   =   CreateOleObject("Excel.Application");   

           //   使Excel程序不可见   

           vExcelApp.OlePropertySet("Visible",   true);   

           //   打开Excel文档   

           vExcelApp.OlePropertyGet("Workbooks").   

                           OleFunction("Open",   strFileName.c_str());   

           //   获得当前活动的Sheet   

           vSheet   =   vExcelApp.OlePropertyGet("ActiveSheet");   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("PrintTitleRows",   "");   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("PrintTitleColumns",   "");   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("PrintArea",   "");   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("LeftHeader",   "");   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("CenterHeader",   "");   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("RightHeader",   "");   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("LeftFooter",   "");   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("CenterFooter",   "");   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("RightFooter",   "");   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("LeftMargin",   0.748031496062992);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("RightMargin",   0.748031496062992);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("TopMargin",   0.984251968503937);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("BottomMargin",   0.984251968503937);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("HeaderMargin",   0.511811023622047);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("FooterMargin",   0.511811023622047);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("PrintHeadings",   false);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("PrintGridlines",   false);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("PrintComments",   -);   //   xlPrintNoComments   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("PrintQuality",   );   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("CenterHorizontally",   true);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("CenterVertically",   false);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("Orientation",   );   //   xlPortrait   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("Draft",   false);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("PaperSize",   );   //   xlPaperA4   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("FirstPageNumber",   -);   //   xlAutomatic   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("Order",   );   //   xlDownThenOver   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("BlackAndWhite",   false);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("Zoom",   false);   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("FitToPagesWide",   );   

           vSheet.OlePropertyGet("PageSetup").OlePropertySet("FitToPagesTall",   );   

           //   保存这个工作簿   

           vExcelApp.OlePropertyGet("ActiveWorkBook").OleProcedure("Save");   

           //   退出Excel程序   

           vExcelApp.OleFunction("Quit");   

           ShowMessage("设置成功!");   

     }

另一实现:http://bbs.csdn.net/topics/360155474

 // Access数据库文件名
String strMdbFile = "D:\\ccrun\\222.mdb";
// Access数据库中的表名
String strTableName = "t1"; // Excel文件名
String strXlsFile = "D:\\ccrun\\222.xls";
// Excel文件中的Sheet名
String strSheetName = "Sheet1"; // 先连接Access数据库
// 63 63 72 75 6E 2E 63 6F 6D
String strConn = String().sprintf(
TEXT("Provider=Microsoft.Jet.OLEDB.4.0;")
TEXT("Data Source=%s;")
TEXT("Persist Security Info=False"),
strMdbFile.c_str()
); ADOConnection1->Connected = false;
ADOConnection1->ConnectionString = strConn;
try
{
ADOConnection1->Connected = true;
}
catch(...)
{
ShowMessage("连接失败!");
return;
} // 将Excel文件中的数据导入到Access中
String strSQL = String().sprintf(
TEXT("Insert into [%s] ")
TEXT("SELECT * FROM [Excel 5.0;HDR=NO;DATABASE=%s].[%s$];"),
strTableName.c_str(), strXlsFile.c_str(), strSheetName.c_str()
);
ADOConnection1->Execute(strSQL);

还有一个也可以参考一下:

使用方法,把下面的RtpExcel中的RtpExcel.h段存成文件RtpExcel.h,
RtpExcel.c存成文件RtpExcel.c并保存,加入到C++Builder的工程中即可使用。 /*
RtpExcel.h
*/
//---------------------------------------------------------------------------
#ifndef RptExcelH
#define RptExcelH
#include <utilcls.h>
struct RptPageSetup
{
String sLeftHeader;
String sLeftFooter;
String sCenterheader;
String sRightHeader;
String sRightFooter;
String sCenterFooter;
};
struct RptInf
{
RptPageSetup RptPage;
String tTitle;
String tFirstRowL;
String tFirstRowR;
};
class CRptExcel
{
public:
CRptExcel();
~CRptExcel();
//从sBeginRow行开始设置数据并初始化边框
bool SetData(const RptInf& rInf,TDataSet* pSet);
bool PrintRpt();
private:
//初始化应用程序对象
bool InitApp();
//设置excel程序对象的可见性
bool SetAppVisible(bool bVisible); private:
bool SetCellBorder(); bool SetInfTable();
bool SetInfCom();
bool SetTitle();
bool SetTopRow();
bool SetCellValue();
bool NewWorkBook();
bool NewExcelApp(); private:
TDataSet *m_pSet;
Variant m_ExcelApp;
Variant m_Sheet;
Variant m_WorkBook;
Variant m_Range;
unsigned int m_RowLast;
unsigned int m_RowBegin;
char m_cBegin;
char m_cEnd;
unsigned int m_RowCount;
unsigned int m_ColCount;
String m_sTitle;
String m_sCompanyInf;
String m_sA3Content;
String m_sLastCol3Content;
bool m_bAppRun;
private:
String m_sError;
};
//---------------------------------------------------------------------------
#endif //---------------------------------------------------------------------------
/*
RptExcel.c
*/ #include <vcl.h>
#pragma hdrstop
#include "Excel_2K_SRVR.h" #include "RptExcel.h"
CRptExcel::CRptExcel()
{
m_pSet=NULL;
m_bAppRun=false;
}
CRptExcel::~CRptExcel()
{
if(m_bAppRun)
{
m_ExcelApp.OleFunction ("Quit");
}
}
bool CRptExcel::PrintRpt()
{
if(!InitApp()) return false;
if(!SetCellValue()) return false;
if(!SetCellBorder()) return false;
if(!SetTitle()) return false;
if(!SetInfCom()) return false;
if(!SetInfTable()) return false;
if(!SetTopRow()) return false;
SetAppVisible(true);
return true;
}
bool CRptExcel::InitApp()
{
if(!NewExcelApp()) return false;
if(!NewWorkBook()) return false;
return true;
}
bool CRptExcel::NewExcelApp()
{
try
{
m_ExcelApp = Variant::CreateObject("excel.application");
m_bAppRun=true;
}
catch(...)
{
m_sError="不能初始化Excel应用程序对象!";
return false;
}
return true;
}
bool CRptExcel::NewWorkBook()
{
Variant all_workbooks;
//-- Get workbooks collection
all_workbooks = m_ExcelApp.OlePropertyGet("Workbooks");
//-- Set number of worksheets to 1
m_ExcelApp.OlePropertySet("SheetsInNewWorkbook",(Variant));
//-- Create a new workbook
m_WorkBook=all_workbooks.OleFunction("Add");
m_Sheet=m_WorkBook.OlePropertyGet("ActiveSheet");
return true;
}
bool CRptExcel::SetAppVisible(bool bVisible)
{
m_ExcelApp.OlePropertySet("Visible",(Variant)bVisible);
return true;
}
//得到m_cEnd,m_cBegin;m_RowLast;m_RowBegin;的值
bool CRptExcel::SetData(const RptInf& rInf,TDataSet* pSet)
{
m_ColCount=pSet->FieldCount;
m_cBegin='A';
m_cEnd='A'+m_ColCount;
m_RowBegin=;
m_RowCount=pSet->RecordCount;
m_RowLast=m_RowBegin+m_RowCount;
m_pSet=pSet;
m_sTitle=rInf.tTitle;
m_sA3Content=rInf.tFirstRowL;
m_sLastCol3Content=rInf.tFirstRowR;
m_sCompanyInf=rInf.RptPage.sLeftHeader;
return true;
}
bool CRptExcel::SetCellValue()
{
char ctemp,cEnd;
int iRow,iRowLast;
unsigned int index;
Variant cell;
String str;
if(!m_pSet)
{
m_sError="没有设置数据集!";
return false;
}
if(m_pSet->Eof&&m_pSet->Bof)
{
m_sError="数据集为空";
return false;
}
if(m_ColCount<=)
{
m_sError="列数读取出错!";
return false;
}
ctemp='A';iRow=;
for(index=;index<m_ColCount;index++)
{
ctemp='A'+index;
str.sprintf("%c%d",ctemp,iRow);
cell=m_Sheet.OlePropertyGet("Range",str);
str=m_pSet->Fields->Fields[index]->FieldName;
cell.OlePropertySet("Value",str);
if(ctemp=='Z')
{
m_sError="列数太多出错";
return false;
}
} iRow++;ctemp='A';
m_pSet->First();
while(!m_pSet->Eof)
{
for(index=;index<m_ColCount;index++)
{
ctemp='A'+index;
str.sprintf("%c%d",ctemp,iRow);
cell=m_Sheet.OlePropertyGet("Range",str);
str=m_pSet->Fields->Fields[index]->AsString;
cell.OlePropertySet("Value",str);
}
iRow++;
m_pSet->Next();
} return true;
}
bool CRptExcel::SetTitle()
{
String str;
char ct;
str.sprintf("%c%d:%c%d",'A',,('A'+m_ColCount),);
Variant vCell;
try
{
vCell=m_Sheet.OlePropertyGet("Range",str);
vCell.OlePropertySet("Value",m_sTitle);
}
catch(...)
{
m_sError="设置表头信息时出错!";
return false;
}
return true;
}
//设置公司的信息到页眉页脚处
bool CRptExcel::SetInfCom()
{
try{
Variant PageHeader=m_Sheet.OlePropertyGet("PageSetup");
PageHeader.OlePropertySet("RightHeader","&D ");
PageHeader.OlePropertySet("LeftHeader",m_sCompanyInf);
}
catch(...)
{
m_sError="设置页眉信息时出错!";
return false;
}
return true;
}
bool CRptExcel::SetInfTable()
{ try{
Variant PageHeader=m_Sheet.OlePropertyGet("PageSetup");
PageHeader.OlePropertySet("RightFoot","&P/&N");
PageHeader.OlePropertySet("LeftFoot",m_sTitle);
}
catch(...)
{
m_sError="设置表头信息时出错!";
return false;
}
return true;
}
bool CRptExcel::SetTopRow()
{
try{
Variant vCell=m_Sheet.OlePropertyGet("Range","A3");
vCell.OlePropertySet("Value",m_sA3Content);
String str;
str.sprintf("%c3",'A'+m_ColCount);
vCell.OlePropertyGet("Range",str);
vCell.OlePropertySet("Value",m_sLastCol3Content);
}
catch(...)
{
m_sError="设置表头信息时出错!";
return false;
}
return true;
}
bool CRptExcel::SetCellBorder()
{
String str;
char ct='A';
for(unsigned int index=m_RowBegin;index<m_RowLast+;index++)
{
for(unsigned int j=;j<m_ColCount;j++)
{
ct='A'+j;
Variant vCell,vBorder;
try{
str.sprintf("%c%d",ct,index);
vCell=m_Sheet.OlePropertyGet("Range",str);
vCell.OlePropertyGet("Borders").OlePropertySet("linestyle",xlContinuous);
if(j==)//对第一列的单元格设置其左边界为粗
{
vBorder=vCell.OlePropertyGet("Borders",xlEdgeLeft);
vBorder.OlePropertySet("linestyle",xlContinuous);
vBorder.OlePropertySet("weight",xlThick);
}
if(j==m_ColCount-)//the Right Edge of last col
{
vBorder=vCell.OlePropertyGet("Borders",xlEdgeRight);
vBorder.OlePropertySet("linestyle",xlContinuous);
vBorder.OlePropertySet("weight",xlThick);
}
if(index==m_RowBegin)//the first row having data
{
vBorder=vCell.OlePropertyGet("Borders",xlEdgeTop);
vBorder.OlePropertySet("linestyle",xlContinuous);
vBorder.OlePropertySet("weight",xlThick);
}
if(index==m_RowLast)
{
vBorder=vCell.OlePropertyGet("Borders",xlEdgeBottom);
vBorder.OlePropertySet("linestyle",xlContinuous);
vBorder.OlePropertySet("weight",xlThick);
}
}
catch(...)
{
m_sError="设置边框时出错!";
return false;
}
}
}
return true;
}
//---------------------------------------------------------------------------
#pragma package(smart_init)

C++ builder 操作Excel方法(据网上资料整理)的相关教程结束。

《C++ builder 操作Excel方法(据网上资料整理).doc》

下载本文的Word格式文档,以方便收藏与打印。