C语言操作Excel
引用第三方库libxls实现C语言操作Excel
libxls
官网描述
LibXL is a library that can read and write Excel files. It doesn’t require Microsoft Excel and .NET framework, combines an easy to use and powerful features. Library can be used to
- Generate a new spreadsheet from scratch
- Extract data from an existing spreadsheet
- Edit an existing spreadsheet
LibXL can help your applications in exporting and extracting data to/from Excel files with minimum effort. Also it can be used as report engine. Library can be used in C, C++, C#, Delphi, PHP, Python, PowerBASIC, Xojo, Fortran and other languages. Supports Excel 97-2003 binary formats (xls), Excel 2007-2021 XML formats (xlsx/xlsm). Supports Unicode and 64-bit platforms. There are a wrapper for .NET developers and separate Linux, Mac and iOS editions. See features of the library in demo.xls or demo.xlsx files.
配置环境
官方原文版
LibXL is a library for direct reading and writing Excel files.
Package contents:
bin 32-bit dynamic library (libxl.dll)
bin64 64-bit dynamic library (libxl.dll)
bin64_32 the same libraries with different names for 32-bit and 64-bit (can be used in the same folder)
binarm64 ARM64 dynamic library (libxl.dll)
doc C++ documentation
examples C, C++, C#, Delphi and Fortran examples (MinGW, Visual Studio, Qt, Code::Blocks)
include_c headers for C
include_cpp headers for C++
lib Microsoft Visual C++ 32-bit import library for libxl.dll in the bin folder
lib64 Microsoft Visual C++ 64-bit import library for libxl.dll in the bin64 folder
lib64_32 the import libraries for dynamic libraries libxl32.dll and libxl64.dll from the bin64_32 folder
libarm64 Microsoft Visual C++ ARM64 import library for libxl.dll in the binarm64 folder
net .NET wrapper (assembly)
php compiled plug-in for PHP
stdcall 32-bit dynamic library with the stdcall calling convention
changelog.txt version history
libxl.url link to home page
license.txt end-user license agreement
readme.txt this file
Using library:
Microsoft Visual C++
add include directory in your project, for example: c:\libxl\include_cpp
Project -> Properties -> C/C++ -> General -> Additional Include Directories
add library directory in your project, for example: c:\libxl\lib
Project -> Properties -> Linker -> General -> Additional Library Directories
add libxl.lib in project dependencies:
Project -> Properties -> Linker -> Input -> Additional Dependencies
copy bin\libxl.dll to directory of your project
MinGW
Type in examples/c++/mingw directory:
g++ generate.cpp -o generate -I../../../include_cpp -L../../../bin -lxl
Use mingw32-make for building examples.
C# and other .NET languages
Use assembly libxl.net.dll in net directory: Project -> Add reference… -> Browse
Also copy bin\libxl.dll to Debug or Release directory of your project.
Qt
add the following lines to a configuration file (.pro):
INCLUDEPATH = c:/libxl-3.6.4.0/include_cpp
LIBS += c:/libxl-3.6.4.0/lib/libxl.libcopy bin\libxl.dll to the build directory of your project
Borland C++ and Embarcadero C++ Builder
create an import library for your compiler:
implib -a libxl.lib libxl.dll
add the include directory to your project, for example: c:\libxl-3.9.1.0\include_cpp
Project -> Options -> Building -> C++ Compiler -> Directories and Conditionals -> Include file search path
or
Project -> Options -> Directories/Conditionals -> Include path (for old C++ Bulder versions)
add library directory to your project (only for old C++ Builder versions)
Project -> Options -> Directories/Conditionals -> Library path
add libxl.lib to your project
Project -> Add to Project…
copy libxl.dll from the bin folder to
/Win32/Debug or /Win32/Release folder If your target is “Windows 64-bit” copy libxl.dll from the bin64 folder.
Delphi
add the directory with the LibXL.pas unit, for example: c:\libxl-3.9.1.0\examples\delphi12
Project -> Options -> Building -> Delphi Compiler -> Search path
copy libxl.dll from the bin folder to
\Win32\Debug or \Win32\Release folder
Documentation:
Contact:
VS简化版
把 \libxl\include_cpp 文件添加到 Project -> Properties -> C/C++ -> General -> Additional Include Directories
把 \libxl\lib 文件添加到 Project -> Properties -> Linker -> General -> Additional Library Directories
添加 libxl.lib 文件到 Project -> Properties -> Linker -> Input -> Additional Dependencies
复制 bin\libxl.dll 到项目路径下