-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update libxlsx to 0.8.3 October 1 2018
- Loading branch information
Showing
80 changed files
with
7,133 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Anatomy of a simple libxlsxwriter program. | ||
* | ||
* Copyright 2014-2018, John McNamara, jmcnamara@cpan.org | ||
* | ||
*/ | ||
|
||
#include "xlsxwriter.h" | ||
|
||
int main() { | ||
|
||
/* Create a new workbook. */ | ||
lxw_workbook *workbook = workbook_new("anatomy.xlsx"); | ||
|
||
/* Add a worksheet with a user defined sheet name. */ | ||
lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, "Demo"); | ||
|
||
/* Add a worksheet with Excel's default sheet name: Sheet2. */ | ||
lxw_worksheet *worksheet2 = workbook_add_worksheet(workbook, NULL); | ||
|
||
/* Add some cell formats. */ | ||
lxw_format *myformat1 = workbook_add_format(workbook); | ||
lxw_format *myformat2 = workbook_add_format(workbook); | ||
|
||
/* Set the bold property for the first format. */ | ||
format_set_bold(myformat1); | ||
|
||
/* Set a number format for the second format. */ | ||
format_set_num_format(myformat2, "$#,##0.00"); | ||
|
||
/* Widen the first column to make the text clearer. */ | ||
worksheet_set_column(worksheet1, 0, 0, 20, NULL); | ||
|
||
/* Write some unformatted data. */ | ||
worksheet_write_string(worksheet1, 0, 0, "Peach", NULL); | ||
worksheet_write_string(worksheet1, 1, 0, "Plum", NULL); | ||
|
||
/* Write formatted data. */ | ||
worksheet_write_string(worksheet1, 2, 0, "Pear", myformat1); | ||
|
||
/* Formats can be reused. */ | ||
worksheet_write_string(worksheet1, 3, 0, "Persimmon", myformat1); | ||
|
||
|
||
/* Write some numbers. */ | ||
worksheet_write_number(worksheet1, 5, 0, 123, NULL); | ||
worksheet_write_number(worksheet1, 6, 0, 4567.555, myformat2); | ||
|
||
|
||
/* Write to the second worksheet. */ | ||
worksheet_write_string(worksheet2, 0, 0, "Some text", myformat1); | ||
|
||
|
||
/* Close the workbook, save the file and free any memory. */ | ||
lxw_error error = workbook_close(workbook); | ||
|
||
/* Check if there was any error creating the xlsx file. */ | ||
if (error) | ||
printf("Error in workbook_close().\n" | ||
"Error %d = %s\n", error, lxw_strerror(error)); | ||
|
||
return error; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Example of how to use the libxlsxwriter library to write simple | ||
* array formulas. | ||
* | ||
* Copyright 2014-2018, John McNamara, jmcnamara@cpan.org | ||
* | ||
*/ | ||
|
||
#include "xlsxwriter.h" | ||
|
||
int main() { | ||
|
||
/* Create a new workbook and add a worksheet. */ | ||
lxw_workbook *workbook = workbook_new("array_formula.xlsx"); | ||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); | ||
|
||
/* Write some data for the formulas. */ | ||
worksheet_write_number(worksheet, 0, 1, 500, NULL); | ||
worksheet_write_number(worksheet, 1, 1, 10, NULL); | ||
worksheet_write_number(worksheet, 4, 1, 1, NULL); | ||
worksheet_write_number(worksheet, 5, 1, 2, NULL); | ||
worksheet_write_number(worksheet, 6, 1, 3, NULL); | ||
|
||
worksheet_write_number(worksheet, 0, 2, 300, NULL); | ||
worksheet_write_number(worksheet, 1, 2, 15, NULL); | ||
worksheet_write_number(worksheet, 4, 2, 20234, NULL); | ||
worksheet_write_number(worksheet, 5, 2, 21003, NULL); | ||
worksheet_write_number(worksheet, 6, 2, 10000, NULL); | ||
|
||
/* Write an array formula that returns a single value. */ | ||
worksheet_write_array_formula(worksheet, 0, 0, 0, 0, "{=SUM(B1:C1*B2:C2)}", NULL); | ||
|
||
/* Similar to above but using the RANGE macro. */ | ||
worksheet_write_array_formula(worksheet, RANGE("A2:A2"), "{=SUM(B1:C1*B2:C2)}", NULL); | ||
|
||
/* Write an array formula that returns a range of values. */ | ||
worksheet_write_array_formula(worksheet, 4, 0, 6, 0, "{=TREND(C5:C7,B5:B7)}", NULL); | ||
|
||
workbook_close(workbook); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Example of adding an autofilter to a worksheet in Excel using | ||
* libxlsxwriter. | ||
* | ||
* Copyright 2014-2018, John McNamara, jmcnamara@cpan.org | ||
* | ||
*/ | ||
|
||
#include "xlsxwriter.h" | ||
|
||
|
||
int main() { | ||
|
||
lxw_workbook *workbook = workbook_new("autofilter.xlsx"); | ||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); | ||
uint16_t i; | ||
|
||
|
||
/* Simple data structure to represent the row data. */ | ||
struct row { | ||
char region[16]; | ||
char item[16]; | ||
int volume; | ||
char month[16]; | ||
}; | ||
|
||
struct row data[] = { | ||
{"East", "Apple", 9000, "July" }, | ||
{"East", "Apple", 5000, "July" }, | ||
{"South", "Orange", 9000, "September" }, | ||
{"North", "Apple", 2000, "November" }, | ||
{"West", "Apple", 9000, "November" }, | ||
{"South", "Pear", 7000, "October" }, | ||
{"North", "Pear", 9000, "August" }, | ||
{"West", "Orange", 1000, "December" }, | ||
{"West", "Grape", 1000, "November" }, | ||
{"South", "Pear", 10000, "April" }, | ||
{"West", "Grape", 6000, "January" }, | ||
{"South", "Orange", 3000, "May" }, | ||
{"North", "Apple", 3000, "December" }, | ||
{"South", "Apple", 7000, "February" }, | ||
{"West", "Grape", 1000, "December" }, | ||
{"East", "Grape", 8000, "February" }, | ||
{"South", "Grape", 10000, "June" }, | ||
{"West", "Pear", 7000, "December" }, | ||
{"South", "Apple", 2000, "October" }, | ||
{"East", "Grape", 7000, "December" }, | ||
{"North", "Grape", 6000, "April" }, | ||
{"East", "Pear", 8000, "February" }, | ||
{"North", "Apple", 7000, "August" }, | ||
{"North", "Orange", 7000, "July" }, | ||
{"North", "Apple", 6000, "June" }, | ||
{"South", "Grape", 8000, "September" }, | ||
{"West", "Apple", 3000, "October" }, | ||
{"South", "Orange", 10000, "November" }, | ||
{"West", "Grape", 4000, "July" }, | ||
{"North", "Orange", 5000, "August" }, | ||
{"East", "Orange", 1000, "November" }, | ||
{"East", "Orange", 4000, "October" }, | ||
{"North", "Grape", 5000, "August" }, | ||
{"East", "Apple", 1000, "December" }, | ||
{"South", "Apple", 10000, "March" }, | ||
{"East", "Grape", 7000, "October" }, | ||
{"West", "Grape", 1000, "September" }, | ||
{"East", "Grape", 10000, "October" }, | ||
{"South", "Orange", 8000, "March" }, | ||
{"North", "Apple", 4000, "July" }, | ||
{"South", "Orange", 5000, "July" }, | ||
{"West", "Apple", 4000, "June" }, | ||
{"East", "Apple", 5000, "April" }, | ||
{"North", "Pear", 3000, "August" }, | ||
{"East", "Grape", 9000, "November" }, | ||
{"North", "Orange", 8000, "October" }, | ||
{"East", "Apple", 10000, "June" }, | ||
{"South", "Pear", 1000, "December" }, | ||
{"North", "Grape", 10000, "July" }, | ||
{"East", "Grape", 6000, "February" } | ||
}; | ||
|
||
|
||
/* Write the column headers. */ | ||
worksheet_write_string(worksheet, 0, 0, "Region", NULL); | ||
worksheet_write_string(worksheet, 0, 1, "Item", NULL); | ||
worksheet_write_string(worksheet, 0, 2, "Volume" , NULL); | ||
worksheet_write_string(worksheet, 0, 3, "Month", NULL); | ||
|
||
|
||
/* Write the row data. */ | ||
for (i = 0; i < sizeof(data)/sizeof(struct row); i++) { | ||
worksheet_write_string(worksheet, i + 1, 0, data[i].region, NULL); | ||
worksheet_write_string(worksheet, i + 1, 1, data[i].item, NULL); | ||
worksheet_write_number(worksheet, i + 1, 2, data[i].volume , NULL); | ||
worksheet_write_string(worksheet, i + 1, 3, data[i].month, NULL); | ||
} | ||
|
||
/* Add the autofilter. */ | ||
worksheet_autofilter(worksheet, 0, 0, 50, 3); | ||
|
||
return workbook_close(workbook); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* An example of a simple Excel chart using the libxlsxwriter library. | ||
* | ||
* Copyright 2014-2018, John McNamara, jmcnamara@cpan.org | ||
* | ||
*/ | ||
|
||
#include "xlsxwriter.h" | ||
|
||
/* Write some data to the worksheet. */ | ||
void write_worksheet_data(lxw_worksheet *worksheet) { | ||
|
||
uint8_t data[5][3] = { | ||
/* Three columns of data. */ | ||
{1, 2, 3}, | ||
{2, 4, 6}, | ||
{3, 6, 9}, | ||
{4, 8, 12}, | ||
{5, 10, 15} | ||
}; | ||
|
||
int row, col; | ||
for (row = 0; row < 5; row++) | ||
for (col = 0; col < 3; col++) | ||
worksheet_write_number(worksheet, row, col, data[row][col], NULL); | ||
} | ||
|
||
/* Create a worksheet with a chart. */ | ||
int main() { | ||
|
||
lxw_workbook *workbook = new_workbook("chart.xlsx"); | ||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); | ||
|
||
/* Write some data for the chart. */ | ||
write_worksheet_data(worksheet); | ||
|
||
/* Create a chart object. */ | ||
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN); | ||
|
||
/* Configure the chart. In simplest case we just add some value data | ||
* series. The NULL categories will default to 1 to 5 like in Excel. | ||
*/ | ||
chart_add_series(chart, NULL, "Sheet1!$A$1:$A$5"); | ||
chart_add_series(chart, NULL, "Sheet1!$B$1:$B$5"); | ||
chart_add_series(chart, NULL, "Sheet1!$C$1:$C$5"); | ||
|
||
/* Insert the chart into the worksheet. */ | ||
worksheet_insert_chart(worksheet, CELL("B7"), chart); | ||
|
||
return workbook_close(workbook); | ||
} |
Oops, something went wrong.