Comments (6)
+1
from libxlsxwriter.
+1
from libxlsxwriter.
Since I've had a few requests about this I've added a note about making donations to prioritize this feature.
from libxlsxwriter.
There is now working code for this feature on the rich_strings branch.
It still needs parameter validation and documentation before it is merged up to master but the core API and functionality is complete. Here is an example from the branch:
/*
* An example of using the libxlsxwriter library to write some "rich strings",
* i.e., strings with multiple formats.
*
* Copyright 2014-2018, John McNamara, [email protected]
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("rich_strings.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
/* Set up some formats to use. */
lxw_format *bold = workbook_add_format(workbook);
format_set_bold(bold);
lxw_format *italic = workbook_add_format(workbook);
format_set_italic(italic);
lxw_format *red = workbook_add_format(workbook);
format_set_font_color(red, LXW_COLOR_RED);
lxw_format *blue = workbook_add_format(workbook);
format_set_font_color(blue, LXW_COLOR_BLUE);
lxw_format *center = workbook_add_format(workbook);
format_set_align(center, LXW_ALIGN_CENTER);
lxw_format *superscript = workbook_add_format(workbook);
format_set_font_script(superscript, LXW_FONT_SUPERSCRIPT);
/* Make the first column wide for clarity. */
worksheet_set_column(worksheet, 0, 0, 30, NULL);
/* Create and write some rich strings with multiple formats. */
/* Example 1. Some bold and italic in the same string. */
lxw_rich_string_tuple fragment11 = {.format = NULL, .string = "This is "};
lxw_rich_string_tuple fragment12 = {.format = bold, .string = "bold"};
lxw_rich_string_tuple fragment13 = {.format = NULL, .string = " and this is "};
lxw_rich_string_tuple fragment14 = {.format = italic, .string = "italic"};
lxw_rich_string_tuple *rich_string1[] = {&fragment11, &fragment12,
&fragment13, &fragment14, NULL};
worksheet_write_rich_string(worksheet, CELL("A1"), rich_string1, NULL);
/* Example 2. Some red and blue coloring in the same string. */
lxw_rich_string_tuple fragment21 = {.format = NULL, .string = "This is "};
lxw_rich_string_tuple fragment22 = {.format = red, .string = "red"};
lxw_rich_string_tuple fragment23 = {.format = NULL, .string = " and this is "};
lxw_rich_string_tuple fragment24 = {.format = blue, .string = "blue"};
lxw_rich_string_tuple *rich_string2[] = {&fragment21, &fragment22,
&fragment23, &fragment24, NULL};
worksheet_write_rich_string(worksheet, CELL("A3"), rich_string2, NULL);
/* Example 3. A rich string plus cell formatting. */
lxw_rich_string_tuple fragment31 = {.format = NULL, .string = "Some "};
lxw_rich_string_tuple fragment32 = {.format = bold, .string = "bold text"};
lxw_rich_string_tuple fragment33 = {.format = NULL, .string = " centered"};
lxw_rich_string_tuple *rich_string3[] = {&fragment31, &fragment32,
&fragment33, NULL};
/* Note that is example also can a "center" cell format. */
worksheet_write_rich_string(worksheet, CELL("A5"), rich_string3, center);
/* Example 4. A math example with a superscript. */
lxw_rich_string_tuple fragment41 = {.format = italic, .string = "j =k"};
lxw_rich_string_tuple fragment42 = {.format = superscript, .string = "(n-1)"};
lxw_rich_string_tuple *rich_string4[] = {&fragment41, &fragment42, NULL};
worksheet_write_rich_string(worksheet, CELL("A7"), rich_string4, center);
workbook_close(workbook);
return 0;
}
And the output:
The key idea is to split the string into to fragments that are preceded by the format. If the format is NULL
then default formatting is applied.
The API is a little clunky, i.e., having to create a lxw_rich_string_tuple **
with the fragments) but that is suitable for wrapping in small user defined functions suitable to the data.
If you want to try it in advance let me know how you get on. All the tests are ported and passing.
from libxlsxwriter.
Added docs: https://github.com/jmcnamara/libxlsxwriter/blob/rich_strings/include/xlsxwriter/worksheet.h#L1338
from libxlsxwriter.
Added in version 0.8.3: https://libxlsxwriter.github.io/changes.html
from libxlsxwriter.
Related Issues (20)
- Using this lib in for another computer language HOT 2
- Implement the $book->set_custom_color() function from the Perl library in the C library HOT 2
- Linker error when trying to use latest version with macOS project HOT 1
- File creation performance HOT 2
- Linux(CentOS6) Build Error.
- LXW_ERROR_CREATING_XLSX_FILE: error creating output xlsx file. Usually a permissions error. HOT 1
- cannot run on x64 Release in Visual Studio 2022 HOT 5
- Issue: Corrupt file compiled using VS2008 on Windows HOT 9
- Issue when using constant memory with merge range HOT 2
- password HOT 1
- Still Tagging Releases? HOT 2
- 1.1.6 release did not get marked as latest release HOT 4
- How to insert image data of type CV:: Mat HOT 2
- test/functional/test_image.py::TestCompareXLSXFiles::test_image58 failure on 32bit architectures HOT 8
- Bug: workbook_validate_sheet_name buffer-overflow HOT 4
- Bug: workbook_add_worksheet does not return a reasonable worksheet HOT 1
- workbook_define_name stack-buffer-underflow HOT 2
- workbook_close stack-buffer-overflow HOT 4
- _store_array_formula heap-buffer-overflow HOT 5
- worksheet_set_selection stack-buffer-overflow HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libxlsxwriter.