This commit is contained in:
Elena.Subbotina
2021-11-30 17:49:51 +03:00
parent c100d54aa5
commit d71477e8a3
10 changed files with 59 additions and 26 deletions

View File

@ -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_;

View File

@ -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<xlsx_xml_worksheet_ptr> sheets_;
std::vector<oox_chart_context_ptr> charts_;
std::vector<std::wstring> table_parts_;
std::wstringstream defaultOutput_;
std::pair<double, double> maxDigitSize_;
std::pair<double, double> maxDigitSize_;
num_format_context num_format_context_;
size_t default_style_;
mediaitems_ptr mediaitems_;

View File

@ -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_);
}

View File

@ -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);

View File

@ -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_;

View File

@ -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<office_spreadsheet*>(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)

View File

@ -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();

View File

@ -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());

View File

@ -38,6 +38,7 @@
#include <xml/nodetype.h>
#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_;

View File

@ -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<std::wstring, OOX::Spreadsheet::CWorksheet*> &mapWorksheets = xlsx_document->m_mapWorksheets;
xlsx_current_container = dynamic_cast<OOX::IFileContainer*>(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)