diff --git a/ASCOfficeOdfFile/src/docx/xlsxconversioncontext.cpp b/ASCOfficeOdfFile/src/docx/xlsxconversioncontext.cpp index 0da6ff76db..7086840dff 100644 --- a/ASCOfficeOdfFile/src/docx/xlsxconversioncontext.cpp +++ b/ASCOfficeOdfFile/src/docx/xlsxconversioncontext.cpp @@ -241,6 +241,13 @@ void xlsx_conversion_context::end_document() CP_XML_ATTR(L"xmlns", L"http://schemas.openxmlformats.org/spreadsheetml/2006/main"); CP_XML_ATTR(L"xmlns:r", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships"); + if (table_structure_protected_) + { + CP_XML_NODE(L"workbookProtection") + { + CP_XML_ATTR(L"lockStructure", 1); + } + } serialize_bookViews (CP_XML_STREAM()); CP_XML_NODE(L"sheets") @@ -609,7 +616,10 @@ void xlsx_conversion_context::start_office_spreadsheet(const odf_reader::office_ { spreadsheet_ = elm; } - +void xlsx_conversion_context::set_table_structure_protected(bool val) +{ + table_structure_protected_ = val; +} const odf_reader::office_element * xlsx_conversion_context::get_spreadsheet() { return spreadsheet_; diff --git a/ASCOfficeOdfFile/src/docx/xlsxconversioncontext.h b/ASCOfficeOdfFile/src/docx/xlsxconversioncontext.h index f7eae983d2..7e5645fc44 100644 --- a/ASCOfficeOdfFile/src/docx/xlsxconversioncontext.h +++ b/ASCOfficeOdfFile/src/docx/xlsxconversioncontext.h @@ -83,6 +83,8 @@ public: void start_document (); void end_document (); + void set_table_structure_protected(bool val); + void start_chart(std::wstring name); void end_chart (); @@ -189,12 +191,14 @@ private: const odf_reader::office_element *spreadsheet_; odf_reader::odf_document *odf_document_; + bool table_structure_protected_ = false; + std::vector sheets_; std::vector charts_; std::vector table_parts_; std::wstringstream defaultOutput_; - std::pair maxDigitSize_; + std::pair maxDigitSize_; num_format_context num_format_context_; size_t default_style_; mediaitems_ptr mediaitems_; diff --git a/ASCOfficeOdfFile/src/odf/odf_document_impl.cpp b/ASCOfficeOdfFile/src/odf/odf_document_impl.cpp index 12245558cc..4964a3b66c 100644 --- a/ASCOfficeOdfFile/src/odf/odf_document_impl.cpp +++ b/ASCOfficeOdfFile/src/odf/odf_document_impl.cpp @@ -1110,19 +1110,15 @@ bool odf_document::Impl::docx_convert(oox::docx_conversion_context & Context) if (bUserStopConvert !=0 ) return false; Context.process_styles(); - if (UpdateProgress(450000)) return false; Context.process_fonts(); Context.process_headers_footers(); - if (UpdateProgress(500000)) return false; Context.start_document(); if (content_xml_) content_xml_->docx_convert(Context); - - if (UpdateProgress(800000)) return false; - + Context.end_document(); // мы обрабатываем стили списка после того как сконвертировали документ, @@ -1141,21 +1137,17 @@ bool odf_document::Impl::xlsx_convert(oox::xlsx_conversion_context & Context) try { - _CP_LOG << L"[info] convert content" << std::endl; + _CP_LOG << L"[info] convert content" << std::endl; Context.start_document(); - if (UpdateProgress(450000)) return false; - + if (content_xml_) content_xml_->xlsx_convert(Context); - if (UpdateProgress(700000)) return false; Context.end_document(); - if (UpdateProgress(750000)) return false; _CP_LOG << L"[info] process styles" << std::endl; Context.process_styles(); - if (UpdateProgress(800000)) return false; Context.add_jsaProject(jsaProject_bin_); } @@ -1189,20 +1181,15 @@ bool odf_document::Impl::pptx_convert(oox::pptx_conversion_context & Context) _CP_LOG << L"[info] convert content" << std::endl; Context.start_document(); - if (UpdateProgress(450000)) return false; if (content_xml_) content_xml_->pptx_convert(Context); - if (UpdateProgress(700000)) return false; Context.process_layouts(); - if (UpdateProgress(750000)) return false; Context.process_master_pages(); - if (UpdateProgress(800000)) return false; Context.end_document(); - if (UpdateProgress(850000)) return false; Context.add_jsaProject(jsaProject_bin_); } diff --git a/ASCOfficeOdfFile/src/odf/office_spreadsheet.cpp b/ASCOfficeOdfFile/src/odf/office_spreadsheet.cpp index eb6d27ed38..65d37b0ed0 100644 --- a/ASCOfficeOdfFile/src/odf/office_spreadsheet.cpp +++ b/ASCOfficeOdfFile/src/odf/office_spreadsheet.cpp @@ -45,6 +45,13 @@ namespace odf_reader { const wchar_t * office_spreadsheet::ns = L"office"; const wchar_t * office_spreadsheet::name = L"spreadsheet"; +void office_spreadsheet::add_attributes(const xml::attributes_wc_ptr & Attributes) +{ + CP_APPLY_ATTR(L"table:structure-protected", table_structure_protected_); + CP_APPLY_ATTR(L"table:protection-key", table_protection_key_); + CP_APPLY_ATTR(L"table:protection-key-digest-algorithm", table_protection_key_digest_algorithm_); +} + void office_spreadsheet::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name) { if CP_CHECK_NAME(L"table", L"database-ranges") @@ -98,6 +105,10 @@ void office_spreadsheet::xlsx_convert(oox::xlsx_conversion_context & Context) Context.start_office_spreadsheet(this); _CP_LOG << L"[info][xlsx] process spreadsheet (" << content_.size() << L" tables)" << std::endl; + if (table_structure_protected_) + { + Context.set_table_structure_protected(*table_structure_protected_); + } if (user_fields_) user_fields_->xlsx_convert(Context); diff --git a/ASCOfficeOdfFile/src/odf/office_spreadsheet.h b/ASCOfficeOdfFile/src/odf/office_spreadsheet.h index 9e3676d9eb..5b321d1c7f 100644 --- a/ASCOfficeOdfFile/src/odf/office_spreadsheet.h +++ b/ASCOfficeOdfFile/src/odf/office_spreadsheet.h @@ -54,10 +54,14 @@ public: virtual void xlsx_convert(oox::xlsx_conversion_context & Context); private: - virtual void add_attributes( const xml::attributes_wc_ptr & Attributes ){} + virtual void add_attributes(const xml::attributes_wc_ptr & Attributes); virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name); public: + _CP_OPT(bool) table_structure_protected_; + _CP_OPT(std::wstring) table_protection_key_; + _CP_OPT(std::wstring) table_protection_key_digest_algorithm_; + office_element_ptr named_expressions_; office_element_ptr database_ranges_; office_element_ptr data_pilot_tables_; diff --git a/ASCOfficeOdfFileW/source/OdfFormat/ods_conversion_context.cpp b/ASCOfficeOdfFileW/source/OdfFormat/ods_conversion_context.cpp index ce802e73ba..88cb5d469a 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/ods_conversion_context.cpp +++ b/ASCOfficeOdfFileW/source/OdfFormat/ods_conversion_context.cpp @@ -86,7 +86,6 @@ ods_conversion_context::ods_conversion_context(package::odf_document * outputDoc font_metrix_ = _font_metrix(); } - void ods_conversion_context::start_document() { start_spreadsheet(); @@ -94,6 +93,11 @@ void ods_conversion_context::start_document() root_spreadsheet_ = dynamic_cast(get_current_object_element().get()); } +void ods_conversion_context::set_tables_structure_lock(bool val) +{ + root_spreadsheet_->table_structure_protected_ = val; +} + void ods_conversion_context::end_document() { if (table_context_.table_database_ranges_.root) diff --git a/ASCOfficeOdfFileW/source/OdfFormat/ods_conversion_context.h b/ASCOfficeOdfFileW/source/OdfFormat/ods_conversion_context.h index 2f174df750..e9c09ea232 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/ods_conversion_context.h +++ b/ASCOfficeOdfFileW/source/OdfFormat/ods_conversion_context.h @@ -66,6 +66,8 @@ public: virtual void start_document(); virtual void end_document(); + void set_tables_structure_lock(bool val); + void start_sheet(); void set_sheet_dimension(const std::wstring & ref); void end_sheet(); diff --git a/ASCOfficeOdfFileW/source/OdfFormat/office_spreadsheet.cpp b/ASCOfficeOdfFileW/source/OdfFormat/office_spreadsheet.cpp index 8660b70125..47d7477ec9 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/office_spreadsheet.cpp +++ b/ASCOfficeOdfFileW/source/OdfFormat/office_spreadsheet.cpp @@ -106,6 +106,8 @@ void office_spreadsheet::serialize(std::wostream & _Wostream) { CP_XML_NODE_SIMPLE() { + CP_XML_ATTR_OPT(L"table:structure-protected", table_structure_protected_); + if (forms_) forms_->serialize(CP_XML_STREAM()); diff --git a/ASCOfficeOdfFileW/source/OdfFormat/office_spreadsheet.h b/ASCOfficeOdfFileW/source/OdfFormat/office_spreadsheet.h index c0e1996140..db56458b13 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/office_spreadsheet.h +++ b/ASCOfficeOdfFileW/source/OdfFormat/office_spreadsheet.h @@ -38,6 +38,7 @@ #include #include "office_elements_create.h" +#include "bool.h" namespace cpdoccore { namespace odf_writer { @@ -58,6 +59,10 @@ public: virtual void serialize(std::wostream & _Wostream); + _CP_OPT(odf_types::Bool) table_structure_protected_; + _CP_OPT(std::wstring) table_protection_key_; + _CP_OPT(std::wstring) table_protection_key_digest_algorithm_; + office_element_ptr named_expressions_; office_element_ptr database_ranges_; office_element_ptr data_pilot_tables_; diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp index 2d647ec46e..0d912fa16c 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp @@ -178,6 +178,10 @@ void XlsxConverter::convert_sheets() pWorkbook = xlsx_document->m_pWorkbook; if (!pWorkbook) return; + if ((pWorkbook->m_oWorkbookProtection.IsInit()) && (pWorkbook->m_oWorkbookProtection->m_oLockStructure.IsInit())) + { + ods_context->set_tables_structure_lock(pWorkbook->m_oWorkbookProtection->m_oLockStructure->ToBool()); + } std::map &mapWorksheets = xlsx_document->m_mapWorksheets; xlsx_current_container = dynamic_cast(pWorkbook); @@ -892,27 +896,27 @@ void XlsxConverter::convert(OOX::Spreadsheet::CSheetProtection *oox_prot) if (oox_prot->m_oInsertColumns.IsInit()) { - ods_context->current_table()->set_table_protection_insert_columns(oox_prot->m_oInsertColumns->ToBool()); + ods_context->current_table()->set_table_protection_insert_columns(!oox_prot->m_oInsertColumns->ToBool()); } if (oox_prot->m_oInsertRows.IsInit()) { - ods_context->current_table()->set_table_protection_insert_rows(oox_prot->m_oInsertRows->ToBool()); + ods_context->current_table()->set_table_protection_insert_rows(!oox_prot->m_oInsertRows->ToBool()); } if (oox_prot->m_oDeleteColumns.IsInit()) { - ods_context->current_table()->set_table_protection_delete_columns(oox_prot->m_oDeleteColumns->ToBool()); + ods_context->current_table()->set_table_protection_delete_columns(!oox_prot->m_oDeleteColumns->ToBool()); } if (oox_prot->m_oDeleteRows.IsInit()) { - ods_context->current_table()->set_table_protection_delete_rows(oox_prot->m_oDeleteRows->ToBool()); + ods_context->current_table()->set_table_protection_delete_rows(!oox_prot->m_oDeleteRows->ToBool()); } if (oox_prot->m_oSelectLockedCells.IsInit()) { - ods_context->current_table()->set_table_protection_protected_cells(oox_prot->m_oSelectLockedCells->ToBool()); + ods_context->current_table()->set_table_protection_protected_cells(!oox_prot->m_oSelectLockedCells->ToBool()); } if (oox_prot->m_oSelectUnlockedCells.IsInit()) { - ods_context->current_table()->set_table_protection_unprotected_cells(oox_prot->m_oSelectUnlockedCells->ToBool()); + ods_context->current_table()->set_table_protection_unprotected_cells(!oox_prot->m_oSelectUnlockedCells->ToBool()); } } void XlsxConverter::convert(OOX::Spreadsheet::CDataValidations *oox_validations)