@@ -10,6 +10,16 @@ pub use filter::*;
10
10
pub use table:: * ;
11
11
pub use validation:: * ;
12
12
13
+ /// Integer data type to represent a column value. Equivalent to `u16`.
14
+ ///
15
+ /// The maximum column in Excel is 16,384.
16
+ pub type WorksheetCol = libxlsxwriter_sys:: lxw_col_t ;
17
+
18
+ /// Integer data type to represent a row value. Equivalent to `u32`.
19
+ ///
20
+ /// The maximum row in Excel is 1,048,576.
21
+ pub type WorksheetRow = libxlsxwriter_sys:: lxw_row_t ;
22
+
13
23
#[ derive( Debug , Clone , PartialEq , PartialOrd , Default ) ]
14
24
pub struct DateTime {
15
25
pub year : i16 ,
@@ -232,18 +242,114 @@ impl From<&Protection> for libxlsxwriter_sys::lxw_protection {
232
242
}
233
243
}
234
244
235
- /// Integer data type to represent a column value. Equivalent to `u16`.
236
- ///
237
- /// The maximum column in Excel is 16,384.
238
- pub type WorksheetCol = libxlsxwriter_sys:: lxw_col_t ;
245
+ /// Options struct for the `set_column()` and `set_row()` functions.
246
+ #[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
247
+ pub struct RowColOptions {
248
+ hidden : bool ,
249
+ level : u8 ,
250
+ collapsed : bool ,
251
+ }
239
252
240
- /// Integer data type to represent a row value. Equivalent to `u32`.
241
- ///
242
- /// The maximum row in Excel is 1,048,576.
243
- pub type WorksheetRow = libxlsxwriter_sys:: lxw_row_t ;
253
+ impl RowColOptions {
254
+ pub fn new ( hidden : bool , level : u8 , collapsed : bool ) -> Self {
255
+ RowColOptions {
256
+ hidden,
257
+ level,
258
+ collapsed,
259
+ }
260
+ }
244
261
245
- pub type CommentOptions = libxlsxwriter_sys:: lxw_comment_options ;
246
- pub type RowColOptions = libxlsxwriter_sys:: lxw_row_col_options ;
262
+ pub ( crate ) fn into_internal ( & self ) -> libxlsxwriter_sys:: lxw_row_col_options {
263
+ libxlsxwriter_sys:: lxw_row_col_options {
264
+ hidden : convert_bool ( self . hidden ) ,
265
+ level : self . level ,
266
+ collapsed : convert_bool ( self . collapsed ) ,
267
+ }
268
+ }
269
+ }
270
+
271
+ impl Default for RowColOptions {
272
+ fn default ( ) -> Self {
273
+ RowColOptions {
274
+ hidden : false ,
275
+ level : 0 ,
276
+ collapsed : false ,
277
+ }
278
+ }
279
+ }
280
+
281
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
282
+ pub enum CommentDisplayType {
283
+ Default ,
284
+ Hidden ,
285
+ Visible ,
286
+ }
287
+
288
+ impl Default for CommentDisplayType {
289
+ fn default ( ) -> Self {
290
+ CommentDisplayType :: Default
291
+ }
292
+ }
293
+
294
+ impl CommentDisplayType {
295
+ pub ( crate ) fn into_internal ( self ) -> libxlsxwriter_sys:: lxw_comment_display_types {
296
+ match self {
297
+ CommentDisplayType :: Default => {
298
+ libxlsxwriter_sys:: lxw_comment_display_types_LXW_COMMENT_DISPLAY_DEFAULT
299
+ }
300
+ CommentDisplayType :: Hidden => {
301
+ libxlsxwriter_sys:: lxw_comment_display_types_LXW_COMMENT_DISPLAY_HIDDEN
302
+ }
303
+ CommentDisplayType :: Visible => {
304
+ libxlsxwriter_sys:: lxw_comment_display_types_LXW_COMMENT_DISPLAY_VISIBLE
305
+ }
306
+ }
307
+ }
308
+ }
309
+
310
+ /// Options for modifying comments inserted via `write_comment_opt()`
311
+ #[ derive( Debug , Clone , PartialEq , PartialOrd ) ]
312
+ pub struct CommentOptions {
313
+ visible : CommentDisplayType ,
314
+ author : Option < String > ,
315
+ width : Option < u16 > ,
316
+ height : Option < u16 > ,
317
+ x_scale : Option < f64 > ,
318
+ y_scale : Option < f64 > ,
319
+ color : FormatColor ,
320
+ font_name : Option < String > ,
321
+ font_size : Option < f64 > ,
322
+ font_family : Option < u8 > ,
323
+ start_row : WorksheetRow ,
324
+ start_col : WorksheetCol ,
325
+ x_offset : i32 ,
326
+ y_offset : i32 ,
327
+ }
328
+
329
+ impl CommentOptions {
330
+ pub ( crate ) fn into_internal (
331
+ & self ,
332
+ workbook : & Workbook ,
333
+ ) -> libxlsxwriter_sys:: lxw_comment_options {
334
+ libxlsxwriter_sys:: lxw_comment_options {
335
+ visible : self . visible . into_internal ( ) as u8 ,
336
+ author : workbook. register_option_str ( self . author . as_deref ( ) ) as * mut std:: ffi:: c_char ,
337
+ width : self . width . unwrap_or_default ( ) ,
338
+ height : self . height . unwrap_or_default ( ) ,
339
+ x_scale : self . x_scale . unwrap_or_default ( ) ,
340
+ y_scale : self . y_scale . unwrap_or_default ( ) ,
341
+ color : self . color . value ( ) ,
342
+ font_name : workbook. register_option_str ( self . font_name . as_deref ( ) )
343
+ as * mut std:: ffi:: c_char ,
344
+ font_size : self . font_size . unwrap_or_default ( ) ,
345
+ font_family : self . font_family . unwrap_or_default ( ) ,
346
+ start_row : self . start_row ,
347
+ start_col : self . start_col ,
348
+ x_offset : self . x_offset ,
349
+ y_offset : self . y_offset ,
350
+ }
351
+ }
352
+ }
247
353
248
354
pub const LXW_DEF_ROW_HEIGHT : f64 = 8.43 ;
249
355
pub const LXW_DEF_ROW_HEIGHT_PIXELS : u32 = 20 ;
@@ -307,15 +413,16 @@ impl<'a> Worksheet<'a> {
307
413
row : WorksheetRow ,
308
414
col : WorksheetCol ,
309
415
text : & str ,
310
- options : & mut CommentOptions ,
416
+ options : & CommentOptions ,
311
417
) -> Result < ( ) , XlsxError > {
418
+ let mut options = options. into_internal ( self . _workbook ) ;
312
419
unsafe {
313
420
let result = libxlsxwriter_sys:: worksheet_write_comment_opt (
314
421
self . worksheet ,
315
422
row,
316
423
col,
317
- CString :: new ( text ) . unwrap ( ) . as_c_str ( ) . as_ptr ( ) ,
318
- options,
424
+ self . _workbook . register_str ( text ) ,
425
+ & mut options,
319
426
) ;
320
427
if result == libxlsxwriter_sys:: lxw_error_LXW_NO_ERROR {
321
428
Ok ( ( ) )
@@ -960,15 +1067,16 @@ impl<'a> Worksheet<'a> {
960
1067
row : WorksheetRow ,
961
1068
height : f64 ,
962
1069
format : Option < & Format > ,
963
- options : & mut RowColOptions ,
1070
+ options : & RowColOptions ,
964
1071
) -> Result < ( ) , XlsxError > {
965
1072
unsafe {
1073
+ let mut options = options. into_internal ( ) ;
966
1074
let result = libxlsxwriter_sys:: worksheet_set_row_opt (
967
1075
self . worksheet ,
968
1076
row,
969
1077
height,
970
1078
format. map ( |x| x. format ) . unwrap_or ( std:: ptr:: null_mut ( ) ) ,
971
- options,
1079
+ & mut options,
972
1080
) ;
973
1081
if result == libxlsxwriter_sys:: lxw_error_LXW_NO_ERROR {
974
1082
Ok ( ( ) )
@@ -1007,15 +1115,16 @@ impl<'a> Worksheet<'a> {
1007
1115
row : WorksheetRow ,
1008
1116
pixels : u32 ,
1009
1117
format : Option < & Format > ,
1010
- options : & mut RowColOptions ,
1118
+ options : & RowColOptions ,
1011
1119
) -> Result < ( ) , XlsxError > {
1120
+ let mut options = options. into_internal ( ) ;
1012
1121
unsafe {
1013
1122
let result = libxlsxwriter_sys:: worksheet_set_row_pixels_opt (
1014
1123
self . worksheet ,
1015
1124
row,
1016
1125
pixels,
1017
1126
format. map ( |x| x. format ) . unwrap_or ( std:: ptr:: null_mut ( ) ) ,
1018
- options,
1127
+ & mut options,
1019
1128
) ;
1020
1129
if result == libxlsxwriter_sys:: lxw_error_LXW_NO_ERROR {
1021
1130
Ok ( ( ) )
@@ -1054,16 +1163,17 @@ impl<'a> Worksheet<'a> {
1054
1163
last_col : WorksheetCol ,
1055
1164
width : f64 ,
1056
1165
format : Option < & Format > ,
1057
- options : & mut RowColOptions ,
1166
+ options : & RowColOptions ,
1058
1167
) -> Result < ( ) , XlsxError > {
1168
+ let mut options = options. into_internal ( ) ;
1059
1169
unsafe {
1060
1170
let result = libxlsxwriter_sys:: worksheet_set_column_opt (
1061
1171
self . worksheet ,
1062
1172
first_col,
1063
1173
last_col,
1064
1174
width,
1065
1175
format. map ( |x| x. format ) . unwrap_or ( std:: ptr:: null_mut ( ) ) ,
1066
- options,
1176
+ & mut options,
1067
1177
) ;
1068
1178
if result == libxlsxwriter_sys:: lxw_error_LXW_NO_ERROR {
1069
1179
Ok ( ( ) )
@@ -1104,14 +1214,15 @@ impl<'a> Worksheet<'a> {
1104
1214
format : Option < & Format > ,
1105
1215
options : & mut RowColOptions ,
1106
1216
) -> Result < ( ) , XlsxError > {
1217
+ let mut options = options. into_internal ( ) ;
1107
1218
unsafe {
1108
1219
let result = libxlsxwriter_sys:: worksheet_set_column_pixels_opt (
1109
1220
self . worksheet ,
1110
1221
first_col,
1111
1222
last_col,
1112
1223
pixels,
1113
1224
format. map ( |x| x. format ) . unwrap_or ( std:: ptr:: null_mut ( ) ) ,
1114
- options,
1225
+ & mut options,
1115
1226
) ;
1116
1227
if result == libxlsxwriter_sys:: lxw_error_LXW_NO_ERROR {
1117
1228
Ok ( ( ) )
0 commit comments