【mfc】excel读写——libxl.lib库
来源:互联网 发布:windows系统编程 环境 编辑:程序博客网 时间:2024/05/18 18:15
工程的配置
1、把include_cpp复制到工程文件夹下,设置包含目录
2、把libxl.lib复制到工程文件夹下,附加依赖项:libxl.lib
3、把libxl.dll复制到Debug下
Dlg.cpp下补充头文件与命名空间
#include "libxl.h"#include <iostream>using namespace libxl;
Dlg.cpp下主要代码:
const TCHAR* ReadDataToWChar(Sheet* sheet, int row,int col){ CellType type = sheet->cellType(row,col); TCHAR buff[1024]; switch (type) { case 1://Num { swprintf_s(buff,1024,_T("%.2lf"),sheet->readNum(row,col)); return buff; } case 2://Str { return sheet->readStr(row,col); } default: { return _T("读取错误!"); } }}void CExcelTestDlg::OnBnClickedButton1(){ //初始化 Book* book = xlCreateBook(); //if(!book) return -1; //book->load("00.xls");//直接读的方式 //创建两个表,一个为“测试写”,一个为“测试读” Sheet* sheet = book->addSheet(_T("测试写")); Sheet* sheet1 = book->addSheet(_T("测试读")); //sheet = book->getSheet(0); //创建出错返回 //if(!sheet || !sheet1) return -2; ///////////////////////////////设置格式////////////////////////////// //设置字体 //libxl::Font* font = book->addFont(); //font->setName(_T("0")); //font->setSize(20); //font->setColor(COLOR_DARKBLUE); //font->setItalic(); //设置样式 Format* StrFormat = book->addFormat(); //StrFormat->setAlignH(ALIGNH_LEFT); //StrFormat->setBorder(BORDERSTYLE_MEDIUMDASHDOTDOT); //StrFormat->setBorderColor(COLOR_RED); //StrFormat->setFont(font); Format* dateFormat = book->addFormat(); //dateFormat->setNumFormat(NUMFORMAT_DATE); Format* NumFormat = book->addFormat(); //NumFormat->setNumFormat(NUMFORMAT_NUMBER); //Format* NumFormat1 = book->addFormat(); //NumFormat1->setNumFormat(NUMFORMAT_NUMBER_D2); //////////////////////////////////////////////////////////////////// /////////////////////////你提出的要求的测试代码///////////////////// //读EDIT写入EXCEL CString str; GetDlgItemText(IDC_WRITE, str);//得到字符串 sheet->writeStr(0, 0, str, StrFormat);//0行0列 //读EXCEL写入EDIT CString str2; str2 = ReadDataToWChar(sheet,0,0);//0行0列 SetDlgItemText(IDC_READ, str2); /////////////////////////你提出的要求的测试代码///////////////////// //////////////////////////以下为自由发挥部分//////////////////////// ///////////////////////////写数据/////////////////////////////////// sheet->writeStr(2, 0, _T("Hello, World !"),StrFormat); sheet->writeNum(4, 0, 1000,NumFormat); //sheet->writeNum(5, 0, 20.98,NumFormat1); sheet->writeFormula(6, 0, _T("SUM(A5:A6)")); sheet->writeNum(8, 0, book->datePack(2012, 05, 17), dateFormat); //循环写 for (int i = 0;i < 200;i++) { sheet->writeStr(i, 2, _T("Hello, World !"),StrFormat); sheet->writeNum(i, 3, i); } //////////////////////////////////////////////////////////////////// ///////////////////////////读数据/////////////////////////////////// for (int i = 0;i < 200;i++) { sheet1->writeStr(i, 0,ReadDataToWChar(sheet,i,2)); sheet1->writeStr(i, 3,ReadDataToWChar(sheet,i,3)); sheet1->setCellFormat(i,3,StrFormat); } //////////////////////////////////////////////////////////////////// ///////////////////////////保存/////////////////////////////////// if(book->save(_T("00.xls"))) { // ::ShellExecute(NULL, _T("open"), _T("00.xls"), NULL, NULL, SW_SHOW); } else { std::cout << book->errorMessage() << std::endl; } //////////////////////////////////////////////////////////////////// book->release();}
具体工程见下载链接(VS2012):http://download.csdn.net/detail/qq_15947787/9844045
阅读全文
0 0
- 【mfc】excel读写——libxl.lib库
- libxl库 学习,读写excel中数据
- libxl 学习之 excel 读写操作
- Visual Studio 2010利用libxl读写excel表格数据
- C++ 读取excel 之libxl VS 库的配置使用
- C++ 读写Excel表格文件 Libxl破解版 支持2007版本 xlsx 中文
- MFC读写Excel
- MFC读写excel文件
- MFC 操作Excel-读写
- MFC读写excel
- MFC----MFC添加excel类库ole库,执行简单读写
- libxl库的使用
- MFC vc++6 读写Excel
- MFC vc++6 读写Excel
- VS2010 MFC 操作Excel(读写)
- vs2008 mfc 读写excel文件
- VS调用 libxl 库异常
- VC读写Excel MFC读写Excel 考勤数据
- Oracle中NVL、NVL2、DECODE函数的用法
- Java 并发编程知识点(四)
- 二次封装的缓存框架wCache(支持缓存时间、默认值)--微信小程序
- Google2016 面试题 吹气球 区间dp
- uva 103
- 【mfc】excel读写——libxl.lib库
- hdu1003 Max Sum
- 阿里云搭建基于MatlabMPI的集群(六):NFS文件共享系统安装与配置
- tensorflow学习笔记(四十二):输入流水线
- Android 控件ImageView ScaleType详解
- html中a标签如何设置行宽高
- 不会的东西 ____备忘录
- 方法重载与方法重写
- Quartz的使用(二)