读写Excel的动态库版本2,供各种开发语言调用,不需安装Office

19 篇文章 0 订阅

之前写了个读写Excel的动态库,接口较少。换了个新版本,采用的https://github.com/360EntSecGroup-Skylar/excelize,接口更丰富,可以写入图片。代码已开源https://github.com/6550523/ExcelDll2

C++读写Excel范例:

#include "stdafx.h"
#include <Windows.h>

#define ERR_LEN 1024
#define TEXT_LEN 32767

#ifdef _WIN64
#define DLL_PATH _T("..\\..\\Release\\excel-win-64.dll")
#else
#define DLL_PATH _T("..\\..\\Release\\excel-win-32.dll")
#endif

#define  XLSX_FILE "..\\..\\Release\\1.xlsx"
#define  IMG_FILE "..\\..\\Release\\1.jpg"

int main()
{
	HMODULE module = LoadLibrary(DLL_PATH);
	if (module == NULL)
	{
		printf("Load excel.dll failed\n");
		return -1;
	}

	char output[ERR_LEN];
	memset(output, 0, ERR_LEN);

	//NewFile
	//typedef void(*NewFileFunc)();
	//NewFileFunc NewFile;
	//NewFile = (NewFileFunc)GetProcAddress(module, "NewFile");
	//NewFile();

	//OpenFile
	typedef void(*OpenFileFunc)(char*, char*);
	OpenFileFunc OpenFile;
	OpenFile = (OpenFileFunc)GetProcAddress(module, "OpenFile");
	OpenFile(XLSX_FILE, output);
	printf(output);

	//NewSheet
	//typedef int(*NewSheetFunc)(char*);
	//NewSheetFunc NewSheet;
	//NewSheet = (NewSheetFunc)GetProcAddress(module, "NewSheet");
	//int sheetIndex = NewSheet("new_sheet");
	//printf("sheetIndex %d", sheetIndex);

	//GetCellValue
	typedef int(*GetCellValueFunc)(char*, char*, char*, char*);
	GetCellValueFunc GetCellValue;
	GetCellValue = (GetCellValueFunc)GetProcAddress(module, "GetCellValue");
	char cellValue[TEXT_LEN];
	memset(cellValue, 0, TEXT_LEN);
	GetCellValue("Sheet1", "A1", cellValue, output);
	printf(cellValue);
	printf(output);

	//SetCellValue
	typedef int(*SetCellValueFunc)(char*, char*, char*, char*);
	SetCellValueFunc SetCellValue;
	SetCellValue = (SetCellValueFunc)GetProcAddress(module, "SetCellValue");
	SetCellValue("Sheet1", "A2", "Hello world.", output);
	printf(output);

	//AddPicture
	//typedef int(*AddPictureFunc)(char*, char*, char*, char*, char*);
	//AddPictureFunc AddPicture;
	//AddPicture = (AddPictureFunc)GetProcAddress(module, "AddPicture");
	//AddPicture("Sheet1", "B4", IMG_FILE, "{\"x_scale\": 0.5, \"y_scale\": 0.5}", output);
	//printf(output);

	//GetActiveSheetIndex
	typedef int(*GetActiveSheetIndexFunc)();
	GetActiveSheetIndexFunc GetActiveSheetIndex;
	GetActiveSheetIndex = (GetActiveSheetIndexFunc)GetProcAddress(module, "GetActiveSheetIndex");
	printf("index %d", GetActiveSheetIndex());

	//SetActiveSheet
	typedef void(*SetActiveSheetFunc)(int);
	SetActiveSheetFunc SetActiveSheet;
	SetActiveSheet = (SetActiveSheetFunc)GetProcAddress(module, "SetActiveSheet");
	SetActiveSheet(0);
	printf("index %d", GetActiveSheetIndex());

	//GetSheetName
	typedef void(*GetSheetNameFunc)(int, char*);
	GetSheetNameFunc GetSheetName;
	GetSheetName = (GetSheetNameFunc)GetProcAddress(module, "GetSheetName");
	char sheetName[TEXT_LEN];
	memset(sheetName, 0, TEXT_LEN);
	GetSheetName(0, sheetName);
	printf(sheetName);

	//SetSheetName
	//typedef void(*SetSheetNameFunc)(char*, char*);
	//SetSheetNameFunc SetSheetName;
	//SetSheetName = (SetSheetNameFunc)GetProcAddress(module, "SetSheetName");
	//SetSheetName("Sheet2", "SheetB");

	//GetSheetIndex
	typedef int(*GetSheetIndexFunc)(char*);
	GetSheetIndexFunc GetSheetIndex;
	GetSheetIndex = (GetSheetIndexFunc)GetProcAddress(module, "GetSheetIndex");
	printf("index %d", GetSheetIndex("Sheet3"));

	//GetSheetCount
	typedef int(*GetSheetCountFunc)();
	GetSheetCountFunc GetSheetCount;
	GetSheetCount = (GetSheetCountFunc)GetProcAddress(module, "GetSheetCount");
	printf("sheet count %d", GetSheetCount());

	//DeleteSheet
	//typedef int(*DeleteSheetFunc)(char*);
	//DeleteSheetFunc DeleteSheet;
	//DeleteSheet = (DeleteSheetFunc)GetProcAddress(module, "DeleteSheet");
	//DeleteSheet("Sheet3");

	//CopySheet
	//typedef void(*CopySheetFunc)(int, int, char*);
	//CopySheetFunc CopySheet;
	//CopySheet = (CopySheetFunc)GetProcAddress(module, "CopySheet");
	//CopySheet(0, 1, output);
	//printf(output);

	//GetRowCount
	typedef int(*GetRowCountFunc)(char*, char*);
	GetRowCountFunc GetRowCount;
	GetRowCount = (GetRowCountFunc)GetProcAddress(module, "GetRowCount");
	printf("row count %d", GetRowCount("Sheet1", output));
	printf(output);

	//GetColumnCount
	typedef int(*GetColumnCountFunc)(char*, int, char*);
	GetColumnCountFunc GetColumnCount;
	GetColumnCount = (GetColumnCountFunc)GetProcAddress(module, "GetColumnCount");
	printf("column count %d", GetColumnCount("Sheet1", 1, output));
	printf(output);

	//SetRowHeight
	typedef int(*SetRowHeightFunc)(char*, int, double, char*);
	SetRowHeightFunc SetRowHeight;
	SetRowHeight = (SetRowHeightFunc)GetProcAddress(module, "SetRowHeight");
	SetRowHeight("Sheet1", 1, 100.1, output);
	printf(output);

	//GetRowHeight
	typedef double(*GetRowHeightFunc)(char*, int, char*);
	GetRowHeightFunc GetRowHeight;
	GetRowHeight = (GetRowHeightFunc)GetProcAddress(module, "GetRowHeight");
	printf("row height %f", GetRowHeight("Sheet1", 1, output));
	printf(output);

	//RemoveRow
	typedef void(*RemoveRowFunc)(char*, int, char*);
	GetRowHeightFunc RemoveRow;
	RemoveRow = (GetRowHeightFunc)GetProcAddress(module, "RemoveRow");
	RemoveRow("Sheet1", 2, output);
	printf(output);

	//InsertRow
	typedef void(*InsertRowFunc)(char*, int, char*);
	InsertRowFunc InsertRow;
	InsertRow = (InsertRowFunc)GetProcAddress(module, "InsertRow");
	InsertRow("Sheet1", 2, output);
	printf(output);

	//DuplicateRowTo
	typedef void(*DuplicateRowToFunc)(char*, int, int, char*);
	DuplicateRowToFunc DuplicateRowTo;
	DuplicateRowTo = (DuplicateRowToFunc)GetProcAddress(module, "DuplicateRowTo");
	DuplicateRowTo("Sheet1", 1, 2, output);
	printf(output);

	//SetCellInt
	typedef void(*SetCellIntFunc)(char*, char*, int, char*);
	SetCellIntFunc SetCellInt;
	SetCellInt = (SetCellIntFunc)GetProcAddress(module, "SetCellInt");
	SetCellInt("Sheet1", "A1", 33, output);
	printf(output);

	//SetCellBool
	typedef void(*SetCellBoolFunc)(char*, char*, int, char*);
	SetCellBoolFunc SetCellBool;
	SetCellBool = (SetCellBoolFunc)GetProcAddress(module, "SetCellBool");
	SetCellBool("Sheet1", "A2", 1, output);
	printf(output);

	//SetCellFloat
	typedef void(*SetCellFloatFunc)(char*, char*, double, int, int, char*);
	SetCellFloatFunc SetCellFloat;
	SetCellFloat = (SetCellFloatFunc)GetProcAddress(module, "SetCellFloat");
	SetCellFloat("Sheet1", "A3", 0.123456, 2, 32, output);
	printf(output);

	//SetCellStr
	typedef void(*SetCellStrFunc)(char*, char*, char*, char*);
	SetCellStrFunc SetCellStr;
	SetCellStr = (SetCellStrFunc)GetProcAddress(module, "SetCellStr");
	SetCellStr("Sheet1", "B1", "bye", output);
	printf(output);

	//GetCellFormula
	typedef void(*GetCellFormulaFunc)(char*, char*, char*, char*);
	GetCellFormulaFunc GetCellFormula;
	GetCellFormula = (GetCellFormulaFunc)GetProcAddress(module, "GetCellFormula");
	char formula[TEXT_LEN];
	memset(formula, 0, TEXT_LEN);
	GetCellFormula("Sheet1", "C1", formula, output);
	printf(output);

	//test faild//GetCellHyperLink
	//typedef void(*GetCellHyperLinkFunc)(char*, char*, char*, char*);
	//GetCellHyperLinkFunc GetCellHyperLink;
	//GetCellHyperLink = (GetCellHyperLinkFunc)GetProcAddress(module, "GetCellHyperLink");
	//char link[TEXT_LEN];
	//memset(link, 0, TEXT_LEN);
	//GetCellHyperLink("Sheet1", "C2", link, output);
	//printf(output);

	//Save
	typedef void(*SaveFunc)(char*);
	SaveFunc Save;
	Save = (SaveFunc)GetProcAddress(module, "Save");
	Save(output);
	printf(output);


	//SaveAs
	//typedef void(*SaveAsFunc)(char*, char*);
	//SaveAsFunc SaveAs;
	//SaveAs = (SaveAsFunc)GetProcAddress(module, "SaveAs");
	//SaveAs("..\\..\\Release\\2.xlsx", output);
	//printf(output);

	FreeLibrary(module);
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
随着 ComponentOne 2012V3 的发布,ComponentOne .NET 主流平台开始正式支持中文本地化。在ComponentOne 2012V3中,开发人员的交互界面和提示信息都是中文,包括菜单和对话框等交互界面,在设计时控件各对象的方法和属性的说明,以及在Visual Studio 环境中的 API 智能提示等。ComponentOne 2012V3还针对WinForm平台主要控件-FlexGrid和Chart制作了包含了近20万字的中文帮助文档,产品的每一功能进行了细致的介绍并提示例代码,便于开发人员的学习和使用。 我们借此机会编写 C1FlexGrid 和 C1Chart 初级、高级应用系列文章。希望能对正在使用或对第三方控件感兴趣的朋友能有所帮助。 关于 FlexGrid ComponentOne FlexGrid for WinForms是一款易用、灵活的高性能表格控件,可帮助用户创建友好界面,用于展示、变更、修改格式、组织、总结和打印各种数据。它提所有基础功能,以及更加灵活的高级功能,包括概要树、单元格合并、高级打印、快速变更格式、单元格自定义等。通过自定义功能,您可以创建您自己的单元格类,自定义表格的呈现和特性等。 与同类产品相比,ComponentOne FlexGrid的特点是: 轻便快速 相比较同类产品1M至3M的安装文件大小,FlexGrid安装包仅为150K,同时可达3至10倍快速加载数据和滚动数据。 操作简单 以Microsoft Excel为模型,帮助用户从最熟悉的微软键盘处理习惯开始入手,支持编辑,选择,和便签板,同时满足优良的性能和呈现效果。 多平台支持 ComponentOne FlexGrid是唯一一个表格控件支持微软的多个平台(包括Silverlight, WPF, WinForms, ActiveX, Compact Framework)。 ComponentOne FlexGrid 包含如下控件: C1FlexGrid 是一款功能强大完整的表格控件,它能够提所有基础的功能以及一些高级功能,包括概要树、 单元格合并、高级打印、快速变更格式、单元格自定义等。 C1FlexGridClassic 衍生自C1FlexGrid并提一个对象模型,在实质上100%等同于VSFlexGrid ActiveX控件,帮助用户便捷地移植至.NET平台。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昵称6550523

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值