Skip to content

Commit

Permalink
Fix sheet locking
Browse files Browse the repository at this point in the history
Excel protected the visible sheet. I do not know why and can only speculate that some reordering was not complete. Creating the hidden sheet second solves the issue.
  • Loading branch information
KochTobi committed Sep 16, 2024
1 parent eb906f2 commit ea44f52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,6 @@ public byte[] getContent() {
defineReadOnlyCellStyle(workbook);
defineBoldStyle(workbook);

Sheet hiddenSheet = workbook.createSheet("hidden");

Name sequencingReadTypeArea = createOptionArea(hiddenSheet,
"Sequencing read type", SequencingReadType.getOptions());

Sheet sheet = workbook.createSheet("NGS Measurement Metadata");

Row header = getOrCreateRow(sheet, 0);
Expand All @@ -201,6 +196,11 @@ public byte[] getContent() {
var generatedRowCount = rowIndex - startIndex;
assert generatedRowCount == measurements.size() : "all measurements have a corresponding row";

// make sure to create the visible sheet first
Sheet hiddenSheet = workbook.createSheet("hidden");
Name sequencingReadTypeArea = createOptionArea(hiddenSheet,
"Sequencing read type", SequencingReadType.getOptions());

XLSXTemplateHelper.addDataValidation(sheet,
NGSMeasurementColumns.SEQUENCING_READ_TYPE.columnIndex(),
startIndex,
Expand All @@ -209,7 +209,6 @@ public byte[] getContent() {
sequencingReadTypeArea);

setAutoWidth(sheet);
workbook.setSheetOrder(sheet.getSheetName(), 0);
workbook.setActiveSheet(0);

lockSheet(hiddenSheet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,8 @@ public byte[] getContent() {
font.setColor(new XSSFColor(DARK_GREY, new DefaultIndexedColorMap()));
readOnlyStyle.setFont(font);

Sheet hiddenSheet = workbook.createSheet("hidden");
Name digestionMethodArea = createOptionArea(hiddenSheet, "Digestion Method",
DigestionMethod.getOptions());

Sheet sheet = workbook.createSheet("Proteomics Measurement Metadata");

Row header = getOrCreateRow(sheet, 0);

for (ProteomicsMeasurementColumns measurementColumn : ProteomicsMeasurementColumns.values()) {
var cell = getOrCreateCell(header, measurementColumn.columnIndex());
cell.setCellValue(measurementColumn.headerName());
Expand All @@ -155,14 +149,18 @@ public byte[] getContent() {
var generatedRowCount = rowIndex - startIndex;
assert generatedRowCount == measurements.size() : "all measurements have a corresponding row";

// make sure to create the visible sheet first
Sheet hiddenSheet = workbook.createSheet("hidden");
Name digestionMethodArea = createOptionArea(hiddenSheet, "Digestion Method",
DigestionMethod.getOptions());

addDataValidation(sheet,
ProteomicsMeasurementColumns.DIGESTION_METHOD.columnIndex(), startIndex,
ProteomicsMeasurementColumns.DIGESTION_METHOD.columnIndex(),
DEFAULT_GENERATED_ROW_COUNT - 1,
digestionMethodArea);

setAutoWidth(sheet);
workbook.setSheetOrder(sheet.getSheetName(), 0);
workbook.setActiveSheet(0);

lockSheet(hiddenSheet);
Expand Down

0 comments on commit ea44f52

Please sign in to comment.