C Programs in Ubuntu use xlslib2.3.4 to write Excel File

Source: Internet
Author: User

Xlslib is a cross-platform Excel tableWriteClass Library. That is to say, you can call it in C and C ++ under Linux to output an Excel table file.

Download the source code, decompress it, compile and install it.

Source code: http://sourceforge.net/projects/xlslib/files/

Run the following command on the terminal:

./Configre

Make

Make check

Make install

In the last step, make install must switch to the root user to write the header file and library file to/usr.

After this step, the default installed library files are stored in/usr/local/lib, which is not in the default lib path of the system. You need to manually copy them

Sudo CP/usr/local/lib/libxls */usr/lib

Before writingSource codeRemember to include the following two header files, or the compilation will fail!

# Include <wchar. h>
# Include <stdbool. h>

For the example of how to use it, 2.3.4 seems to have changed a lot. Most of the source code searched on the internet is unavailable ,,

You can view it in the targets/test/folder under the source code directory,

Mainc. C is an example of calling xlslib in C. maincpp. cpp is an example of calling xlslib in C ++.

The following is a simple example: WB. c

You can add the XLS library during compilation.

Gcc wb. C-o WB-lxls

 
# Include <stdio. h> # include <string. h> # include <wchar. h> # include <stdbool. h> # include <errno. h> # include <xlslib/xlslib. h> int main (INT argc, char * argv []) {workbook * WB; worksheet * ws; WB = xlsnewworkbook (); Ws = xlsworkbooksheet (WB, "sheet1 "); xlsworksheetlabel (WS, 0, 1, "name", null); xlsworksheetlabel (WS, 0, 2, "us", null); xlsworksheetlabel (WS, 0, 3, "cn", null); xlsworksheetlabel (WS, 0, 4, "TR", nu Ll); int err = xlsworkbookdump (WB, "blank.xls"); xlsdeleteworkbook (WB); If (Err! = 0) {fprintf (stderr, "Dump xls file failed: I/O failure % d. \ n", err); Return-1;} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.