How to copy a spread sheet data to another spreadsheet using umya_spreadsheet

I have some large .xlsx files. I wanted to copy data of all these xlsx file in one large file with some additional data agains each row like timestamp when the data was copied. file_name from where the data is copied etc. I have written a code for doing so and it is working fine. But I am copying data cell by cell. Since my files are quite large I want to have some efficient method. The line of code that is copying data cell by cell is as follows:

pub fn insert_data_from_file (from_file: &std::path::Path, to_file: &std::path::Path) -> Result<(), std::io::Error> {

    let  file_name = from_file.file_name().unwrap().to_owned().into_string().unwrap();

    let mut output_ss = reader::xlsx::read(to_file).unwrap();
    let output_ws = output_ss.get_sheet_mut(&0).unwrap();
     let input_ss = reader::xlsx::read(from_file).unwrap();
     let input_ws = input_ss.get_sheet(&0).unwrap();

    let (output_ws_highest_col_index, output_ws_highest_row_index) = output_ws.get_highest_column_and_row();
    let (input_ws_highest_col_index, input_ws_highest_row_index) = input_ws.get_highest_column_and_row();

    let mut output_ws_current_row_index: u32 = 1;
    let mut output_ws_current_col_index: u32 = 1;

    let mut input_ws_current_col_index = 0;
    let mut input_ws_current_row_index = 1;

    //insert data from file into combine spreadsheet. It is copying data cell by cell,
    //I want to copy all the sheet at once or row by row
    //so that the speed can be imporved.
    for cell in  input_ws.get_cell_value_by_range(&input_ws.calculate_worksheet_dimension()) {

        if input_ws_current_col_index < input_ws_highest_col_index {
            input_ws_current_col_index += 1;
        } else {
            input_ws_current_col_index = 1;
            input_ws_current_row_index +=1;


        if output_ws_highest_row_index ==1 || input_ws_current_row_index > 1  {

            if output_ws_current_col_index < input_ws_highest_col_index+5 {
                output_ws_current_col_index += 1;
            } else {
                output_ws_current_col_index = 1;
                output_ws_current_row_index += 1;

            output_ws.get_cell_value_mut((output_ws_current_col_index, output_ws_current_row_index)).set_value(cell.get_value());


    let _ = writer::xlsx::write(&output_ss, to_file);


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.