@@ -7,13 +7,14 @@ use itertools::Itertools;
77use lz_str:: compress_to_utf16;
88use serde_derive:: Serialize ;
99use serde_json:: json;
10- use simple_excel_writer:: * ;
1110use std:: collections:: { HashMap , HashSet } ;
11+ use std:: convert:: TryInto ;
1212use std:: fs;
1313use std:: io:: Write ;
1414use std:: path:: Path ;
1515use std:: str:: FromStr ;
1616use tera:: { Context , Tera } ;
17+ use xlsxwriter:: * ;
1718
1819type LookupTable = HashMap < String , HashMap < String , Vec < ( String , usize , usize ) > > > ;
1920
@@ -85,11 +86,11 @@ pub(crate) fn csv_report(
8586 for title in & titles {
8687 match is_numeric. get ( title) {
8788 Some ( true ) => {
88- let plot = num_plot ( table. clone ( ) , title. to_string ( ) ) ;
89+ let plot = num_plot ( & table, title. to_string ( ) ) ;
8990 num_plot_data. insert ( title, plot) ;
9091 }
9192 Some ( false ) => {
92- let plot = nominal_plot ( table. clone ( ) , title. to_string ( ) ) ;
93+ let plot = nominal_plot ( & table, title. to_string ( ) ) ;
9394 plot_data. insert ( title, plot) ;
9495 }
9596 _ => unreachable ! ( ) ,
@@ -118,28 +119,22 @@ pub(crate) fn csv_report(
118119 ( _, _) => { }
119120 }
120121
121- let mut wb = Workbook :: create ( & ( output_path. to_owned ( ) + "/report.xlsx" ) ) ;
122- let mut sheet = wb. create_sheet ( "Report" ) ;
123- for _ in 1 .. titles. len ( ) {
124- sheet. add_column ( Column { width : 50.0 } ) ;
122+ let wb = Workbook :: new ( & ( output_path. to_owned ( ) + "/report.xlsx" ) ) ;
123+ let mut sheet = wb. add_worksheet ( Some ( "Report" ) ) ? ;
124+ for ( i , title ) in titles. iter ( ) . enumerate ( ) {
125+ sheet. write_string ( 0 , i . try_into ( ) ? , title , None ) ? ;
125126 }
126127
127- wb. write_sheet ( & mut sheet, |sheet_writer| {
128- let sw = sheet_writer;
129- let mut title_row = Row :: new ( ) ;
130- for title in titles. clone ( ) {
131- title_row. add_cell ( title) ;
132- }
133- sw. append_row ( title_row) ?;
134- for row in table. clone ( ) {
135- let mut excel_row = Row :: new ( ) ;
136- for title in titles. clone ( ) {
137- excel_row. add_cell ( row. get ( title) . unwrap ( ) . as_str ( ) ) ;
138- }
139- sw. append_row ( excel_row) ?;
128+ for ( i, row) in table. iter ( ) . enumerate ( ) {
129+ for ( c, title) in titles. iter ( ) . enumerate ( ) {
130+ sheet. write_string (
131+ ( i + 1 ) . try_into ( ) ?,
132+ c. try_into ( ) ?,
133+ row. get ( * title) . unwrap ( ) ,
134+ None ,
135+ ) ?;
140136 }
141- Ok ( ( ) )
142- } ) ?;
137+ }
143138
144139 wb. close ( ) ?;
145140
@@ -341,7 +336,7 @@ pub(crate) fn csv_report(
341336 Ok ( ( ) )
342337}
343338
344- fn num_plot ( table : Vec < HashMap < String , String > > , column : String ) -> Vec < BinnedPlotRecord > {
339+ fn num_plot ( table : & [ HashMap < String , String > ] , column : String ) -> Vec < BinnedPlotRecord > {
345340 let mut values = Vec :: new ( ) ;
346341 let mut nan = 0 ;
347342 for row in table {
@@ -390,7 +385,7 @@ fn num_plot(table: Vec<HashMap<String, String>>, column: String) -> Vec<BinnedPl
390385 plot_data
391386}
392387
393- fn nominal_plot ( table : Vec < HashMap < String , String > > , column : String ) -> Vec < PlotRecord > {
388+ fn nominal_plot ( table : & [ HashMap < String , String > ] , column : String ) -> Vec < PlotRecord > {
394389 let mut values = Vec :: new ( ) ;
395390 for row in table {
396391 let val = row. get ( & column) . unwrap ( ) ;
0 commit comments