diff --git a/NEWS b/NEWS index e9b6610562ec0bc6adc3d1d84756d13282e21f53..2f625a5a3fca87176d6082af57b807a5a161bdf2 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ Gnumeric 1.6.3 Klokan Pridal: * Implement xml saving/loading of "protected" attribute. [#334257] + * Implement xls saving/loading of "protected" attribute. [#330129] Morten: * Fix printing issue when sheet is zoomed. [#332932] diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog index a4e567054bd07fd6e376c652a45ad02da701143e..10b7dbe4828519f2c3a54970923e84a9ff880174 100644 --- a/plugins/excel/ChangeLog +++ b/plugins/excel/ChangeLog @@ -1,3 +1,11 @@ +2006-03-13 Morten Welinder + + * ms-excel-write.c (write_sheet_head): Write protection flags. + * ms-excel-read.c (excel_read_sheet_PROTECT): Store falg. + (excel_read_workbook_PROTECT): New function. + (excel_read_workbook): Read protection flags. + Patch from Klokan Petr Pridal. [#330129] + 2006-03-10 Jody Goldberg * ms-formula-read.c (excel_parse_formula) : back port handling of diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c index d00248e8fddc45cee10fc3847daf46c170c72ee1..e91e85bc793aeb2c32709f77f834e9f61c92d870 100644 --- a/plugins/excel/ms-excel-read.c +++ b/plugins/excel/ms-excel-read.c @@ -4199,19 +4199,35 @@ sheet_container (ExcelReadSheet *esheet) } static gboolean -excel_read_PROTECT (BiffQuery *q, char const *obj_type) +excel_read_sheet_PROTECT (BiffQuery *q, ExcelReadSheet *esheet) { - /* TODO: Use this information when gnumeric supports protection */ gboolean is_protected = TRUE; /* MS Docs fail to mention that in some stream this * record can have size zero. I assume the in that * case its existence is the flag. */ - if (q->length > 0) + if (q->length >= 2) is_protected = (1 == GSF_LE_GET_GUINT16 (q->data)); - d (1,if (is_protected) fprintf (stderr,"%s is protected\n", obj_type);); + esheet->sheet->is_protected = is_protected; + + return is_protected; +} + +static gboolean +excel_read_workbook_PROTECT (BiffQuery *q, WorkbookView *wb_view) +{ + gboolean is_protected = TRUE; + + /* MS Docs fail to mention that in some stream this + * record can have size zero. I assume the in that + * case its existence is the flag. + */ + if (q->length >= 2) + is_protected = (1 == GSF_LE_GET_GUINT16 (q->data)); + + wb_view->is_protected = is_protected; return is_protected; } @@ -5547,7 +5563,8 @@ excel_read_sheet (BiffQuery *q, GnmXLImporter *importer, case BIFF_REFMODE: excel_read_REFMODE (q, esheet); break; case BIFF_DELTA: excel_read_DELTA (q, importer); break; case BIFF_ITERATION: excel_read_ITERATION (q, importer); break; - case BIFF_PROTECT: excel_read_PROTECT (q, "Sheet"); break; + case BIFF_OBJPROTECT: + case BIFF_PROTECT: excel_read_sheet_PROTECT (q, esheet); break; case BIFF_PASSWORD: if (q->length == 2) { @@ -5633,7 +5650,6 @@ excel_read_sheet (BiffQuery *q, GnmXLImporter *importer, case BIFF_SAVERECALC: break; case BIFF_TAB_COLOR: excel_read_TAB_COLOR (q, esheet); break; - case BIFF_OBJPROTECT: excel_read_PROTECT (q, "Sheet"); break; case BIFF_COLINFO: excel_read_COLINFO (q, esheet); break; case BIFF_RK: @@ -6082,7 +6098,7 @@ excel_read_workbook (IOContext *context, WorkbookView *wb_view, GsfInput *input, case BIFF_OBJPROTECT: case BIFF_PROTECT: - excel_read_PROTECT (q, "Workbook"); + excel_read_workbook_PROTECT (q, wb_view); break; case BIFF_PASSWORD: diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c index dc1fca4691bda3f5a8c07ad74653f8755cf8b1cc..d7e903bd2a00441204d39bc91e7ac8ba4a7c749f 100644 --- a/plugins/excel/ms-excel-write.c +++ b/plugins/excel/ms-excel-write.c @@ -4077,6 +4077,12 @@ write_sheet_head (BiffPut *bp, ExcelWriteSheet *esheet) * to make our lives easier */ excel_write_externsheets_v7 (esheet->ewb); } + if (sheet->is_protected) { + ms_biff_put_2byte (bp, BIFF_PROTECT, 1 ); + ms_biff_put_2byte (bp, BIFF_OBJPROTECT, 1); + ms_biff_put_2byte (bp, BIFF_SCENPROTECT, 1); + ms_biff_put_2byte (bp, BIFF_PASSWORD, 0); + } excel_write_DEFCOLWIDTH (bp, esheet); excel_write_colinfos (bp, esheet); excel_write_AUTOFILTERINFO (bp, esheet); @@ -5191,7 +5197,7 @@ excel_write_workbook (ExcelWriteState *ewb) } ms_biff_put_2byte (ewb->bp, BIFF_WINDOWPROTECT, 0); - ms_biff_put_2byte (ewb->bp, BIFF_PROTECT, 0); + ms_biff_put_2byte (ewb->bp, BIFF_PROTECT, ewb->gnum_wb_view->is_protected ? 1 : 0); ms_biff_put_2byte (ewb->bp, BIFF_PASSWORD, 0); if (bp->version >= MS_BIFF_V8) {