Skip to content
Snippets Groups Projects
Commit c22f2d55 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Export to XLSX: In the CF and PV tabs, hide all columns without any values

As we have dozens of different cost variants, most of them are not relevant to a given product, so we simply hide those columns (for prototyping / finding implementation errors/debuggin, one can unhide those).
parent 69cd5bbd
Branches
Tags
No related merge requests found
...@@ -704,10 +704,16 @@ exportAbsCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c( ...@@ -704,10 +704,16 @@ exportAbsCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(
crow crow
} }
# Return list of all column indices witout any non-zero entries => these columns are to be hidden later
empty.col.indices = function(df) {
unname(which(colSums(df != 0) == 0))
}
exportPVTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), seprows = 5, freeze = TRUE) { exportPVTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), seprows = 5, freeze = TRUE) {
if (!is.null(contract$Values$presentValues)) { if (!is.null(contract$Values$presentValues)) {
id = contract$Parameters$ContractData$id id = contract$Parameters$ContractData$id
nrrow = contract$Values$int$l nrrow = contract$Values$int$l
empty.cols = c()
blockid.row = crow blockid.row = crow
crow = crow + 2 crow = crow + 2
...@@ -729,6 +735,7 @@ exportPVTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), ...@@ -729,6 +735,7 @@ exportPVTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(),
w1 = writePremiumCoefficients(wb, sheet, contract$Values$premiumCoefficients, type = "benefits", crow = crow, ccol = cl - 2, tarif = contract$tarif); w1 = writePremiumCoefficients(wb, sheet, contract$Values$premiumCoefficients, type = "benefits", crow = crow, ccol = cl - 2, tarif = contract$tarif);
area.premiumcoeff = paste0(int2col(cl), "%d:", int2col(cl + w1 - 1), "%d"); area.premiumcoeff = paste0(int2col(cl), "%d:", int2col(cl + w1 - 1), "%d");
area.premiumvals = paste0("$", int2col(cl), "$", crow + 6 + 2 + tPrem, ":$", int2col(cl + w1 - 1), "$", crow + 6 + 2 + tPrem); area.premiumvals = paste0("$", int2col(cl), "$", crow + 6 + 2 + tPrem, ":$", int2col(cl + w1 - 1), "$", crow + 6 + 2 + tPrem);
empty.cols = c(empty.cols, empty.col.indices(contract$Values$presentValues) - 1 + cl)
cl = cl + writeValuesTable(wb, sheet, as.data.frame(setInsuranceValuesLabels(contract$Values$presentValues)), cl = cl + writeValuesTable(wb, sheet, as.data.frame(setInsuranceValuesLabels(contract$Values$presentValues)),
crow = crow + 6, ccol = cl, tableName = tableName("PresentValues_Benefits_", id), styles = styles, crow = crow + 6, ccol = cl, tableName = tableName("PresentValues_Benefits_", id), styles = styles,
caption = "Leistungsbarwerte", valueStyle = styles$pv0) + 1; caption = "Leistungsbarwerte", valueStyle = styles$pv0) + 1;
...@@ -736,6 +743,7 @@ exportPVTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), ...@@ -736,6 +743,7 @@ exportPVTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(),
w2 = writePremiumCoefficients(wb, sheet, contract$Values$premiumCoefficients, type = "costs", crow = crow, ccol = cl - 2, tarif = contract$tarif); w2 = writePremiumCoefficients(wb, sheet, contract$Values$premiumCoefficients, type = "costs", crow = crow, ccol = cl - 2, tarif = contract$tarif);
area.costcoeff = paste0(int2col(cl), "%d:", int2col(cl + w2 - 1), "%d"); area.costcoeff = paste0(int2col(cl), "%d:", int2col(cl + w2 - 1), "%d");
area.costvals = paste0("$", int2col(cl), "$", crow + 6 + 2 + tPrem, ":$", int2col(cl + w2 - 1), "$", crow + 6 + 2 + tPrem); area.costvals = paste0("$", int2col(cl), "$", crow + 6 + 2 + tPrem, ":$", int2col(cl + w2 - 1), "$", crow + 6 + 2 + tPrem);
empty.cols = c(empty.cols, empty.col.indices(as.data.frame(costPV)) - 1 + cl)
cl = cl + writeValuesTable(wb, sheet, as.data.frame(costPV), cl = cl + writeValuesTable(wb, sheet, as.data.frame(costPV),
crow = crow + 6, ccol = cl, tableName = tableName("PresentValues_Costs_", id), styles = styles, crow = crow + 6, ccol = cl, tableName = tableName("PresentValues_Costs_", id), styles = styles,
caption = "Kostenbarwerte", valueStyle = styles$cost0) + 1; caption = "Kostenbarwerte", valueStyle = styles$cost0) + 1;
...@@ -762,11 +770,14 @@ exportPVTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), ...@@ -762,11 +770,14 @@ exportPVTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(),
} }
for (b in contract$blocks) { for (b in contract$blocks) {
crow = exportPVTable( res = exportPVTable(
wb = wb, sheet = sheet, contract = b, wb = wb, sheet = sheet, contract = b,
ccol = ccol, crow = crow, styles = styles, seprows = seprows, freeze = FALSE) ccol = ccol, crow = crow, styles = styles, seprows = seprows, freeze = FALSE)
# exportPVTable returns a list of the next excel table row and a list of all empty columns (to be hidden later on)
crow = res$crow
empty.cols = intersect(empty.cols, res$empty.cols)
} }
crow list(crow = crow, empty.cols = empty.cols)
} }
exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), seprows = 5, freeze = TRUE) { exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), seprows = 5, freeze = TRUE) {
...@@ -774,6 +785,7 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), ...@@ -774,6 +785,7 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(),
if (!is.null(contract$Values$cashFlows)) { if (!is.null(contract$Values$cashFlows)) {
id = contract$Parameters$ContractData$id id = contract$Parameters$ContractData$id
nrrow = contract$Values$int$l nrrow = contract$Values$int$l
empty.cols = c()
blockid.row = crow blockid.row = crow
crow = crow + 2 crow = crow + 2
...@@ -786,11 +798,13 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), ...@@ -786,11 +798,13 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(),
cl = ccol cl = ccol
cl = cl + writeAgeQTable(wb, sheet, probs = qp, crow = crow, ccol = cl, styles = styles); cl = cl + writeAgeQTable(wb, sheet, probs = qp, crow = crow, ccol = cl, styles = styles);
empty.cols = c(empty.cols, empty.col.indices(contract$Values$cashFlows)- 1 + cl)
cl = cl + writeValuesTable( cl = cl + writeValuesTable(
wb, sheet, setInsuranceValuesLabels(contract$Values$cashFlows), wb, sheet, setInsuranceValuesLabels(contract$Values$cashFlows),
crow = crow, ccol = cl, tableName = tableName("CF_", id), styles = styles, crow = crow, ccol = cl, tableName = tableName("CF_", id), styles = styles,
caption = "Leistungscashflows", valueStyle = styles$hide0) + 1; caption = "Leistungscashflows", valueStyle = styles$hide0) + 1;
costCF = costValuesAsDF(setInsuranceValuesLabels(contract$Values$cashFlowsCosts)) costCF = costValuesAsDF(setInsuranceValuesLabels(contract$Values$cashFlowsCosts))
empty.cols = c(empty.cols, empty.col.indices(costCF)- 1 + cl)
cl = cl + writeValuesTable( cl = cl + writeValuesTable(
wb, sheet, costCF, wb, sheet, costCF,
crow = crow, ccol = cl, tableName = tableName("CFcosts_", id), styles = styles, crow = crow, ccol = cl, tableName = tableName("CFcosts_", id), styles = styles,
...@@ -801,11 +815,14 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), ...@@ -801,11 +815,14 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(),
} }
for (b in contract$blocks) { for (b in contract$blocks) {
crow = exportCFTable( res = exportCFTable(
wb = wb, sheet = sheet, contract = b, wb = wb, sheet = sheet, contract = b,
ccol = ccol, crow = crow, styles = styles, seprows = seprows, freeze = FALSE) ccol = ccol, crow = crow, styles = styles, seprows = seprows, freeze = FALSE)
# exportCFTable returns a list of the next excel table row and a list of all empty columns (to be hidden later on)
crow = res$crow
empty.cols = intersect(empty.cols, res$empty.cols)
} }
crow list(crow = crow, empty.cols = empty.cols)
} }
...@@ -976,9 +993,12 @@ exportInsuranceContract.xlsx = function(contract, filename) { ...@@ -976,9 +993,12 @@ exportInsuranceContract.xlsx = function(contract, filename) {
# TODO-blocks # TODO-blocks
sheet = "Barwerte"; sheet = "Barwerte";
addValuesWorksheet(wb, sheet); addValuesWorksheet(wb, sheet);
exportPVTable( res = exportPVTable(
wb = wb, sheet = sheet, contract = contract, wb = wb, sheet = sheet, contract = contract,
ccol = 1, crow = 4,styles = styles) ccol = 1, crow = 4,styles = styles)
if (length(res$empty.cols) > 0) {
setColWidths(wb, sheet = sheet, cols = res$empty.cols, hidden = TRUE)
}
############################################## # ############################################## #
...@@ -987,9 +1007,12 @@ exportInsuranceContract.xlsx = function(contract, filename) { ...@@ -987,9 +1007,12 @@ exportInsuranceContract.xlsx = function(contract, filename) {
sheet = "Cash-Flows"; sheet = "Cash-Flows";
addValuesWorksheet(wb, sheet); addValuesWorksheet(wb, sheet);
exportCFTable( res = exportCFTable(
wb = wb, sheet = sheet, contract = contract, wb = wb, sheet = sheet, contract = contract,
ccol = 1, crow = 4, styles = styles) ccol = 1, crow = 4, styles = styles)
if (length(res$empty.cols) > 0) {
setColWidths(wb, sheet = sheet, cols = res$empty.cols, hidden = TRUE)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment