VC++如何读写excel
来源:互联网 发布:尚观大数据培训怎么样 编辑:程序博客网 时间:2024/04/28 20:52
using namespace std ;
#import "C:/Program Files/Common Files/Microsoft Shared/OFFICE11/mso.dll" rename("RGB", "MSRGB")
#import "C:/Program Files/Common Files/Microsoft Shared/VBA/VBA6/VBE6EXT.OLB" raw_interfaces_only, /
rename("Reference", "ignorethis"), rename("VBE", "JOEVBE")
#import "C:/Program Files/Microsoft Office/OFFICE11/excel.exe" exclude("IFont", "IPicture") /
rename("RGB", "ignorethis"), rename("DialogBox", "ignorethis"), rename("VBE", "JOEVBE"), /
rename("ReplaceText", "JOEReplaceText"), rename("CopyFile","JOECopyFile"), /
rename("FindText", "JOEFindText"), rename("NoPrompt", "JOENoPrompt")
using namespace Office;
using namespace VBIDE;
using namespace Excel ;
int ExportExcelFile() ;
int main(int argc, char* argv[])
{
if(FAILED(::CoInitialize(NULL)))
return 1 ;
ExportExcelFile() ;
::CoUninitialize();
return 0;
}
int ExportExcelFile()
{
_ApplicationPtr pApplication = NULL ;
_WorkbookPtr pThisWorkbook = NULL ;
_WorksheetPtr pThisWorksheet = NULL ;
SheetsPtr pThisSheets = NULL ;
RangePtr pThisRange = NULL ;
_variant_t vt ;
Excel::XlFileFormat vFileFormat ;
Excel::XlSaveAsAccessMode vSaveAsAccessMode ;
Excel::XlSaveConflictResolution vSaveConflictResolution ;
pApplication.CreateInstance("Excel.Application");
pApplication->PutVisible (0,VARIANT_TRUE);
pThisWorkbook = pApplication->GetWorkbooks()->Add() ;
pThisSheets = pThisWorkbook->GetWorksheets() ;
pThisWorksheet = pThisSheets->GetItem((short)1);
// 设置整个sheet的填充色为白色
pThisWorksheet->GetCells()->GetInterior()->PutColor(RGB(255, 255, 255));
pThisWorksheet->GetCells()->ClearContents() ;
pThisRange = pThisWorksheet->GetRange("A1:C5") ;
pThisRange->ClearFormats() ;
// 如果有不会的,可以在debug文件夹的excel.tlh里找找
//pThisRange->GetItem(1,1) ;
pThisRange->PutItem(1, 1, _variant_t("哈尔滨市平房区")) ;
pThisRange->PutItem(1, 2, _variant_t("高宏伟")) ;
pThisRange->PutItem(1, 3, _variant_t("QQ:21807822")) ;
pThisRange->PutItem(2, 1, _variant_t("1")) ;
pThisRange->PutItem(3, 1, _variant_t("2")) ;
pThisRange->PutItem(4, 1, _variant_t("3")) ;
pThisRange->PutItem(5, 1, _variant_t("4")) ;
// 为Range的四周和内部加上边框
pThisRange->GetBorders()->GetItem(xlEdgeLeft)->PutLineStyle(xlContinuous) ;
pThisRange->GetBorders()->GetItem(xlEdgeTop)->PutLineStyle(xlContinuous) ;
pThisRange->GetBorders()->GetItem(xlEdgeRight)->PutLineStyle(xlContinuous) ;
pThisRange->GetBorders()->GetItem(xlEdgeBottom)->PutLineStyle(xlContinuous) ;
pThisRange->GetBorders()->GetItem(xlInsideHorizontal)->PutLineStyle(xlContinuous) ;
pThisRange->GetBorders()->GetItem(xlInsideVertical)->PutLineStyle(xlContinuous) ;
// 设置第一行的格式(背景色、粗体、颜色、列宽)
pThisRange->GetRange("A1:C1")->GetInterior()->ColorIndex = 47 ;
pThisRange->GetRange("A1:C1")->GetInterior()->Pattern = xlPatternSolid ;
pThisRange->GetRange("A1:C1")->GetFont()->ColorIndex = 6 ;
pThisRange->GetRange("A1:C1")->GetFont()->Bold = TRUE ;
pThisRange->GetEntireColumn()->ColumnWidth = 18.63 ;
pThisRange->GetRange("A2:C5")->GetInterior()->ColorIndex = 16 ;
pThisRange->GetRange("A2:C5")->GetInterior()->Pattern = xlPatternSolid ;
pThisRange->GetRange("A2:C5")->GetFont()->ColorIndex = 2 ;
// 冻结窗格
pApplication->ActiveWindow->FreezePanes = FALSE ;
pApplication->Range["A2"]->Select() ;
pApplication->ActiveWindow->FreezePanes = TRUE ;
// 存盘退出
vSaveAsAccessMode = xlNoChange ;
vFileFormat = xlWorkbookNormal ;
vSaveConflictResolution = xlLocalSessionChanges ;
pThisWorkbook->SaveAs(_variant_t("D://Visual Studio Projects//VCReportDemo//joe.xls"), vFileFormat,_variant_t(""),_variant_t(""), _variant_t(false),
_variant_t(false), vSaveAsAccessMode, vSaveConflictResolution, _variant_t(false)) ;
pThisWorkbook->Close();
pApplication->Quit();
return 0 ;
}
- VC++如何读写excel
- VC读写EXCEL
- VC++读写excel文档
- vc读写excel
- vc读写excel表格
- MFC vc++6 读写Excel
- VC读写Excel 速度问题
- MFC vc++6 读写Excel
- VC++ Excel电子表格读写示例
- 如何读写Excel 电子表格
- VC读写Excel MFC读写Excel 考勤数据
- MATLAB如何读写Excel数据文件
- vc读写Excel文件的方法
- vc读写Excel文件的方法
- vc读写Excel文件的方法
- 转贴:vc读写excel中的数据
- 用VC直接读写excel中的数据
- VC用OLE方式读写Excel
- 百业本地生活搜索引擎 百业更懂生活
- 佳得视数字电视机顶盒共享器原理分析
- C#读取Excel数据
- 浮点数在计算机中存储方式 (转)
- 软件开发人员发展的几个阶段和问题(转)
- VC++如何读写excel
- Debian 配置Bind9 DNS服务器
- 测试培训的对话
- 重新理解MTA
- bool , float, 指针变量与“零值”比较的标准风格
- 在visual studio中删除最近打开的项目和文件记录的方法
- 查看本机器的oralce 的SID
- 简单解析url参数的js对象。
- iframe高度自适应的有效办法