Exporting the Merged Cell : Exports the merged cell properly with testcase to verify the scenario (#76)
* adding the functionality of exporting the merged cell with testcase to vreify the above enhancement * addressing review comments : 1) moving the testing to appropriate folder 2) fixing lint errors 3) fixing the scenario when merge cell count is 0 * addressing 2nd round review comments : cosmetic fixes * addressing review comments : taking reference instead of cloning
This commit is contained in:
@@ -59,6 +59,7 @@ pub(crate) fn get_worksheet_xml(
|
||||
) -> String {
|
||||
let mut sheet_data_str: Vec<String> = vec![];
|
||||
let mut cols_str: Vec<String> = vec![];
|
||||
let mut merged_cells_str: Vec<String> = vec![];
|
||||
|
||||
for col in &worksheet.cols {
|
||||
// <col min="4" max="4" width="12" customWidth="1"/>
|
||||
@@ -241,6 +242,12 @@ pub(crate) fn get_worksheet_xml(
|
||||
))
|
||||
}
|
||||
let sheet_data = sheet_data_str.join("");
|
||||
|
||||
for merge_cell_ref in &worksheet.merge_cells {
|
||||
merged_cells_str.push(format!("<mergeCell ref=\"{merge_cell_ref}\"/>"))
|
||||
}
|
||||
let merged_cells_count = merged_cells_str.len();
|
||||
|
||||
let cols = cols_str.join("");
|
||||
let cols = if cols.is_empty() {
|
||||
"".to_string()
|
||||
@@ -280,6 +287,16 @@ pub(crate) fn get_worksheet_xml(
|
||||
}
|
||||
}
|
||||
|
||||
let merge_cells_section = if merged_cells_count > 0 {
|
||||
format!(
|
||||
"<mergeCells count=\"{}\">{}</mergeCells>",
|
||||
merged_cells_count,
|
||||
merged_cells_str.join("")
|
||||
)
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
|
||||
format!(
|
||||
"{XML_DECLARATION}
|
||||
<worksheet \
|
||||
@@ -295,6 +312,7 @@ xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">
|
||||
<sheetData>\
|
||||
{sheet_data}\
|
||||
</sheetData>\
|
||||
{merge_cells_section}\
|
||||
</worksheet>"
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user