Commit ad40f51d authored by ElenaSubbotina's avatar ElenaSubbotina

OdsFormatReader - fix after testing

parent 1f9e3f4f
......@@ -454,7 +454,7 @@ namespace formulasconvert {
// boost::match_default | boost::format_all);
bool isFormula = check_formula(workstr);
boost::regex_replace(
workstr,
boost::wregex(L"('.*?')|(\".*?\")"),
......@@ -477,6 +477,12 @@ namespace formulasconvert {
}
//todooo INDEX((A1:C6~A8:C11),2,2,2) - ???? - INDEX_emb.ods
}
else
{
size_t sz_workstr = workstr.length();
if (workstr.substr(0, min(3, sz_workstr)) == L"of:")//sample_02neu_crashes.ods
workstr = workstr.substr(3);
}
//-----------------------------------------------------------
......
......@@ -800,7 +800,7 @@ bool docx_conversion_context::process_page_properties(std::wostream & strm)
if (page_layout_instance_)
{
page_layout_instance_->docx_convert_serialize(strm, *this);
page_layout_instance_->docx_serialize(strm, *this);
}
else
{
......
......@@ -281,6 +281,11 @@ void xlsx_conditionalFormatting_context::set_formula(std::wstring f)
impl_->conditionalFormattings_.back().rules.back().formula_type = L"expression";
impl_->conditionalFormattings_.back().rules.back().formula = converter.convert_named_expr(val);
}
else if (0 <= (pos = f.find(L"is-error")))
{
impl_->conditionalFormattings_.back().rules.back().formula_type = L"containsErrors";
impl_->conditionalFormattings_.back().rules.back().formula = L"0";
}
else if (0 <= (pos = f.find(L"duplicate")))
{
impl_->conditionalFormattings_.back().rules.back().formula_type = L"duplicateValues";
......
......@@ -38,6 +38,8 @@
#include <cpdoccore/xml/simple_xml_writer.h>
#include"../../Common/DocxFormat/Source/XML/Utils.h"
#include"../../Common/DocxFormat/Source/base/types_32.h"
#include <map>
namespace cpdoccore {
......@@ -80,6 +82,7 @@ public:
bool repeat_item_labels = true;
int type_groups = 0;
int sort = 0;
std::wstring source_groups;
std::vector<int> subtotals;
......@@ -143,9 +146,13 @@ public:
bool data_on_row = false;
}current_;
void sort_fields();
void serialize_view(std::wostream & strm);
void serialize_cache(std::wostream & strm);
void serialize_type_field(CP_ATTR_NODE, _field & field);
private:
bool clear_header_map(std::map<size_t, size_t> & map)
{//отсев по секонд - нужны тока повторы
......@@ -243,12 +250,27 @@ private:
}
connections_ += strm.str();
}
};
xlsx_pivots_context::xlsx_pivots_context() : impl_(new xlsx_pivots_context::Impl())
{
}
void xlsx_pivots_context::Impl::sort_fields()
{
for (size_t i = 0; i < current_.fields.size(); i++)
{
if (current_.fields[i].type == 7)
continue;
if (!current_.fields[i].source_groups.empty() && i != current_.fields.size() -1)
{
current_.fields.push_back(current_.fields[i]);
current_.fields.erase(current_.fields.begin() + i , current_.fields.begin() + i + 1);
i--;
}
}
}
void xlsx_pivots_context::Impl::serialize_view(std::wostream & strm)
{
if (current_.headers.empty()) return;
......@@ -403,6 +425,7 @@ void xlsx_pivots_context::Impl::serialize_view(std::wostream & strm)
CP_XML_ATTR(L"colPageCount", 1);
}
}
std::map<std::wstring, bool> used_field_name;
CP_XML_NODE(L"pivotFields")
{
CP_XML_ATTR(L"count", current_.fields_count);
......@@ -411,6 +434,11 @@ void xlsx_pivots_context::Impl::serialize_view(std::wostream & strm)
if (current_.fields[i].type == 7)
continue;
if (used_field_name.end() != used_field_name.find(current_.fields[i].name))
continue;
used_field_name.insert(std::make_pair(current_.fields[i].name, true));
CP_XML_NODE(L"pivotField")
{
switch(current_.fields[i].type)
......@@ -554,9 +582,90 @@ void xlsx_pivots_context::Impl::serialize_view(std::wostream & strm)
}
}
}
void xlsx_pivots_context::Impl::serialize_type_field(CP_ATTR_NODE, _field & field)
{
_CP_OPT(bool) containsSemiMixedTypes;
_CP_OPT(bool) containsMixedTypes;
_CP_OPT(bool) containsNonDate;
_CP_OPT(bool) containsDate;
_CP_OPT(bool) containsString;
_CP_OPT(bool) containsBlank;
_CP_OPT(bool) containsNumber;
_CP_OPT(bool) containsInteger;
if (field.bDate & field.bNumber/* ||
field.bNumber & field.bString*/)
{
containsSemiMixedTypes = true;
}
else if (field.bDate & field.bString ||
field.bNumber & field.bString ||
field.bInteger & field.bString)
{
containsMixedTypes = true;
if (field.bInteger)
{
if (field.bNumber) field.bInteger = false;
field.bNumber = true;
}
}
else if (!field.bEmpty && !field.bString && !field.bBool)
{
containsSemiMixedTypes = false;
}
if (field.bDate &&
!(field.bNumber || field.bInteger || field.bString || field.bEmpty ))
{
containsNonDate = false;
}
if (field.bDate)
{
containsDate = true;
}
if (!field.bString &&
(field.bInteger || field.bDate || field.bNumber || field.bEmpty))
{
containsString = false;
if (field.bInteger)
{
if (field.bNumber) field.bInteger = false;
field.bNumber = true;
}
if (/*!field.bDate && */field.bEmpty)
containsNonDate = false;
}
if (field.bEmpty)
{
containsBlank = true;
}
if (field.bNumber)
{
containsNumber = true;
}
if (field.bInteger && !field.bDate)
{
if (containsMixedTypes)
{
containsNumber = true;
containsInteger = true;
}
else
containsInteger = true;
}
if (containsNonDate) CP_XML_ATTR(L"containsNonDate", *containsNonDate);
if (containsSemiMixedTypes) CP_XML_ATTR(L"containsSemiMixedTypes", *containsSemiMixedTypes);
if (containsString) CP_XML_ATTR(L"containsString", *containsString);
if (containsBlank) CP_XML_ATTR(L"containsBlank", *containsBlank);
if (containsMixedTypes) CP_XML_ATTR(L"containsMixedTypes", *containsMixedTypes);
if (containsDate) CP_XML_ATTR(L"containsDate", *containsDate);
if (containsNumber) CP_XML_ATTR(L"containsNumber", *containsNumber);
if (containsInteger) CP_XML_ATTR(L"containsInteger", *containsInteger);
}
void xlsx_pivots_context::Impl::serialize_cache(std::wostream & strm)
{
std::map<std::wstring, bool> used_field_name;
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"pivotCacheDefinition")
......@@ -611,16 +720,26 @@ void xlsx_pivots_context::Impl::serialize_cache(std::wostream & strm)
if (current_.fields[i].type == 7)
continue;
if (used_field_name.end() != used_field_name.find(current_.fields[i].name))
continue;
used_field_name.insert(std::make_pair(current_.fields[i].name, true));
CP_XML_NODE(L"cacheField")
{
CP_XML_ATTR(L"name", current_.fields[i].name);
CP_XML_ATTR(L"numFmtId", 0);
if (!current_.fields[i].source_groups.empty())
{
CP_XML_ATTR(L"databaseField", 0);
}
CP_XML_NODE(L"sharedItems")
{
if (current_.fields[i].caches.empty() == false/* &&
current_.fields[i].type != 2*/)
{
{
if (current_.fields[i].type_groups == 0)
{
CP_XML_ATTR(L"count", current_.fields[i].caches.size());
......@@ -630,48 +749,8 @@ void xlsx_pivots_context::Impl::serialize_cache(std::wostream & strm)
current_.fields[i].bDate = true;
current_.fields[i].bString = false;
}
if ((current_.fields[i].bDate & current_.fields[i].bNumber) ||
(current_.fields[i].bNumber & current_.fields[i].bString))
{
CP_XML_ATTR(L"containsSemiMixedTypes", 1);
}
else if (current_.fields[i].bDate & current_.fields[i].bString)
{
CP_XML_ATTR(L"containsMixedTypes", 1);
}
else if (!current_.fields[i].bEmpty && !current_.fields[i].bString && !current_.fields[i].bBool)
{
CP_XML_ATTR(L"containsSemiMixedTypes", 0);
}
if (current_.fields[i].bDate &&
!(current_.fields[i].bNumber || current_.fields[i].bInteger || current_.fields[i].bString || current_.fields[i].bEmpty ))
{
CP_XML_ATTR(L"containsNonDate", 0);
}
if (current_.fields[i].bDate) CP_XML_ATTR(L"containsDate", 1);
if (!current_.fields[i].bString &&
(current_.fields[i].bInteger || current_.fields[i].bDate || current_.fields[i].bNumber || current_.fields[i].bEmpty))
{
CP_XML_ATTR(L"containsString", 0);
}
if (current_.fields[i].bEmpty) CP_XML_ATTR(L"containsBlank", 1);
if (current_.fields[i].bNumber) CP_XML_ATTR(L"containsNumber", 1);
if (current_.fields[i].bInteger && !current_.fields[i].bDate)
{
if (current_.fields[i].bString)
{
CP_XML_ATTR(L"containsInteger", 1);
}
else if (!current_.fields[i].bNumber)
{
CP_XML_ATTR(L"containsNumber", 1);
CP_XML_ATTR(L"containsInteger", 1);
}
}
serialize_type_field(CP_GET_XML_NODE(), current_.fields[i]);
if ( current_.fields[i].type_groups == 0 )
{
for (size_t j = 0; j < current_.fields[i].caches.size(); j++)
......@@ -691,7 +770,7 @@ void xlsx_pivots_context::Impl::serialize_cache(std::wostream & strm)
{
CP_XML_NODE(L"fieldGroup")
{
CP_XML_ATTR(L"base", i);
CP_XML_ATTR(L"base", 0);
CP_XML_NODE(L"rangePr")
{
switch(current_.fields[i].type_groups)
......@@ -823,6 +902,8 @@ int xlsx_pivots_context::end_table()
std::wstringstream view_strm;
std::wstringstream cache_strm;
std::wstringstream rec_strm;
impl_->sort_fields();
impl_->serialize_view(view_strm);
impl_->serialize_cache(cache_strm);
......@@ -973,6 +1054,10 @@ void xlsx_pivots_context::set_field_groups(int type)
{
impl_->current_.fields.back().type_groups = type + 1;
}
void xlsx_pivots_context::set_field_groups_source(std::wstring name)
{
impl_->current_.fields.back().source_groups = name;
}
void xlsx_pivots_context::set_field_sort(int type)
{
impl_->current_.fields.back().sort = type + 1;
......@@ -1002,15 +1087,16 @@ void xlsx_pivots_context::add_field_cache(int index, std::wstring value)
_CP_OPT(double) dVal;
if (pos >= 0)//финановый .. todooo общее правило бы...
{
value = value.substr(pos + 1);
XmlUtils::replace_all(value, L",", L"");
XmlUtils::replace_all(value, L" ", L"");
XmlUtils::replace_all(value, L"\x00A0", L"");
//value = value.substr(pos + 1);
//XmlUtils::replace_all(value, L",", L"");
//XmlUtils::replace_all(value, L" ", L"");
//XmlUtils::replace_all(value, L"\x00A0", L"");
}
if (oox::IsNumber(value))
{
try
{
XmlUtils::replace_all(value, L",", L".");
dVal = boost::lexical_cast<double>(value);
}
catch(...)
......@@ -1021,7 +1107,7 @@ void xlsx_pivots_context::add_field_cache(int index, std::wstring value)
{
node_name = L"n";
int iVal = *dVal;
_INT64 iVal = *dVal;
if (abs(iVal - *dVal) > 0.00001)
{
value = std::to_wstring(*dVal);
......
......@@ -60,6 +60,7 @@ public:
void set_field_data_layout (bool val);
void set_field_sort (int type);
void set_field_groups (int type);
void set_field_groups_source(std::wstring name);
void set_repeat_item_labels(bool val);
void end_field();
......
......@@ -358,7 +358,18 @@ void xlsx_table_state::serialize_page_properties (std::wostream & strm)
page_layout->xlsx_serialize(strm, *context_);
}
void xlsx_table_state::serialize_background (std::wostream & strm)
{
if (tableBackground_.empty()) return;
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"picture")
{
CP_XML_ATTR(L"r:id", tableBackground_);
}
}
}
void xlsx_table_state::serialize_table_format (std::wostream & strm)
{
odf_reader::odf_read_context & odfContext = context_->root()->odf_context();
......
......@@ -120,10 +120,12 @@ public:
xlsx_conditionalFormatting_context & get_conditionalFormatting_context() {return xlsx_conditionalFormatting_context_;}
void table_column_last_width(double w) { table_column_last_width_ = w; }
double table_column_last_width() const { return table_column_last_width_; };
double table_column_last_width() const { return table_column_last_width_; };
void start_hyperlink ();
std::wstring end_hyperlink (std::wstring const & ref, std::wstring const & href, std::wstring const & display);
std::wstring end_hyperlink (std::wstring const & ref, std::wstring const & href, std::wstring const & display);
void set_background (std::wstring rId) { tableBackground_ = rId; }
void serialize_conditionalFormatting (std::wostream & _Wostream);
void serialize_table_format (std::wostream & _Wostream);
......@@ -131,6 +133,7 @@ public:
void serialize_hyperlinks (std::wostream & _Wostream);
void serialize_ole_objects (std::wostream & _Wostream);
void serialize_page_properties (std::wostream & _Wostream);
void serialize_background (std::wostream & _Wostream);
void dump_rels_hyperlinks (rels & Rels);
void dump_rels_ole_objects (rels & Rels);
......@@ -154,6 +157,7 @@ private:
std::wstring tableName_;
int tableId_;
std::wstring tableBackground_;
std::wstring table_style_;
std::wstring table_row_style_;
......
......@@ -320,6 +320,10 @@ void xlsx_table_context::serialize_page_properties(std::wostream & _Wostream)
{
return state()->serialize_page_properties(_Wostream);
}
void xlsx_table_context::serialize_background(std::wostream & _Wostream)
{
return state()->serialize_background(_Wostream);
}
void xlsx_table_context::serialize_hyperlinks(std::wostream & _Wostream)
{
return state()->serialize_hyperlinks(_Wostream);
......
......@@ -90,6 +90,7 @@ public:
void serialize_hyperlinks (std::wostream & _Wostream);
void serialize_ole_objects (std::wostream & _Wostream);
void serialize_page_properties (std::wostream & _Wostream);
void serialize_background (std::wostream & _Wostream);
xlsx_table_metrics & get_table_metrics();
......
......@@ -47,7 +47,7 @@ namespace oox {
bool IsNumber(const std::wstring &value)
{
boost::wregex rule(L"\\-?^[0-9]*[.,]?[0-9]*$");
boost::wregex rule(L"^\\-{0,1}[0-9]*[.,]{0,1}[0-9]*$");
boost::match_results<std::wstring::const_iterator> results;
return boost::regex_search(value/*.begin(), value.end(), results*/, rule);
......
......@@ -475,9 +475,10 @@ void xlsx_conversion_context::end_table()
{
CP_XML_ATTR(L"r:id", drawingName.second);
}
}
}
}
get_table_context().serialize_background (current_sheet().drawing());
}
if (!get_comments_context().empty())
{
std::wstringstream strm;
......@@ -495,7 +496,6 @@ void xlsx_conversion_context::end_table()
current_sheet().set_comments_link(commentsName.first, commentsName.second);
current_sheet().set_vml_drawing_link(vml_drawingName.first, vml_drawingName.second);
}
//background picture
get_table_context().end_table();
}
......@@ -547,7 +547,10 @@ int xlsx_conversion_context::current_table_row()
std::wstring xlsx_conversion_context::current_cell_address()
{
return oox::getCellAddress(current_table_column(), current_table_row());
int col = current_table_column();
int row = current_table_row();
return oox::getCellAddress(col < 0 ? 0 : col, row < 0 ? 0 : row); //under covered cell
}
void xlsx_conversion_context::start_office_spreadsheet(const odf_reader::office_element * elm)
......
......@@ -331,7 +331,7 @@ void page_layout_instance::xlsx_serialize(std::wostream & strm, oox::xlsx_conver
props->xlsx_serialize(strm, Context);
}
void page_layout_instance::docx_convert_serialize(std::wostream & strm, oox::docx_conversion_context & Context)
void page_layout_instance::docx_serialize(std::wostream & strm, oox::docx_conversion_context & Context)
{
const style_header_style * headerStyle = dynamic_cast<style_header_style *>(style_page_layout_->style_header_style_.get());
const style_footer_style * footerStyle = dynamic_cast<style_footer_style *>(style_page_layout_->style_footer_style_.get());
......@@ -357,7 +357,7 @@ void page_layout_instance::docx_convert_serialize(std::wostream & strm, oox::doc
style_page_layout_properties * props = properties();
if (props)
props->docx_convert_serialize(strm, Context);
props->docx_serialize(strm, Context);
}
void page_layout_instance::pptx_serialize(std::wostream & strm, oox::pptx_conversion_context & Context)
{
......
......@@ -193,9 +193,9 @@ public:
const std::wstring & name() const;
style_page_layout_properties * properties() const;
void docx_convert_serialize (std::wostream & strm, oox::docx_conversion_context & Context);
void xlsx_serialize (std::wostream & strm, oox::xlsx_conversion_context & Context);
void pptx_serialize (std::wostream & strm, oox::pptx_conversion_context & Context);
void docx_serialize (std::wostream & strm, oox::docx_conversion_context & Context);
void pptx_serialize (std::wostream & strm, oox::pptx_conversion_context & Context);
void xlsx_serialize (std::wostream & strm, oox::xlsx_conversion_context & Context);
const style_page_layout * style_page_layout_;
......
......@@ -40,9 +40,10 @@
#include "serialize_elements.h"
#include <cpdoccore/odf/odf_document.h>
#include "../odf/odfcontext.h"
#include "odfcontext.h"
#include "../odf/calcs_styles.h"
#include "calcs_styles.h"
#include "../docx/xlsx_utils.h"
namespace cpdoccore {
......@@ -215,8 +216,12 @@ void office_annotation::xlsx_convert(oox::xlsx_conversion_context & Context)
const std::wstring textStyleName = office_annotation_attr_.draw_text_style_name_.get_value_or(L"");
std::wstring ref = Context.current_cell_address();
Context.get_comments_context().end_comment(ref,Context.current_table_column(), Context.current_table_row());
int col = Context.current_table_column(); if (col < 0) col = 0;
int row = Context.current_table_row(); if (row < 0) row = 0;
std::wstring ref = oox::getCellAddress(col, row);
Context.get_comments_context().end_comment(ref, col, row);
}
// officeooo:annotation
//////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -152,7 +152,7 @@ void office_body::docx_convert(oox::docx_conversion_context & Context)
{
if (page_layout_instance * lastPageLayout = Context.root()->odf_context().pageLayoutContainer().page_layout_by_name(Context.get_page_properties()))
{
lastPageLayout->docx_convert_serialize(Context.output_stream(), Context);
lastPageLayout->docx_serialize(Context.output_stream(), Context);
//Context.remove_page_properties();
}
}
......
......@@ -1254,7 +1254,6 @@ bool style_page_layout_properties::docx_background_serialize(std::wostream & str
void style_page_layout_properties::xlsx_convert(oox::xlsx_conversion_context & Context)
{
}
void style_page_layout_properties::xlsx_serialize(std::wostream & strm, oox::xlsx_conversion_context & Context)
{
CP_XML_WRITER(strm)
......@@ -1319,31 +1318,28 @@ void style_page_layout_properties::xlsx_serialize(std::wostream & strm, oox::xls
}
}
}
if (elements_.style_background_image_)
}
if (elements_.style_background_image_)
{
oox::_oox_fill fill;
Compute_GraphicFill(attlist_.common_draw_fill_attlist_, elements_.style_background_image_, Context.root()->odf_context().drawStyles(), fill);
if (fill.bitmap)
{
oox::_oox_fill fill;
Compute_GraphicFill(attlist_.common_draw_fill_attlist_, elements_.style_background_image_, Context.root()->odf_context().drawStyles(), fill);
if (fill.bitmap)
if ( fill.bitmap->rId.empty())
{
if ( fill.bitmap->rId.empty())
{
std::wstring href = fill.bitmap->xlink_href_;
fill.bitmap->rId = Context.get_mediaitems().add_or_find(href, oox::typeImage, fill.bitmap->isInternal, href);
std::wstring href = fill.bitmap->xlink_href_;
fill.bitmap->rId = Context.get_mediaitems().add_or_find(href, oox::typeImage, fill.bitmap->isInternal, href);
Context.get_drawing_context().get_drawings()->add(fill.bitmap->isInternal, fill.bitmap->rId, href, oox::typeImage, true);
}
Context.get_drawing_context().get_drawings()->add(fill.bitmap->isInternal, fill.bitmap->rId, href, oox::typeImage, true);
}
CP_XML_NODE(L"picture")
{
CP_XML_ATTR(L"r:id", fill.bitmap->rId );
}
}
}
Context.get_table_context().state()->set_background(fill.bitmap->rId);
}
}
}
void style_page_layout_properties::docx_convert_serialize(std::wostream & strm, oox::docx_conversion_context & Context)
void style_page_layout_properties::docx_serialize(std::wostream & strm, oox::docx_conversion_context & Context)
{
style_columns * columns = dynamic_cast<style_columns *>( elements_.style_columns_.get());
......
......@@ -975,11 +975,12 @@ public:
static const ElementType type = typeStylePageLayout;
CPDOCCORE_DEFINE_VISITABLE();
void docx_convert_serialize (std::wostream & strm, oox::docx_conversion_context & Context);
void pptx_convert (oox::pptx_conversion_context & Context);
void xlsx_convert (oox::xlsx_conversion_context & Context);
bool docx_background_serialize(std::wostream & strm, oox::docx_conversion_context & Context, oox::_oox_fill & fill, int id);
void docx_serialize (std::wostream & strm, oox::docx_conversion_context & Context);
void xlsx_serialize(std::wostream & strm, oox::xlsx_conversion_context & Context);
void pptx_serialize(std::wostream & strm, oox::pptx_conversion_context & Context);
......
......@@ -406,6 +406,10 @@ void table_data_pilot_groups::xlsx_convert(oox::xlsx_conversion_context & Contex
if (table_grouped_by_)
Context.get_pivots_context().set_field_groups(table_grouped_by_->get_type());
if (table_source_field_name_)
Context.get_pivots_context().set_field_groups_source(*table_source_field_name_);
for (size_t i = 0; i < content_.size(); i++)
{
content_[i]->xlsx_convert(Context);
......
......@@ -304,8 +304,10 @@ bool CImageFileFormatChecker::isSvmFile(BYTE* pBuffer,DWORD dwBytes)
if (eFileType)return false;
if ( (6 <= dwBytes) &&(0x56 == pBuffer[0] && 0x43 == pBuffer[1] && 0x4c == pBuffer[2] && 0x4d == pBuffer[3]
&& 0x54 == pBuffer[4] && 0x46 == pBuffer[5] && 0x01 == pBuffer[6] && 0x00 == pBuffer[7]
&& 0x31 == pBuffer[8] && 0x00 == pBuffer[9] && 0x00 == pBuffer[10] && 0x00 == pBuffer[11]) )
&& 0x54 == pBuffer[4] && 0x46 == pBuffer[5] /*&& 0x01 == pBuffer[6] && 0x00 == pBuffer[7]
&& 0x31 == pBuffer[8]*/ && 0x00 == pBuffer[9] && 0x00 == pBuffer[10] && 0x00 == pBuffer[11]) )
//0x02, 0x00, 0x32,
//0x01,0x00, 0x031
return true;
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment