mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-20 06:46:23 +08:00
Compare commits
7 Commits
core-win-6
...
core-linux
| Author | SHA1 | Date | |
|---|---|---|---|
| 93e56e2b8a | |||
| e032fc8294 | |||
| 5ae2ac2385 | |||
| 6b8cb6cae4 | |||
| e66ea7c628 | |||
| 2447925fd6 | |||
| 5e126e28ff |
@ -306,10 +306,15 @@ void docx_conversion_context::finish_run()
|
||||
{
|
||||
if (false == in_run_) return;
|
||||
|
||||
if (get_comments_context().state() == 4)
|
||||
{
|
||||
output_stream()<< L"<w:commentReference w:id=\"" << get_comments_context().current_id() << L"\"/>";
|
||||
get_comments_context().state(0);
|
||||
}
|
||||
output_stream() << L"</w:r>";
|
||||
in_run_ = false;
|
||||
|
||||
if (get_comments_context().state()==2)
|
||||
if (get_comments_context().state() == 2)
|
||||
{
|
||||
output_stream()<< L"<w:commentRangeEnd w:id=\"" << get_comments_context().current_id() << L"\"/>";
|
||||
|
||||
@ -318,7 +323,6 @@ void docx_conversion_context::finish_run()
|
||||
get_comments_context().state(0);
|
||||
finish_run();
|
||||
}
|
||||
|
||||
}
|
||||
void docx_conversion_context::start_math_formula()
|
||||
{
|
||||
@ -587,7 +591,8 @@ oox_chart_context & docx_conversion_context::current_chart()
|
||||
void docx_conversion_context::add_new_run(std::wstring parentStyleId)
|
||||
{
|
||||
finish_run();
|
||||
if (get_comments_context().state()==1)
|
||||
if (get_comments_context().state() == 1 ||
|
||||
get_comments_context().state() == 4)//??? comment in run
|
||||
{
|
||||
output_stream() << L"<w:commentRangeStart w:id=\"" << get_comments_context().current_id() << L"\" />";
|
||||
get_comments_context().state(2);//active
|
||||
|
||||
@ -486,14 +486,14 @@ public:
|
||||
std::wstring author;
|
||||
std::wstring initials;
|
||||
};
|
||||
void start_comment(const std::wstring & content, const std::wstring & author, const std::wstring & date)
|
||||
void start_comment(const std::wstring & content, const std::wstring & author, const std::wstring & date, bool inRun = false)
|
||||
{
|
||||
int id = comments_.size()+1;
|
||||
_comment_desc new_comment={content,id,date,author};
|
||||
int id = comments_.size() + 1;
|
||||
_comment_desc new_comment={content, id, date, author};
|
||||
|
||||
comments_.push_back(new_comment);
|
||||
|
||||
state_ = 1;
|
||||
state_ = inRun ? 4 : 1;
|
||||
}
|
||||
int current_id()
|
||||
{
|
||||
|
||||
@ -50,7 +50,7 @@ std::wostream & operator << (std::wostream & _Wostream, const style_repeat & _Va
|
||||
case style_repeat::Stretch:
|
||||
_Wostream << L"stretch";
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return _Wostream;
|
||||
@ -67,9 +67,10 @@ style_repeat style_repeat::parse(const std::wstring & Str)
|
||||
return style_repeat( Repeat );
|
||||
else if (tmp == L"stretch")
|
||||
return style_repeat( Stretch );
|
||||
else
|
||||
else if (tmp == L"scale")//LOWriter-form-controls modded.odt
|
||||
return style_repeat( Stretch );
|
||||
else
|
||||
{
|
||||
BOOST_THROW_EXCEPTION( errors::invalid_attribute() );
|
||||
return style_repeat( NoRepeat );
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,21 +39,22 @@ namespace odf_reader {
|
||||
class document_context::Impl
|
||||
{
|
||||
public:
|
||||
Impl() : last_paragraph_(NULL) {}
|
||||
Impl() : last_element_(NULL) {}
|
||||
|
||||
public:
|
||||
void set_last_paragraph(text::paragraph * Paragraph)
|
||||
void set_last_element(office_element* elem)
|
||||
{
|
||||
last_paragraph_ = Paragraph;
|
||||
last_element_ = elem;
|
||||
}
|
||||
|
||||
text::paragraph * get_last_paragraph()
|
||||
office_element* get_last_element()
|
||||
{
|
||||
return last_paragraph_;
|
||||
return last_element_;
|
||||
}
|
||||
|
||||
private:
|
||||
text::paragraph * last_paragraph_;
|
||||
office_element * last_element_;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -68,18 +69,15 @@ document_context::~document_context()
|
||||
{
|
||||
delete impl_;
|
||||
}
|
||||
|
||||
void document_context::set_last_paragraph(text::paragraph * Paragraph)
|
||||
void document_context::set_last_element(office_element* elem)
|
||||
{
|
||||
return impl_->set_last_paragraph(Paragraph);
|
||||
return impl_->set_last_element(elem);
|
||||
}
|
||||
|
||||
text::paragraph * document_context::get_last_paragraph()
|
||||
office_element* document_context::get_last_element()
|
||||
{
|
||||
return impl_->get_last_paragraph();
|
||||
return impl_->get_last_element();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,18 +36,14 @@ namespace odf_reader {
|
||||
|
||||
class office_element;
|
||||
|
||||
namespace text {
|
||||
class paragraph;
|
||||
}
|
||||
|
||||
class document_context
|
||||
{
|
||||
public:
|
||||
document_context();
|
||||
virtual ~document_context();
|
||||
|
||||
void set_last_paragraph(text::paragraph * Paragraph);
|
||||
text::paragraph * get_last_paragraph();
|
||||
void set_last_element(office_element* elem);
|
||||
office_element* get_last_element();
|
||||
|
||||
int level;
|
||||
|
||||
|
||||
@ -1255,7 +1255,19 @@ void draw_text_box::docx_convert(oox::docx_conversion_context & Context)
|
||||
//}
|
||||
auto_fit_shape = true;
|
||||
}
|
||||
|
||||
else if ((frame->draw_frame_attlist_.fo_min_height_) && (draw_text_box_attlist_.fo_min_height_->get_type()==length_or_percent::Length))
|
||||
{
|
||||
size_t min_y = get_value_emu(frame->draw_frame_attlist_.fo_min_height_->get_length());
|
||||
if (drawing->cy < min_y)
|
||||
{
|
||||
drawing->cy = min_y;
|
||||
}
|
||||
auto_fit_shape = true;
|
||||
}
|
||||
else if ((frame->common_draw_attlists_.rel_size_.style_rel_height_) && (frame->common_draw_attlists_.rel_size_.style_rel_height_->get_type() == percent_or_scale::ScaleMin))
|
||||
{
|
||||
auto_fit_shape = true;
|
||||
}
|
||||
|
||||
if ((draw_text_box_attlist_.fo_min_width_) && (draw_text_box_attlist_.fo_min_width_->get_type()==length_or_percent::Length))
|
||||
{
|
||||
|
||||
@ -148,7 +148,7 @@ void office_annotation::docx_convert(oox::docx_conversion_context & Context)
|
||||
Context.set_run_state(runState);
|
||||
Context.set_paragraph_state(pState);
|
||||
|
||||
Context.get_comments_context().start_comment(temp_stream.str(), author,date);//content, date, author
|
||||
Context.get_comments_context().start_comment(temp_stream.str(), author, date, runState);//content, date, author
|
||||
|
||||
Context.dump_hyperlinks(Context.get_comments_context().get_rels(), oox::hyperlinks::comment_place);
|
||||
|
||||
|
||||
@ -142,14 +142,14 @@ void office_body::docx_convert(oox::docx_conversion_context & Context)
|
||||
if (content_)
|
||||
content_->docx_convert(Context);
|
||||
|
||||
if (!Context.get_section_context().dump_.empty() && !Context.get_table_context().in_table())
|
||||
if (false == Context.get_section_context().dump_.empty() && false == Context.get_table_context().in_table())
|
||||
{
|
||||
Context.output_stream() << Context.get_section_context().dump_;
|
||||
Context.get_section_context().dump_.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (page_layout_instance * lastPageLayout = Context.root()->odf_context().pageLayoutContainer().page_layout_by_name(Context.get_page_properties()))
|
||||
if (page_layout_instance *lastPageLayout = Context.root()->odf_context().pageLayoutContainer().page_layout_by_name(Context.get_page_properties()))
|
||||
{
|
||||
Context.next_dump_page_properties(true);
|
||||
|
||||
|
||||
@ -47,13 +47,13 @@
|
||||
#include "visitor.h"
|
||||
#include "../conversionelement.h"
|
||||
|
||||
#include "documentcontext.h"
|
||||
|
||||
#include "../../../Common/DocxFormat/Source/XML/Utils.h"
|
||||
|
||||
namespace cpdoccore {
|
||||
namespace odf_reader {
|
||||
|
||||
class document_context;
|
||||
|
||||
class office_element;
|
||||
typedef shared_ptr<office_element>::Type office_element_ptr;
|
||||
typedef weak_ptr<office_element>::Type office_element_weak_ptr;
|
||||
@ -69,17 +69,43 @@ public:
|
||||
|
||||
virtual ElementType get_type() const = 0;
|
||||
virtual ~office_element() = 0;
|
||||
|
||||
void set_root(bool isRoot) { is_root_ = isRoot; }
|
||||
bool is_root() const { return is_root_; }
|
||||
|
||||
virtual void afterCreate() {};
|
||||
virtual void afterReadContent() {};
|
||||
virtual void afterCreate()
|
||||
{
|
||||
// вызывается сразу после создания объекта
|
||||
if (context_)
|
||||
{
|
||||
context_->level++;
|
||||
}
|
||||
}
|
||||
virtual void afterReadContent()
|
||||
{
|
||||
if (context_)
|
||||
{
|
||||
if (context_->level == 4)
|
||||
{
|
||||
if (office_element * prev= context_->get_last_element())
|
||||
{
|
||||
prev->next_element_style_name = element_style_name;
|
||||
}
|
||||
|
||||
// запоминаем в контексте вновь созданный элемент
|
||||
context_->set_last_element(this);
|
||||
}
|
||||
context_->level--;
|
||||
}
|
||||
}
|
||||
|
||||
CPDOCCORE_DEFINE_VISITABLE();
|
||||
|
||||
void setContext(document_context * Context) { context_ = Context; }
|
||||
|
||||
public:
|
||||
_CP_OPT(std::wstring) element_style_name;
|
||||
_CP_OPT(std::wstring) next_element_style_name; //for master page
|
||||
|
||||
virtual std::wostream & text_to_stream(std::wostream & _Wostream) const
|
||||
{
|
||||
_CP_LOG << L"[warning] use base text_to_stream\n";
|
||||
@ -92,8 +118,7 @@ public:
|
||||
return _Wostream;
|
||||
}
|
||||
document_context * getContext() { return context_; }
|
||||
//
|
||||
//protected:
|
||||
|
||||
const document_context * getContext() const { return context_; }
|
||||
|
||||
private:
|
||||
|
||||
@ -36,8 +36,10 @@
|
||||
#include <xml/xmlchar.h>
|
||||
#include <xml/attributes.h>
|
||||
#include <xml/utils.h>
|
||||
#include <odf/odf_document.h>
|
||||
|
||||
#include "serialize_elements.h"
|
||||
#include "odfcontext.h"
|
||||
|
||||
namespace cpdoccore {
|
||||
namespace odf_reader {
|
||||
@ -155,7 +157,41 @@ void office_text::docx_convert(oox::docx_conversion_context & Context)
|
||||
Context.start_office_text();
|
||||
for (size_t i = 0; i < content_.size(); i++)
|
||||
{
|
||||
content_[i]->docx_convert(Context);
|
||||
if (content_[i]->element_style_name)
|
||||
{
|
||||
std::wstring text___ = *content_[i]->element_style_name;
|
||||
|
||||
const _CP_OPT(std::wstring) masterPageName = Context.root()->odf_context().styleContainer().master_page_name_by_name(*content_[i]->element_style_name);
|
||||
|
||||
if (masterPageName)
|
||||
{
|
||||
Context.set_master_page_name(*masterPageName);
|
||||
|
||||
const std::wstring masterPageNameLayout = Context.root()->odf_context().pageLayoutContainer().page_layout_name_by_style(*masterPageName);
|
||||
|
||||
Context.remove_page_properties();
|
||||
Context.add_page_properties(masterPageNameLayout);
|
||||
}
|
||||
}
|
||||
if (content_[i]->next_element_style_name)
|
||||
{
|
||||
std::wstring text___ = *content_[i]->next_element_style_name;
|
||||
// проверяем не сменится ли свойства страницы.
|
||||
// если да — устанавливаем контексту флаг на то что необходимо в текущем параграфе
|
||||
// распечатать свойства раздела/секции
|
||||
//проверить ... не она ли текущая - может быть прописан дубляж - и тогда разрыв нарисуется ненужный
|
||||
const _CP_OPT(std::wstring) next_masterPageName = Context.root()->odf_context().styleContainer().master_page_name_by_name(*content_[i]->next_element_style_name);
|
||||
|
||||
if ((next_masterPageName) && (Context.get_master_page_name() != *next_masterPageName))
|
||||
{
|
||||
if (false == Context.root()->odf_context().pageLayoutContainer().compare_page_properties(Context.get_master_page_name(), *next_masterPageName))
|
||||
{
|
||||
Context.next_dump_page_properties(true);
|
||||
//is_empty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
content_[i]->docx_convert(Context);
|
||||
}
|
||||
Context.end_office_text();
|
||||
}
|
||||
|
||||
@ -1209,10 +1209,21 @@ void sequence_ref::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
}
|
||||
void sequence_ref::add_text(const std::wstring & Text)
|
||||
{
|
||||
content_ = Text;
|
||||
text_ = text::create(Text) ;
|
||||
}
|
||||
void sequence_ref::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
std::wstring ref, sequence;
|
||||
if (!ref_name_) return;
|
||||
|
||||
Context.finish_run();
|
||||
Context.output_stream() << L"<w:fldSimple w:instr=\" REF " << *ref_name_ << L" \\h\">";
|
||||
Context.add_new_run();
|
||||
if (text_)
|
||||
text_->docx_convert(Context);
|
||||
Context.finish_run();
|
||||
|
||||
Context.output_stream() << L"</w:fldSimple>";
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t * sequence::ns = L"text";
|
||||
@ -1277,7 +1288,7 @@ void sequence::docx_convert(oox::docx_conversion_context & Context)
|
||||
num_format= L"ARABIC"; break;
|
||||
}
|
||||
}
|
||||
|
||||
Context.start_bookmark(*ref_name_);
|
||||
Context.output_stream() << L"<w:fldSimple w:instr=\" SEQ " << XmlUtils::EncodeXmlString(sequence) << L" \\* " << num_format << L" \">";
|
||||
Context.add_new_run();
|
||||
for (size_t i = 0; i < text_.size(); i++)
|
||||
@ -1291,6 +1302,8 @@ void sequence::docx_convert(oox::docx_conversion_context & Context)
|
||||
// Context.end_bookmark(ref);
|
||||
//}
|
||||
Context.output_stream() << L"</w:fldSimple>";
|
||||
|
||||
Context.end_bookmark(*ref_name_);
|
||||
}
|
||||
void sequence::pptx_convert(oox::pptx_conversion_context & Context)
|
||||
{
|
||||
|
||||
@ -891,7 +891,7 @@ public:
|
||||
_CP_OPT(std::wstring) reference_format_;//caption, category-and-value, value, chapter, direction, page, text, number, number-all-superior, number-no-superior
|
||||
_CP_OPT(std::wstring) ref_name_;
|
||||
|
||||
std::wstring content_;
|
||||
office_element_ptr text_;
|
||||
|
||||
private:
|
||||
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
|
||||
|
||||
@ -142,7 +142,9 @@ const wchar_t * table_table::name = L"table";
|
||||
|
||||
void table_table::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
{
|
||||
table_table_attlist_.add_attributes(Attributes);
|
||||
CP_APPLY_ATTR(L"table:style-name", element_style_name);
|
||||
|
||||
table_table_attlist_.add_attributes(Attributes);
|
||||
}
|
||||
|
||||
void table_table::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
|
||||
|
||||
@ -144,6 +144,16 @@ void table_table::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
std::wostream & _Wostream = Context.output_stream();
|
||||
|
||||
std::wstring sDumpPageProperties;
|
||||
if (false == Context.get_paragraph_state())
|
||||
{
|
||||
std::wstringstream strm;
|
||||
if (Context.process_page_properties(strm))
|
||||
{
|
||||
sDumpPageProperties = strm.str();
|
||||
}
|
||||
}
|
||||
|
||||
bool sub_table = table_table_attlist_.table_is_sub_table_.get_value_or(false);
|
||||
//todooo придумать как сделать внешние границы sub-таблицы границами внешней ячейки (чтоб слияние произошло)
|
||||
|
||||
@ -173,6 +183,15 @@ void table_table::docx_convert(oox::docx_conversion_context & Context)
|
||||
|
||||
Context.get_table_context().end_table();
|
||||
_Wostream << L"</w:tbl>";
|
||||
|
||||
if (false == sDumpPageProperties.empty())
|
||||
{
|
||||
Context.output_stream() << L"<w:p>";
|
||||
Context.output_stream() << L"<w:pPr>";
|
||||
Context.output_stream() << sDumpPageProperties;
|
||||
Context.output_stream() << L"</w:pPr>";
|
||||
Context.output_stream() << L"</w:p>";
|
||||
}
|
||||
}
|
||||
|
||||
void table_columns::docx_convert(oox::docx_conversion_context & Context)
|
||||
|
||||
@ -71,12 +71,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
template <class ElementT>
|
||||
class text_content_impl : public office_element_impl<ElementT>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,35 +161,6 @@ void paragraph::add_text(const std::wstring & Text)
|
||||
office_element_ptr elm = text::create(Text) ;
|
||||
content_.push_back( elm );
|
||||
}
|
||||
|
||||
void paragraph::afterCreate(document_context * Context)
|
||||
{
|
||||
// вызывается сразу после создания объекта
|
||||
if (Context)
|
||||
{
|
||||
Context->level++;
|
||||
// выставляем у предыдущего параграфа указатель на следующий (т.е. на вновь созданный)
|
||||
|
||||
if (Context->level == 1)
|
||||
{
|
||||
if (paragraph * prevPar = Context->get_last_paragraph())
|
||||
{
|
||||
prevPar->set_next(this);
|
||||
}
|
||||
|
||||
// запоминаем в контексте вновь созданный параграф
|
||||
Context->set_last_paragraph(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
void paragraph::afterReadContent(document_context * Context)
|
||||
{
|
||||
if (Context)
|
||||
{
|
||||
Context->level--;
|
||||
}
|
||||
}
|
||||
|
||||
const wchar_t * emptyParagraphContent = L"<w:pPr></w:pPr><w:r><w:rPr></w:rPr></w:r>";
|
||||
|
||||
const wchar_t * emptyParagraphDrawing = L"<w:p><w:pPr></w:pPr></w:p>";
|
||||
@ -315,30 +286,22 @@ void paragraph::docx_convert(oox::docx_conversion_context & Context)
|
||||
|
||||
if (masterPageName)
|
||||
{
|
||||
Context.set_master_page_name(*masterPageName);
|
||||
|
||||
const std::wstring masterPageNameLayout = Context.root()->odf_context().pageLayoutContainer().page_layout_name_by_style(*masterPageName);
|
||||
|
||||
Context.remove_page_properties();
|
||||
Context.add_page_properties(masterPageNameLayout);
|
||||
|
||||
is_empty = false;
|
||||
}
|
||||
|
||||
if (next_par_)
|
||||
if (next_element_style_name)
|
||||
{
|
||||
// проверяем не сменит ли следующий параграф свойства страницы.
|
||||
// если да — устанавливаем контексту флаг на то что необходимо в текущем параграфе
|
||||
// распечатать свойства раздела/секции
|
||||
//проверить ... не она ли текущая - может быть прописан дубляж - и тогда разрыв нарисуется ненужный
|
||||
const std::wstring & next_styleName = next_par_->attrs_.text_style_name_;
|
||||
const _CP_OPT(std::wstring) next_masterPageName = Context.root()->odf_context().styleContainer().master_page_name_by_name(next_styleName);
|
||||
// проверить ... не она ли текущая - может быть прописан дубляж - и тогда разрыв нарисуется ненужный
|
||||
// dump был выше уровнем
|
||||
const _CP_OPT(std::wstring) next_masterPageName = Context.root()->odf_context().styleContainer().master_page_name_by_name(*next_element_style_name);
|
||||
|
||||
if ((next_masterPageName) && (Context.get_master_page_name() != *next_masterPageName))
|
||||
{
|
||||
if (false == Context.root()->odf_context().pageLayoutContainer().compare_page_properties(Context.get_master_page_name(), *next_masterPageName))
|
||||
{
|
||||
Context.next_dump_page_properties(true);
|
||||
is_empty = false;
|
||||
}
|
||||
}
|
||||
@ -473,7 +436,9 @@ std::wostream & h::text_to_stream(std::wostream & _Wostream) const
|
||||
|
||||
void h::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
{
|
||||
CP_APPLY_ATTR(L"text:outline-level" , outline_level_);
|
||||
CP_APPLY_ATTR(L"text:style-name", element_style_name);
|
||||
|
||||
CP_APPLY_ATTR(L"text:outline-level" , outline_level_);
|
||||
CP_APPLY_ATTR(L"text:restart-numbering" , restart_numbering_);
|
||||
CP_APPLY_ATTR(L"text:start-value" , start_value_);
|
||||
CP_APPLY_ATTR(L"text:is-list-header" , is_list_header_);
|
||||
@ -494,14 +459,12 @@ void h::add_text(const std::wstring & Text)
|
||||
paragraph_.add_text(Text);
|
||||
}
|
||||
|
||||
void h::afterCreate()
|
||||
{
|
||||
paragraph_.afterCreate( getContext() );
|
||||
}
|
||||
void h::afterReadContent()
|
||||
{
|
||||
paragraph_.afterReadContent( getContext() );
|
||||
office_element::afterReadContent();
|
||||
paragraph_.next_element_style_name = next_element_style_name;
|
||||
}
|
||||
|
||||
void h::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
paragraph_.docx_convert(Context);
|
||||
@ -520,14 +483,6 @@ void h::pptx_convert(oox::pptx_conversion_context & Context)
|
||||
const wchar_t * p::ns = L"text";
|
||||
const wchar_t * p::name = L"p";
|
||||
|
||||
void p::afterCreate()
|
||||
{
|
||||
paragraph_.afterCreate( getContext() );
|
||||
}
|
||||
void p::afterReadContent()
|
||||
{
|
||||
paragraph_.afterReadContent( getContext() );
|
||||
}
|
||||
std::wostream & p::text_to_stream(std::wostream & _Wostream) const
|
||||
{
|
||||
return paragraph_.text_to_stream(_Wostream);
|
||||
@ -535,6 +490,8 @@ std::wostream & p::text_to_stream(std::wostream & _Wostream) const
|
||||
|
||||
void p::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
{
|
||||
CP_APPLY_ATTR(L"text:style-name", element_style_name);
|
||||
|
||||
paragraph_.add_attributes(Attributes);
|
||||
}
|
||||
|
||||
@ -562,6 +519,11 @@ void p::pptx_convert(oox::pptx_conversion_context & Context)
|
||||
{
|
||||
paragraph_.pptx_convert(Context);
|
||||
}
|
||||
void p::afterReadContent()
|
||||
{
|
||||
office_element::afterReadContent();
|
||||
paragraph_.next_element_style_name = next_element_style_name;
|
||||
}
|
||||
// text:list
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const wchar_t * list::ns = L"text";
|
||||
@ -661,9 +623,11 @@ std::wostream & section::text_to_stream(std::wostream & _Wostream) const
|
||||
|
||||
void section::afterCreate()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
office_element::afterCreate();
|
||||
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_section(true);
|
||||
}
|
||||
@ -672,13 +636,14 @@ void section::afterCreate()
|
||||
|
||||
void section::afterReadContent()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_end_section(true);
|
||||
}
|
||||
}
|
||||
office_element::afterReadContent();
|
||||
}
|
||||
|
||||
void section::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
@ -1076,9 +1041,11 @@ const wchar_t * illustration_index::name = L"illustration-index";
|
||||
|
||||
void illustration_index::afterCreate()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
office_element::afterCreate();
|
||||
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_section(true);
|
||||
}
|
||||
@ -1089,11 +1056,12 @@ void illustration_index::afterReadContent()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_end_section(true);
|
||||
}
|
||||
}
|
||||
office_element::afterReadContent();
|
||||
}
|
||||
void illustration_index::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
@ -1219,9 +1187,11 @@ void alphabetical_index::add_child_element( xml::sax * Reader, const std::wstrin
|
||||
}
|
||||
void alphabetical_index::afterCreate()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
office_element::afterCreate();
|
||||
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_section(true);
|
||||
}
|
||||
@ -1231,11 +1201,12 @@ void alphabetical_index::afterReadContent()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_end_section(true);
|
||||
}
|
||||
}
|
||||
office_element::afterReadContent();
|
||||
}
|
||||
void alphabetical_index::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
@ -1324,9 +1295,11 @@ const wchar_t * object_index::name = L"object-index";
|
||||
|
||||
void object_index::afterCreate()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
office_element::afterCreate();
|
||||
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_section(true);
|
||||
}
|
||||
@ -1336,11 +1309,12 @@ void object_index::afterReadContent()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_end_section(true);
|
||||
}
|
||||
}
|
||||
office_element::afterReadContent();
|
||||
}
|
||||
void object_index::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
@ -1426,9 +1400,11 @@ const wchar_t * user_index::name = L"user-index";
|
||||
|
||||
void user_index::afterCreate()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
office_element::afterCreate();
|
||||
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_section(true);
|
||||
}
|
||||
@ -1438,11 +1414,12 @@ void user_index::afterReadContent()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_end_section(true);
|
||||
}
|
||||
}
|
||||
office_element::afterReadContent();
|
||||
}
|
||||
void user_index::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
@ -1567,9 +1544,11 @@ const wchar_t * bibliography::name = L"bibliography";
|
||||
|
||||
void bibliography::afterCreate()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
office_element::afterCreate();
|
||||
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_section(true);
|
||||
}
|
||||
@ -1580,11 +1559,12 @@ void bibliography::afterReadContent()
|
||||
{
|
||||
if (document_context * context = getContext())
|
||||
{
|
||||
if (paragraph * lastPar = context->get_last_paragraph())
|
||||
if (paragraph * lastPar = dynamic_cast<paragraph*>(context->get_last_element()))
|
||||
{
|
||||
lastPar->set_next_end_section(true);
|
||||
}
|
||||
}
|
||||
office_element::afterReadContent();
|
||||
}
|
||||
void bibliography::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
|
||||
@ -51,7 +51,7 @@ namespace text {
|
||||
class paragraph
|
||||
{
|
||||
public:
|
||||
paragraph() : next_par_(NULL), next_section_(false), next_end_section_(false), is_header_(false) {}
|
||||
paragraph() : next_section_(false), next_end_section_(false), is_header_(false) {}
|
||||
|
||||
std::wostream & text_to_stream(std::wostream & _Wostream) const;
|
||||
|
||||
@ -59,9 +59,8 @@ public:
|
||||
void add_child_element ( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name, document_context * Context);
|
||||
void add_text (const std::wstring & Text);
|
||||
|
||||
paragraph * get_next() { return next_par_; }
|
||||
void set_next(paragraph * next) {next_par_ = next;}
|
||||
|
||||
_CP_OPT(std::wstring) next_element_style_name; //for master page
|
||||
|
||||
void set_next_section(bool Val)
|
||||
{
|
||||
next_section_ = Val;
|
||||
@ -71,9 +70,6 @@ public:
|
||||
{
|
||||
next_end_section_ = Val;
|
||||
}
|
||||
|
||||
void afterCreate(document_context * ctx);
|
||||
void afterReadContent(document_context * ctx);
|
||||
|
||||
void docx_convert (oox::docx_conversion_context & Context) ;
|
||||
void xlsx_convert (oox::xlsx_conversion_context & Context) ;
|
||||
@ -88,21 +84,18 @@ private:
|
||||
|
||||
paragraph_attrs attrs_;
|
||||
|
||||
paragraph *next_par_;
|
||||
|
||||
bool next_section_;
|
||||
bool next_end_section_;
|
||||
|
||||
bool is_header_;
|
||||
|
||||
friend class par_docx_convert_class;
|
||||
friend class p;
|
||||
friend class h;
|
||||
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class h : public text_content_impl<h>
|
||||
class h : public office_element_impl<h>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -115,9 +108,8 @@ public:
|
||||
void xlsx_convert(oox::xlsx_conversion_context & Context) ;
|
||||
void pptx_convert(oox::pptx_conversion_context & Context) ;
|
||||
|
||||
virtual void afterCreate();
|
||||
virtual void afterReadContent();
|
||||
|
||||
|
||||
virtual std::wostream & text_to_stream(std::wostream & _Wostream) const;
|
||||
|
||||
paragraph paragraph_;
|
||||
@ -134,14 +126,12 @@ private:
|
||||
_CP_OPT(bool) is_list_header_;
|
||||
_CP_OPT(std::wstring) number_;
|
||||
|
||||
friend class par_docx_convert_class;
|
||||
|
||||
};
|
||||
|
||||
CP_REGISTER_OFFICE_ELEMENT2(h);
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class p : public text_content_impl<p>
|
||||
class p : public office_element_impl<p>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -154,7 +144,6 @@ public:
|
||||
void xlsx_convert(oox::xlsx_conversion_context & Context) ;
|
||||
void pptx_convert(oox::pptx_conversion_context & Context) ;
|
||||
|
||||
virtual void afterCreate();
|
||||
virtual void afterReadContent();
|
||||
|
||||
virtual std::wostream & text_to_stream(std::wostream & _Wostream) const;
|
||||
@ -167,12 +156,11 @@ private:
|
||||
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
|
||||
virtual void add_text(const std::wstring & Text);
|
||||
|
||||
friend class par_docx_convert_class;
|
||||
};
|
||||
CP_REGISTER_OFFICE_ELEMENT2(p);
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class list : public text_content_impl<list>
|
||||
class list : public office_element_impl<list>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -203,7 +191,7 @@ private:
|
||||
CP_REGISTER_OFFICE_ELEMENT2(list);
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class soft_page_break : public text_content_impl<soft_page_break>
|
||||
class soft_page_break : public office_element_impl<soft_page_break>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -223,7 +211,7 @@ private:
|
||||
CP_REGISTER_OFFICE_ELEMENT2(soft_page_break);
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class section : public text_content_impl<section>
|
||||
class section : public office_element_impl<section>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -265,7 +253,7 @@ private:
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class section_source : public text_content_impl<section_source>
|
||||
class section_source : public office_element_impl<section_source>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -305,7 +293,7 @@ public:
|
||||
};
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
class table_of_content : public text_content_impl<table_of_content>
|
||||
class table_of_content : public office_element_impl<table_of_content>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -335,7 +323,7 @@ CP_REGISTER_OFFICE_ELEMENT2(table_of_content);
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// text:table-index
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class table_index : public text_content_impl<table_index>
|
||||
class table_index : public office_element_impl<table_index>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -364,7 +352,7 @@ CP_REGISTER_OFFICE_ELEMENT2(table_index);
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// text:illustration-index
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class illustration_index : public text_content_impl<illustration_index>
|
||||
class illustration_index : public office_element_impl<illustration_index>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -396,7 +384,7 @@ CP_REGISTER_OFFICE_ELEMENT2(illustration_index);
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// text:alphabetical-index
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class alphabetical_index : public text_content_impl<alphabetical_index>
|
||||
class alphabetical_index : public office_element_impl<alphabetical_index>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -428,7 +416,7 @@ CP_REGISTER_OFFICE_ELEMENT2(alphabetical_index);
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// text:object-index
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class object_index : public text_content_impl<object_index>
|
||||
class object_index : public office_element_impl<object_index>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -460,7 +448,7 @@ CP_REGISTER_OFFICE_ELEMENT2(object_index);
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// text:user-index
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class user_index : public text_content_impl<user_index>
|
||||
class user_index : public office_element_impl<user_index>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -492,7 +480,7 @@ CP_REGISTER_OFFICE_ELEMENT2(user_index);
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
// text:bibliography
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
class bibliography : public text_content_impl<bibliography>
|
||||
class bibliography : public office_element_impl<bibliography>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -565,7 +553,7 @@ CP_REGISTER_OFFICE_ELEMENT2(bibliography_entry_template);
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
//text:index-body
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class index_body : public text_content_impl<index_body>
|
||||
class index_body : public office_element_impl<index_body>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -588,7 +576,7 @@ private:
|
||||
};
|
||||
CP_REGISTER_OFFICE_ELEMENT2(index_body);
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class index_title : public text_content_impl<index_title>
|
||||
class index_title : public office_element_impl<index_title>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
@ -613,7 +601,7 @@ public:
|
||||
};
|
||||
CP_REGISTER_OFFICE_ELEMENT2(index_title);
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class index_title_template : public text_content_impl<index_title_template>
|
||||
class index_title_template : public office_element_impl<index_title_template>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
|
||||
@ -464,35 +464,49 @@ void odf_text_context::end_list()
|
||||
}
|
||||
//------------------------------------------------------------------------------------------ LIST
|
||||
|
||||
bool odf_text_context::start_field(int type)
|
||||
bool odf_text_context::start_field(int type, const std::wstring& value)
|
||||
{
|
||||
if (single_paragraph_ == true) return false;
|
||||
|
||||
office_element_ptr elm;
|
||||
if (type == fieldPage)
|
||||
|
||||
switch(type)
|
||||
{
|
||||
create_element(L"text", L"page-number", elm, odf_context_);
|
||||
text_page_number *page_numb = dynamic_cast<text_page_number*>(elm.get());
|
||||
if (page_numb)
|
||||
case fieldXE:
|
||||
{
|
||||
page_numb->text_select_page_ = L"current";
|
||||
create_element(L"text", L"alphabetical-index-mark", elm, odf_context_);
|
||||
text_alphabetical_index_mark *index = dynamic_cast<text_alphabetical_index_mark*>(elm.get());
|
||||
if (index)
|
||||
{
|
||||
index->key1_ = value;
|
||||
index->string_value_ = value;
|
||||
}
|
||||
}break;
|
||||
case fieldPage:
|
||||
{
|
||||
create_element(L"text", L"page-number", elm, odf_context_);
|
||||
text_page_number *page_numb = dynamic_cast<text_page_number*>(elm.get());
|
||||
if (page_numb)
|
||||
{
|
||||
page_numb->text_select_page_ = L"current";
|
||||
|
||||
if ( (odf_context_->page_layout_context()) &&
|
||||
(odf_context_->page_layout_context()->last_layout()) &&
|
||||
(odf_context_->page_layout_context()->last_layout()->page_number_format))
|
||||
{
|
||||
if ( (odf_context_->page_layout_context()) &&
|
||||
(odf_context_->page_layout_context()->last_layout()) &&
|
||||
(odf_context_->page_layout_context()->last_layout()->page_number_format))
|
||||
{
|
||||
|
||||
page_numb->common_num_format_attlist_.style_num_format_ = odf_context_->page_layout_context()->last_layout()->page_number_format;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type == fieldNumPages)
|
||||
{
|
||||
create_element(L"text", L"page-count", elm, odf_context_);
|
||||
}
|
||||
if (type == fieldTime)
|
||||
{
|
||||
create_element(L"text", L"date", elm, odf_context_);
|
||||
page_numb->common_num_format_attlist_.style_num_format_ = odf_context_->page_layout_context()->last_layout()->page_number_format;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case fieldNumPages:
|
||||
{
|
||||
create_element(L"text", L"page-count", elm, odf_context_);
|
||||
}break;
|
||||
case fieldTime:
|
||||
{
|
||||
create_element(L"text", L"date", elm, odf_context_);
|
||||
}break;
|
||||
}
|
||||
|
||||
if (elm)
|
||||
|
||||
@ -52,6 +52,7 @@ namespace odf_writer
|
||||
fieldTime,
|
||||
fieldPageRef,
|
||||
fieldSeq,
|
||||
fieldXE,
|
||||
|
||||
fieldBibliography = 0xff + 1,
|
||||
fieldIndex,
|
||||
@ -95,7 +96,7 @@ public:
|
||||
void start_element (office_element_ptr & elm, office_element_ptr style_elm = office_element_ptr(),std::wstring style_name = L"");
|
||||
void end_element ();
|
||||
|
||||
bool start_field (int type);
|
||||
bool start_field (int type, const std::wstring& value);
|
||||
void end_field ();
|
||||
|
||||
void start_span (bool styled = false);
|
||||
|
||||
@ -674,7 +674,7 @@ void odt_conversion_context::set_field_instr(std::wstring instr)
|
||||
|
||||
for (std::map<std::wstring, std::wstring>::iterator it = options.begin(); it != options.end(); ++it)
|
||||
{
|
||||
if (it->first == L" ")
|
||||
if (it->first == L" ")//field-argument
|
||||
{
|
||||
current_fields.back().value = it->second.substr(0, it->second.length() - 1);
|
||||
}
|
||||
@ -684,6 +684,20 @@ void odt_conversion_context::set_field_instr(std::wstring instr)
|
||||
}
|
||||
}
|
||||
}
|
||||
res1 = instr.find(L"XE");
|
||||
if (std::wstring::npos != res1 && current_fields.back().type == 0)
|
||||
{
|
||||
current_fields.back().type = fieldXE;
|
||||
std::map<std::wstring, std::wstring> options = parse_instr_options(instr.substr(3));
|
||||
|
||||
for (std::map<std::wstring, std::wstring>::iterator it = options.begin(); it != options.end(); ++it)
|
||||
{
|
||||
if (it->first == L" ")//field-argument
|
||||
{
|
||||
current_fields.back().value = it->second.substr(0, it->second.length() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
res1 = instr.find(L"BIBLIOGRAPHY");
|
||||
if (std::wstring::npos != res1 && current_fields.back().type == 0)
|
||||
{
|
||||
@ -771,6 +785,9 @@ void odt_conversion_context::set_field_instr(std::wstring instr)
|
||||
}
|
||||
void odt_conversion_context::start_field(bool in_span)
|
||||
{
|
||||
if (false == current_fields.empty() && current_fields.back().status == 0)
|
||||
return; //start_field из sdt
|
||||
|
||||
_field_state field;
|
||||
current_fields.push_back(field);
|
||||
}
|
||||
@ -930,6 +947,10 @@ void odt_conversion_context::end_field()
|
||||
current_fields.pop_back();
|
||||
}
|
||||
}
|
||||
else if (current_fields.back().status == 0)
|
||||
{
|
||||
current_fields.pop_back();
|
||||
}
|
||||
}
|
||||
void odt_conversion_context::end_paragraph()
|
||||
{
|
||||
@ -1054,7 +1075,7 @@ void odt_conversion_context::start_run(bool styled)
|
||||
|
||||
if (current_fields.back().type == fieldHyperlink) start_hyperlink(current_fields.back().value);
|
||||
else if (current_fields.back().type == fieldSeq) start_sequence();
|
||||
else text_context()->start_field(current_fields.back().type);
|
||||
else text_context()->start_field(current_fields.back().type, current_fields.back().value);
|
||||
}
|
||||
|
||||
text_context()->start_span(styled);
|
||||
@ -1069,7 +1090,7 @@ void odt_conversion_context::start_run(bool styled)
|
||||
if (!current_fields.empty() && current_fields.back().status == 1 && current_fields.back().in_span)//поле стартуется в span - нужно для сохранения стиля
|
||||
{
|
||||
current_fields.back().status = 2;
|
||||
text_context()->start_field(current_fields.back().type);
|
||||
text_context()->start_field(current_fields.back().type, current_fields.back().value);
|
||||
}
|
||||
}
|
||||
void odt_conversion_context::end_run()
|
||||
|
||||
@ -197,6 +197,7 @@ bool OoxConverter::encrypt_document (const std::wstring &password, const std::ws
|
||||
|
||||
encrypt_file(password, inp_file_name, out_file_name, rels->relationships_[i].encryption_, rels->relationships_[i].size_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool OoxConverter::encrypt_file (const std::wstring &password, const std::wstring & srcPath, const std::wstring & dstPath, std::wstring &encrypt_info, int &size)
|
||||
{
|
||||
|
||||
@ -403,10 +403,39 @@ void DocxConverter::convert(OOX::WritingElement *oox_unknown)
|
||||
void DocxConverter::convert(OOX::Logic::CSdt *oox_sdt)
|
||||
{
|
||||
if (oox_sdt == NULL) return;
|
||||
//nullable<OOX::Logic::CSdtEndPr > m_oSdtEndPr;
|
||||
//nullable<OOX::Logic::CSdtPr > m_oSdtPr;
|
||||
|
||||
bool bField = false;
|
||||
if (oox_sdt->m_oSdtPr.IsInit())
|
||||
{
|
||||
if (oox_sdt->m_oSdtPr->m_oAlias.IsInit())//friendly name
|
||||
{
|
||||
}
|
||||
if (oox_sdt->m_oSdtPr->m_oDocPartObj.IsInit())
|
||||
{
|
||||
if (oox_sdt->m_oSdtPr->m_oDocPartObj->m_oDocPartGallery.IsInit() &&
|
||||
oox_sdt->m_oSdtPr->m_oDocPartObj->m_oDocPartGallery->m_sVal.IsInit())
|
||||
{
|
||||
if (*oox_sdt->m_oSdtPr->m_oDocPartObj->m_oDocPartGallery->m_sVal == L"List od Illustrations" ||
|
||||
*oox_sdt->m_oSdtPr->m_oDocPartObj->m_oDocPartGallery->m_sVal == L"Table of Contents")
|
||||
{
|
||||
odt_context->start_field(false);
|
||||
bField = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oox_sdt->m_oSdtPr->m_eType == OOX::Logic::sdttypeBibliography)
|
||||
{
|
||||
odt_context->start_field(false);
|
||||
bField = true;
|
||||
}
|
||||
}
|
||||
|
||||
convert(oox_sdt->m_oSdtContent.GetPointer());
|
||||
|
||||
if (bField)
|
||||
{
|
||||
odt_context->end_field();
|
||||
}
|
||||
}
|
||||
void DocxConverter::convert(OOX::Logic::CSdtContent *oox_sdt)
|
||||
{
|
||||
|
||||
@ -218,6 +218,8 @@
|
||||
69E6AC8D2031ACA900795D9D /* VbaProject.h in Headers */ = {isa = PBXBuildFile; fileRef = 69E6AC8B2031ACA900795D9D /* VbaProject.h */; };
|
||||
69E6AC8F2031B72500795D9D /* Worksheet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 69E6AC8E2031B72500795D9D /* Worksheet.cpp */; };
|
||||
69F181EC1C7734A700B2952B /* strings_hack_printf.h in Headers */ = {isa = PBXBuildFile; fileRef = 69F181EA1C7734A700B2952B /* strings_hack_printf.h */; };
|
||||
8A218DBF20FCC770006589C2 /* StreamWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A218DBD20FCC76F006589C2 /* StreamWriter.h */; };
|
||||
8A218DC020FCC770006589C2 /* StreamWriter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A218DBE20FCC770006589C2 /* StreamWriter.cpp */; };
|
||||
8A404FCA2089FF7E00F2D5CF /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A404FC92089FF7E00F2D5CF /* Base64.cpp */; };
|
||||
8A404FCC2089FFE700F2D5CF /* Directory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A404FCB2089FFE700F2D5CF /* Directory.cpp */; };
|
||||
8A404FCE208A001E00F2D5CF /* Path.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A404FCD208A001D00F2D5CF /* Path.cpp */; };
|
||||
@ -443,6 +445,8 @@
|
||||
69E6AC8B2031ACA900795D9D /* VbaProject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VbaProject.h; sourceTree = "<group>"; };
|
||||
69E6AC8E2031B72500795D9D /* Worksheet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Worksheet.cpp; sourceTree = "<group>"; };
|
||||
69F181EA1C7734A700B2952B /* strings_hack_printf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = strings_hack_printf.h; path = ../../Common/DocxFormat/Source/Base/strings_hack_printf.h; sourceTree = "<group>"; };
|
||||
8A218DBD20FCC76F006589C2 /* StreamWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamWriter.h; sourceTree = "<group>"; };
|
||||
8A218DBE20FCC770006589C2 /* StreamWriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamWriter.cpp; sourceTree = "<group>"; };
|
||||
8A404FC92089FF7E00F2D5CF /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Base64.cpp; path = ../../../../DesktopEditor/common/Base64.cpp; sourceTree = "<group>"; };
|
||||
8A404FCB2089FFE700F2D5CF /* Directory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Directory.cpp; path = ../../../../DesktopEditor/common/Directory.cpp; sourceTree = "<group>"; };
|
||||
8A404FCD208A001D00F2D5CF /* Path.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Path.cpp; path = ../../../../DesktopEditor/common/Path.cpp; sourceTree = "<group>"; };
|
||||
@ -925,6 +929,8 @@
|
||||
17E6B3C01AC4298500F28F8B /* Path.h */,
|
||||
17E6B3C11AC4298500F28F8B /* Types.h */,
|
||||
69F181EA1C7734A700B2952B /* strings_hack_printf.h */,
|
||||
8A218DBE20FCC770006589C2 /* StreamWriter.cpp */,
|
||||
8A218DBD20FCC76F006589C2 /* StreamWriter.h */,
|
||||
);
|
||||
name = common;
|
||||
path = ../../../../DesktopEditor/common;
|
||||
@ -970,6 +976,7 @@
|
||||
17C1FBEE1ACC4250006B99B3 /* MergeCells.h in Headers */,
|
||||
17C1FBEF1ACC4250006B99B3 /* Docx.h in Headers */,
|
||||
17C1FBF11ACC4250006B99B3 /* SimpleTypes_OMath.h in Headers */,
|
||||
8A218DBF20FCC770006589C2 /* StreamWriter.h in Headers */,
|
||||
17C1FBF21ACC4250006B99B3 /* StringOutput.h in Headers */,
|
||||
17C1FBF41ACC4250006B99B3 /* Image.h in Headers */,
|
||||
17C1FBF51ACC4250006B99B3 /* Dir.h in Headers */,
|
||||
@ -1198,6 +1205,7 @@
|
||||
17C1FBBA1ACC4250006B99B3 /* SimpleTypes_Word.cpp in Sources */,
|
||||
17C1FBBB1ACC4250006B99B3 /* MathEquation.cpp in Sources */,
|
||||
17C1FBBC1ACC4250006B99B3 /* Wrap.cpp in Sources */,
|
||||
8A218DC020FCC770006589C2 /* StreamWriter.cpp in Sources */,
|
||||
17C1FBBD1ACC4250006B99B3 /* Common.cpp in Sources */,
|
||||
1732414A1BBEC90000E67992 /* pole.cpp in Sources */,
|
||||
17C1FBBE1ACC4250006B99B3 /* IFileContainer.cpp in Sources */,
|
||||
|
||||
@ -91,6 +91,12 @@ namespace OOX
|
||||
|
||||
bool FileInDirectoryCorrect();
|
||||
|
||||
AVSINLINE std::wstring GetBasename() const
|
||||
{
|
||||
std::wstring sFilename = GetFilename();
|
||||
std::wstring sExt = GetExtention();
|
||||
return sFilename.substr(0, sFilename.length() - sExt.length());
|
||||
}
|
||||
AVSINLINE std::wstring GetExtention(bool bIsPoint = true) const
|
||||
{
|
||||
int nFind = (int)m_strFilename.rfind('.');
|
||||
|
||||
@ -229,6 +229,22 @@ namespace OOX
|
||||
pWorkbookView->m_oWindowHeight->SetValue(9720);
|
||||
}
|
||||
}
|
||||
LONG GetActiveSheetIndex()
|
||||
{
|
||||
LONG lActiveSheet = 0;
|
||||
std::wstring sSheetRId = _T("Sheet1"); // Читаем не по rId, а по имени листа
|
||||
// Get active sheet
|
||||
if ( m_oBookViews.IsInit() && !m_oBookViews->m_arrItems.empty())
|
||||
{
|
||||
if (m_oBookViews->m_arrItems.front()->m_oActiveTab.IsInit())
|
||||
{
|
||||
lActiveSheet = m_oBookViews->m_arrItems.front()->m_oActiveTab->GetValue();
|
||||
if (0 > lActiveSheet)
|
||||
lActiveSheet = 0;
|
||||
}
|
||||
}
|
||||
return lActiveSheet;
|
||||
}
|
||||
private:
|
||||
CPath m_oReadPath;
|
||||
|
||||
|
||||
@ -376,6 +376,20 @@ namespace OOX
|
||||
return _T("");
|
||||
}
|
||||
virtual void toXML(NSStringUtils::CStringBuilder& writer) const
|
||||
{
|
||||
toXMLStart(writer);
|
||||
|
||||
for ( size_t i = 0; i < m_arrItems.size(); ++i)
|
||||
{
|
||||
if ( m_arrItems[i] )
|
||||
{
|
||||
m_arrItems[i]->toXML(writer);
|
||||
}
|
||||
}
|
||||
|
||||
toXMLEnd(writer);
|
||||
}
|
||||
virtual void toXMLStart(NSStringUtils::CStringBuilder& writer) const
|
||||
{
|
||||
writer.WriteString(_T("<row"));
|
||||
WritingStringNullableAttrBool(L"collapsed", m_oCollapsed);
|
||||
@ -390,15 +404,9 @@ namespace OOX
|
||||
WritingStringNullableAttrBool(L"thickBot", m_oThickBot);
|
||||
WritingStringNullableAttrBool(L"thickTop", m_oThickTop);
|
||||
writer.WriteString(_T(">"));
|
||||
|
||||
for ( size_t i = 0; i < m_arrItems.size(); ++i)
|
||||
{
|
||||
if ( m_arrItems[i] )
|
||||
{
|
||||
m_arrItems[i]->toXML(writer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
virtual void toXMLEnd(NSStringUtils::CStringBuilder& writer) const
|
||||
{
|
||||
writer.WriteString(_T("</row>"));
|
||||
}
|
||||
virtual void fromXML(XmlUtils::CXmlLiteReader& oReader)
|
||||
@ -489,8 +497,7 @@ namespace OOX
|
||||
}
|
||||
virtual void toXML(NSStringUtils::CStringBuilder& writer) const
|
||||
{
|
||||
writer.WriteString(_T("<sheetData>"));
|
||||
|
||||
toXMLStart(writer);
|
||||
for ( size_t i = 0; i < m_arrItems.size(); ++i)
|
||||
{
|
||||
if ( m_arrItems[i] )
|
||||
@ -498,7 +505,14 @@ namespace OOX
|
||||
m_arrItems[i]->toXML(writer);
|
||||
}
|
||||
}
|
||||
|
||||
toXMLEnd(writer);
|
||||
}
|
||||
virtual void toXMLStart(NSStringUtils::CStringBuilder& writer) const
|
||||
{
|
||||
writer.WriteString(_T("<sheetData>"));
|
||||
}
|
||||
virtual void toXMLEnd(NSStringUtils::CStringBuilder& writer) const
|
||||
{
|
||||
writer.WriteString(_T("</sheetData>"));
|
||||
}
|
||||
virtual void fromXML(XmlUtils::CXmlLiteReader& oReader)
|
||||
|
||||
@ -345,54 +345,71 @@ namespace OOX
|
||||
}
|
||||
void CWorksheet::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const
|
||||
{
|
||||
NSStringUtils::CStringBuilder sXml;
|
||||
sXml.WriteString(_T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\" xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"));
|
||||
if(m_oSheetPr.IsInit())
|
||||
m_oSheetPr->toXML(sXml);
|
||||
if(m_oSheetViews.IsInit())
|
||||
m_oSheetViews->toXML(sXml);
|
||||
if(m_oSheetFormatPr.IsInit())
|
||||
m_oSheetFormatPr->toXML(sXml);
|
||||
if(m_oCols.IsInit())
|
||||
m_oCols->toXML(sXml);
|
||||
if(m_oSheetData.IsInit())
|
||||
m_oSheetData->toXML(sXml);
|
||||
if(m_oAutofilter.IsInit())
|
||||
m_oAutofilter->toXML(sXml);
|
||||
if(m_oMergeCells.IsInit())
|
||||
m_oMergeCells->toXML(sXml);
|
||||
for (size_t nIndex = 0, nLength = m_arrConditionalFormatting.size(); nIndex < nLength; ++nIndex)
|
||||
m_arrConditionalFormatting[nIndex]->toXML(sXml);
|
||||
if(m_oHyperlinks.IsInit())
|
||||
m_oHyperlinks->toXML(sXml);
|
||||
if(m_oPrintOptions.IsInit())
|
||||
m_oPrintOptions->toXML(sXml);
|
||||
if(m_oPageMargins.IsInit())
|
||||
m_oPageMargins->toXML(sXml);
|
||||
if(m_oPageSetup.IsInit())
|
||||
m_oPageSetup->toXML(sXml);
|
||||
if(m_oDrawing.IsInit())
|
||||
m_oDrawing->toXML(sXml);
|
||||
if(m_oLegacyDrawing.IsInit())
|
||||
m_oLegacyDrawing->toXML(sXml);
|
||||
if(m_oLegacyDrawingHF.IsInit())
|
||||
m_oLegacyDrawingHF->toXML(sXml);
|
||||
if(m_oOleObjects.IsInit())
|
||||
m_oOleObjects->toXML(sXml);
|
||||
if (m_oControls.IsInit())
|
||||
m_oControls->toXML(sXml);
|
||||
if(m_oTableParts.IsInit())
|
||||
m_oTableParts->toXML(sXml);
|
||||
if(m_oExtLst.IsInit())
|
||||
if (m_sOutputFilename.empty())
|
||||
{
|
||||
sXml.WriteString(m_oExtLst->toXMLWithNS(_T("")));
|
||||
NSStringUtils::CStringBuilder sXml;
|
||||
toXMLStart(sXml);
|
||||
if(m_oSheetPr.IsInit())
|
||||
m_oSheetPr->toXML(sXml);
|
||||
if(m_oSheetViews.IsInit())
|
||||
m_oSheetViews->toXML(sXml);
|
||||
if(m_oSheetFormatPr.IsInit())
|
||||
m_oSheetFormatPr->toXML(sXml);
|
||||
if(m_oCols.IsInit())
|
||||
m_oCols->toXML(sXml);
|
||||
if(m_oSheetData.IsInit())
|
||||
m_oSheetData->toXML(sXml);
|
||||
if(m_oAutofilter.IsInit())
|
||||
m_oAutofilter->toXML(sXml);
|
||||
if(m_oMergeCells.IsInit())
|
||||
m_oMergeCells->toXML(sXml);
|
||||
for (size_t nIndex = 0, nLength = m_arrConditionalFormatting.size(); nIndex < nLength; ++nIndex)
|
||||
m_arrConditionalFormatting[nIndex]->toXML(sXml);
|
||||
if(m_oHyperlinks.IsInit())
|
||||
m_oHyperlinks->toXML(sXml);
|
||||
if(m_oPrintOptions.IsInit())
|
||||
m_oPrintOptions->toXML(sXml);
|
||||
if(m_oPageMargins.IsInit())
|
||||
m_oPageMargins->toXML(sXml);
|
||||
if(m_oPageSetup.IsInit())
|
||||
m_oPageSetup->toXML(sXml);
|
||||
if(m_oDrawing.IsInit())
|
||||
m_oDrawing->toXML(sXml);
|
||||
if(m_oLegacyDrawing.IsInit())
|
||||
m_oLegacyDrawing->toXML(sXml);
|
||||
if(m_oLegacyDrawingHF.IsInit())
|
||||
m_oLegacyDrawingHF->toXML(sXml);
|
||||
if(m_oOleObjects.IsInit())
|
||||
m_oOleObjects->toXML(sXml);
|
||||
if (m_oControls.IsInit())
|
||||
m_oControls->toXML(sXml);
|
||||
if(m_oTableParts.IsInit())
|
||||
m_oTableParts->toXML(sXml);
|
||||
if(m_oExtLst.IsInit())
|
||||
{
|
||||
sXml.WriteString(m_oExtLst->toXMLWithNS(_T("")));
|
||||
}
|
||||
toXMLEnd(sXml);
|
||||
|
||||
NSFile::CFileBinary::SaveToFile(oPath.GetPath(), sXml.GetData());
|
||||
|
||||
oContent.Registration( type().OverrideType(), oDirectory, oPath.GetFilename() );
|
||||
IFileContainer::Write( oPath, oDirectory, oContent );
|
||||
}
|
||||
sXml.WriteString(_T("</worksheet>"));
|
||||
|
||||
NSFile::CFileBinary::SaveToFile(oPath.GetPath(), sXml.GetData());
|
||||
|
||||
oContent.Registration( type().OverrideType(), oDirectory, oPath.GetFilename() );
|
||||
IFileContainer::Write( oPath, oDirectory, oContent );
|
||||
else
|
||||
{
|
||||
CPath oRealPath(oPath.GetDirectory() + FILE_SEPARATOR_STR + m_sOutputFilename);
|
||||
oContent.Registration( type().OverrideType(), oDirectory, oRealPath.GetFilename() );
|
||||
IFileContainer::Write( oRealPath, oDirectory, oContent );
|
||||
}
|
||||
}
|
||||
void CWorksheet::toXMLStart(NSStringUtils::CStringBuilder& writer) const
|
||||
{
|
||||
writer.WriteString(_T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\" xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"));
|
||||
}
|
||||
void CWorksheet::toXMLEnd(NSStringUtils::CStringBuilder& writer) const
|
||||
{
|
||||
writer.WriteString(_T("</worksheet>"));
|
||||
}
|
||||
|
||||
const OOX::RId CWorksheet::AddHyperlink (std::wstring& sHref)
|
||||
@ -427,4 +444,4 @@ namespace OOX
|
||||
m_arrConditionalFormatting.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,6 +90,8 @@ namespace OOX
|
||||
void PrepareComments(OOX::Spreadsheet::CComments* pComments, OOX::CVmlDrawing* pVmlDrawing);
|
||||
void PrepareToWrite();
|
||||
virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const;
|
||||
void toXMLStart(NSStringUtils::CStringBuilder& writer) const;
|
||||
void toXMLEnd(NSStringUtils::CStringBuilder& writer) const;
|
||||
virtual const OOX::FileType type() const
|
||||
{
|
||||
return OOX::Spreadsheet::FileTypes::Worksheet;
|
||||
|
||||
@ -97,6 +97,9 @@ SOURCES += ./../DesktopEditor/common/Base64.cpp
|
||||
HEADERS += ./../DesktopEditor/common/File.h
|
||||
SOURCES += ./../DesktopEditor/common/File.cpp
|
||||
|
||||
HEADERS += ./../DesktopEditor/common/StreamWriter.h
|
||||
SOURCES += ./../DesktopEditor/common/StreamWriter.cpp
|
||||
|
||||
# DIRECTORY
|
||||
HEADERS += ./../DesktopEditor/common/Directory.h
|
||||
SOURCES += ./../DesktopEditor/common/Directory.cpp
|
||||
|
||||
@ -130,9 +130,9 @@ namespace NSFile
|
||||
|
||||
public:
|
||||
CFileBinary();
|
||||
~CFileBinary();
|
||||
virtual ~CFileBinary();
|
||||
|
||||
void CloseFile();
|
||||
virtual void CloseFile();
|
||||
|
||||
FILE* GetFileNative();
|
||||
long GetFileSize();
|
||||
|
||||
70
DesktopEditor/common/StreamWriter.cpp
Normal file
70
DesktopEditor/common/StreamWriter.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2018
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#include "StreamWriter.h"
|
||||
|
||||
namespace NSFile
|
||||
{
|
||||
CStreamWriter::CStreamWriter(size_t bufferSize)
|
||||
{
|
||||
m_lSize = bufferSize;
|
||||
m_pData = (wchar_t*)malloc(bufferSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
}
|
||||
|
||||
void CStreamWriter::AddSize(size_t nSize)
|
||||
{
|
||||
if ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
Flush();
|
||||
if ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
NSStringUtils::CStringBuilder::AddSize(nSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
void CStreamWriter::CloseFile()
|
||||
{
|
||||
Flush();
|
||||
CFileBinary::CloseFile();
|
||||
}
|
||||
void CStreamWriter::Flush()
|
||||
{
|
||||
if (m_lSizeCur > 0)
|
||||
{
|
||||
CFileBinary::WriteStringUTF8(NSStringUtils::CStringBuilder::GetData());
|
||||
}
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
}
|
||||
}
|
||||
51
DesktopEditor/common/StreamWriter.h
Normal file
51
DesktopEditor/common/StreamWriter.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2018
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#ifndef _BUILD_STREAM_WRITER_CROSSPLATFORM_H_
|
||||
#define _BUILD_STREAM_WRITER_CROSSPLATFORM_H_
|
||||
|
||||
#include "File.h"
|
||||
#include "StringBuilder.h"
|
||||
|
||||
namespace NSFile
|
||||
{
|
||||
class KERNEL_DECL CStreamWriter : public CFileBinary, public NSStringUtils::CStringBuilder
|
||||
{
|
||||
public:
|
||||
CStreamWriter(size_t bufferSize = 16777216);
|
||||
|
||||
void AddSize(size_t nSize);
|
||||
void CloseFile();
|
||||
void Flush();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _BUILD_STREAM_WRITER_CROSSPLATFORM_H_
|
||||
@ -78,7 +78,7 @@ namespace NSStringUtils
|
||||
|
||||
class KERNEL_DECL CStringBuilder
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
wchar_t* m_pData;
|
||||
size_t m_lSize;
|
||||
|
||||
@ -87,9 +87,9 @@ namespace NSStringUtils
|
||||
|
||||
public:
|
||||
CStringBuilder();
|
||||
~CStringBuilder();
|
||||
virtual ~CStringBuilder();
|
||||
|
||||
void AddSize(size_t nSize);
|
||||
virtual void AddSize(size_t nSize);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@ -492,7 +492,7 @@ namespace NSCommon
|
||||
pImageData[i] = 0;
|
||||
}
|
||||
|
||||
NSGraphics::IGraphicsRenderer pRenderer = NSGraphics::Create();
|
||||
NSGraphics::IGraphicsRenderer* pRenderer = NSGraphics::Create();
|
||||
pRenderer->CreateFromBgraFrame(&oFrame);
|
||||
|
||||
pRenderer->SetFontManager(pManager);
|
||||
|
||||
@ -98,6 +98,21 @@ namespace NExtractTools
|
||||
}
|
||||
return sExt;
|
||||
}
|
||||
bool replaceContentType(const std::wstring &sDir, const std::wstring &sCTFrom, const std::wstring &sCTTo)
|
||||
{
|
||||
bool res = false;
|
||||
std::wstring sContentTypesPath = sDir + FILE_SEPARATOR_STR + _T("[Content_Types].xml");
|
||||
if (NSFile::CFileBinary::Exists(sContentTypesPath))
|
||||
{
|
||||
std::wstring sData;
|
||||
if (NSFile::CFileBinary::ReadAllTextUtf8(sContentTypesPath, sData))
|
||||
{
|
||||
sData = string_replaceAll(sData, sCTFrom, sCTTo);
|
||||
res = NSFile::CFileBinary::SaveToFile(sContentTypesPath, sData, true);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// docx -> bin
|
||||
int docx2doct_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
|
||||
{
|
||||
@ -3078,20 +3093,36 @@ namespace NExtractTools
|
||||
int nRes = 0;
|
||||
if(0 != (AVS_OFFICESTUDIO_FILE_DOCUMENT & nFormatTo))
|
||||
{
|
||||
if(AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX == nFormatTo)
|
||||
{
|
||||
if(params.hasSavePassword())
|
||||
if (AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX == nFormatTo || AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM == nFormatTo ||
|
||||
AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX == nFormatTo || AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM == nFormatTo)
|
||||
{
|
||||
if (AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM == nFormatTo || AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX == nFormatTo || AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM == nFormatTo)
|
||||
{
|
||||
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.docx");
|
||||
nRes = dir2zip(sFrom, sToMscrypt);
|
||||
if(SUCCEEDED_X2T(nRes))
|
||||
std::wstring sCTFrom = _T("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
|
||||
std::wstring sCTTo;
|
||||
switch(nFormatTo)
|
||||
{
|
||||
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM: sCTTo = _T("application/vnd.ms-word.document.macroEnabled.main+xml");break;
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX: sCTTo = _T("application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml");break;
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM: sCTTo = _T("application/vnd.ms-word.template.macroEnabledTemplate.main+xml");break;
|
||||
}
|
||||
nRes = replaceContentType(sFrom, sCTFrom, sCTTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
else
|
||||
if(SUCCEEDED_X2T(nRes))
|
||||
{
|
||||
nRes = dir2zip(sFrom, sTo);
|
||||
if(params.hasSavePassword())
|
||||
{
|
||||
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.docx");
|
||||
nRes = dir2zip(sFrom, sToMscrypt);
|
||||
if(SUCCEEDED_X2T(nRes))
|
||||
{
|
||||
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nRes = dir2zip(sFrom, sTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC == nFormatTo)
|
||||
@ -3290,20 +3321,36 @@ namespace NExtractTools
|
||||
int nRes = 0;
|
||||
if(0 != (AVS_OFFICESTUDIO_FILE_SPREADSHEET & nFormatTo) && AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV != nFormatTo)
|
||||
{
|
||||
if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX == nFormatTo)
|
||||
{
|
||||
if(params.hasSavePassword())
|
||||
if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX == nFormatTo || AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM == nFormatTo ||
|
||||
AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX == nFormatTo || AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM == nFormatTo)
|
||||
{
|
||||
if (AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM == nFormatTo || AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX == nFormatTo || AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM == nFormatTo)
|
||||
{
|
||||
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.xlsx");
|
||||
nRes = dir2zip(sFrom, sToMscrypt);
|
||||
if(SUCCEEDED_X2T(nRes))
|
||||
std::wstring sCTFrom = _T("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
|
||||
std::wstring sCTTo;
|
||||
switch(nFormatTo)
|
||||
{
|
||||
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
|
||||
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM: sCTTo = _T("application/vnd.ms-excel.sheet.macroEnabled.main+xml");break;
|
||||
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX: sCTTo = _T("application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml");break;
|
||||
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM: sCTTo = _T("application/vnd.ms-excel.template.macroEnabled.main+xml");break;
|
||||
}
|
||||
nRes = replaceContentType(sFrom, sCTFrom, sCTTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
else
|
||||
if(SUCCEEDED_X2T(nRes))
|
||||
{
|
||||
nRes = dir2zip(sFrom, sTo);
|
||||
if(params.hasSavePassword())
|
||||
{
|
||||
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.xlsx");
|
||||
nRes = dir2zip(sFrom, sToMscrypt);
|
||||
if(SUCCEEDED_X2T(nRes))
|
||||
{
|
||||
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nRes = dir2zip(sFrom, sTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
//else if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS == nFormatTo)
|
||||
@ -3477,20 +3524,39 @@ namespace NExtractTools
|
||||
int nRes = 0;
|
||||
if (0 != (AVS_OFFICESTUDIO_FILE_PRESENTATION & nFormatTo))
|
||||
{
|
||||
if(AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX == nFormatTo)
|
||||
if (AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX == nFormatTo ||
|
||||
AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSM == nFormatTo)
|
||||
{
|
||||
if(params.hasSavePassword())
|
||||
if (AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX == nFormatTo ||
|
||||
AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSM == nFormatTo)
|
||||
{
|
||||
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.pptx");
|
||||
nRes = dir2zip(sFrom, sToMscrypt);
|
||||
if(SUCCEEDED_X2T(nRes))
|
||||
std::wstring sCTFrom = _T("application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml");
|
||||
std::wstring sCTTo;
|
||||
switch(nFormatTo)
|
||||
{
|
||||
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
|
||||
case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM: sCTTo = _T("application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml");break;
|
||||
case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX: sCTTo = _T("application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml");break;
|
||||
case AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX: sCTTo = _T("application/vnd.openxmlformats-officedocument.presentationml.template.main+xml");break;
|
||||
case AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM: sCTTo = _T("application/vnd.ms-powerpoint.template.macroEnabled.main+xml");break;
|
||||
case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSM: sCTTo = _T("application/vnd.ms-powerpoint.slideshow.macroEnabled.main+xml");break;
|
||||
}
|
||||
nRes = replaceContentType(sFrom, sCTFrom, sCTTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
else
|
||||
if(SUCCEEDED_X2T(nRes))
|
||||
{
|
||||
nRes = dir2zip(sFrom, sTo);
|
||||
if(params.hasSavePassword())
|
||||
{
|
||||
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.pptx");
|
||||
nRes = dir2zip(sFrom, sToMscrypt);
|
||||
if(SUCCEEDED_X2T(nRes))
|
||||
{
|
||||
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nRes = dir2zip(sFrom, sTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
//else if(AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT == nFormatTo)
|
||||
|
||||
@ -42,11 +42,12 @@ using namespace OOX::Spreadsheet;
|
||||
|
||||
namespace BinXlsxRW
|
||||
{
|
||||
SaveParams::SaveParams(const std::wstring& _sThemePath, OOX::CContentTypes* _pContentTypes)
|
||||
SaveParams::SaveParams(const std::wstring& _sThemePath, OOX::CContentTypes* _pContentTypes, CSVWriter::CCSVWriter* _pCSVWriter)
|
||||
{
|
||||
pContentTypes = _pContentTypes;
|
||||
sThemePath = _sThemePath;
|
||||
nThemeOverrideCount = 1;
|
||||
pCSVWriter = _pCSVWriter;
|
||||
}
|
||||
|
||||
BYTE c_oserct_extlstEXT = 0;
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
#include "../../Common/DocxFormat/Source/XlsxFormat/Chart/ChartSerialize.h"
|
||||
#include "../Writer/BinaryCommonReader.h"
|
||||
#include "../../ASCOfficePPTXFile/ASCOfficeDrawingConverter.h"
|
||||
#include "../../XlsxSerializerCom/Writer/CSVWriter.h"
|
||||
|
||||
namespace OOX
|
||||
{
|
||||
@ -50,12 +51,13 @@ namespace BinXlsxRW
|
||||
class SaveParams
|
||||
{
|
||||
public:
|
||||
SaveParams (const std::wstring& _sThemePath, OOX::CContentTypes *pContentTypes);
|
||||
SaveParams (const std::wstring& _sThemePath, OOX::CContentTypes *pContentTypes, CSVWriter::CCSVWriter* pCSVWriter = NULL);
|
||||
|
||||
smart_ptr<PPTX::Theme> pTheme;
|
||||
std::wstring sThemePath;
|
||||
OOX::CContentTypes* pContentTypes;
|
||||
int nThemeOverrideCount;
|
||||
CSVWriter::CCSVWriter* pCSVWriter;
|
||||
};
|
||||
|
||||
class BinaryChartReader : public Binary_CommonReader
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
|
||||
#include "../../DesktopEditor/common/Path.h"
|
||||
#include "../../DesktopEditor/common/Directory.h"
|
||||
#include "../../DesktopEditor/common/StreamWriter.h"
|
||||
|
||||
#include "../Common/BinReaderWriterDefines.h"
|
||||
#include "../Common/Common.h"
|
||||
@ -70,6 +71,19 @@
|
||||
|
||||
namespace BinXlsxRW
|
||||
{
|
||||
#define SEEK_TO_POS_START(type) \
|
||||
nPos = aSeekPositions[2 * type - 1]; \
|
||||
length = aSeekPositions[2 * type]; \
|
||||
if (nPos > 0) \
|
||||
{ \
|
||||
m_oBufferedStream.Seek(nPos); \
|
||||
|
||||
#define SEEK_TO_POS_END(elem) \
|
||||
elem.toXML(oStreamWriter); \
|
||||
}
|
||||
|
||||
#define SEEK_TO_POS_END2(elem) \
|
||||
}
|
||||
|
||||
class ImageObject
|
||||
{
|
||||
@ -151,20 +165,21 @@ namespace BinXlsxRW
|
||||
};
|
||||
class BinaryTableReader : public Binary_CommonReader
|
||||
{
|
||||
OOX::Spreadsheet::CWorksheet* m_pCurWorksheet;
|
||||
public:
|
||||
BinaryTableReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream):Binary_CommonReader(oBufferedStream)
|
||||
BinaryTableReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream, OOX::Spreadsheet::CWorksheet* pCurWorksheet):Binary_CommonReader(oBufferedStream), m_pCurWorksheet(pCurWorksheet)
|
||||
{
|
||||
}
|
||||
int Read(long length, OOX::Spreadsheet::CWorksheet* pWorksheet)
|
||||
int Read(long length, OOX::Spreadsheet::CTableParts* pTableParts)
|
||||
{
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
READ1_DEF(length, res, this->ReadTablePart, pWorksheet);
|
||||
READ1_DEF(length, res, this->ReadTablePart, pTableParts);
|
||||
return res;
|
||||
}
|
||||
int ReadTablePart(BYTE type, long length, void* poResult)
|
||||
{
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
OOX::Spreadsheet::CWorksheet* pWorksheet = static_cast<OOX::Spreadsheet::CWorksheet*>(poResult);
|
||||
OOX::Spreadsheet::CTableParts* pTableParts = static_cast<OOX::Spreadsheet::CTableParts*>(poResult);
|
||||
if(c_oSer_TablePart::Table == type)
|
||||
{
|
||||
OOX::Spreadsheet::CTableFile* pTable = new OOX::Spreadsheet::CTableFile(NULL);
|
||||
@ -173,10 +188,10 @@ namespace BinXlsxRW
|
||||
|
||||
OOX::Spreadsheet::CTablePart* pTablePart = new OOX::Spreadsheet::CTablePart();
|
||||
NSCommon::smart_ptr<OOX::File> pTableFile(pTable);
|
||||
const OOX::RId oRId = pWorksheet->Add(pTableFile);
|
||||
const OOX::RId oRId = m_pCurWorksheet->Add(pTableFile);
|
||||
pTablePart->m_oRId.Init();
|
||||
pTablePart->m_oRId->SetValue(oRId.get());
|
||||
pWorksheet->m_oTableParts->m_arrItems.push_back(pTablePart);
|
||||
pTableParts->m_arrItems.push_back(pTablePart);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
@ -2505,6 +2520,8 @@ namespace BinXlsxRW
|
||||
OOX::Spreadsheet::CWorksheet* m_pCurWorksheet;
|
||||
OOX::Spreadsheet::CDrawing* m_pCurDrawing;
|
||||
OOX::CVmlDrawing* m_pCurVmlDrawing;
|
||||
NSFile::CStreamWriter* m_pCurStreamWriter;
|
||||
OOX::Spreadsheet::COleObjects* m_pCurOleObjects;
|
||||
|
||||
const std::wstring& m_sDestinationDir;
|
||||
const std::wstring& m_sMediaDir;
|
||||
@ -2551,20 +2568,24 @@ namespace BinXlsxRW
|
||||
|
||||
m_pCurVmlDrawing->m_lObjectIdVML = (long)(1024 * (m_oWorkbook.m_oSheets->m_arrItems.size() + 1) + 1);
|
||||
|
||||
READ1_DEF(length, res, this->ReadWorksheet, poResult);
|
||||
_UINT32 aSeekPositions[2 * c_oSerWorksheetsTypes::PivotTable + 1];
|
||||
memset(aSeekPositions, 0, (2 * c_oSerWorksheetsTypes::PivotTable + 1) * sizeof(_UINT32));
|
||||
READ1_DEF(length, res, this->ReadWorksheetSeekPositions, aSeekPositions);
|
||||
|
||||
m_pCurWorksheet->m_sOutputFilename = m_pCurWorksheet->DefaultFileName().GetBasename();
|
||||
m_pCurWorksheet->m_sOutputFilename += std::to_wstring(m_arWorksheets.size() + 1);
|
||||
m_pCurWorksheet->m_sOutputFilename += m_pCurWorksheet->DefaultFileName().GetExtention();
|
||||
std::wstring sWsPath = m_sDestinationDir + FILE_SEPARATOR_STR + _T("xl") + FILE_SEPARATOR_STR + m_pCurWorksheet->DefaultDirectory().GetPath();
|
||||
NSDirectory::CreateDirectories(sWsPath);
|
||||
sWsPath += FILE_SEPARATOR_STR + m_pCurWorksheet->m_sOutputFilename;
|
||||
NSFile::CStreamWriter oStreamWriter;
|
||||
oStreamWriter.CreateFileW(sWsPath);
|
||||
m_pCurStreamWriter = &oStreamWriter;
|
||||
res = ReadWorksheet(aSeekPositions, oStreamWriter, poResult);
|
||||
oStreamWriter.CloseFile();
|
||||
|
||||
if(m_pCurSheet->m_oName.IsInit())
|
||||
{
|
||||
//ole & comment
|
||||
if(m_pCurVmlDrawing->m_aXml.size() > 0 || (NULL != m_pCurVmlDrawing->m_mapComments && m_pCurVmlDrawing->m_mapComments->size() > 0))
|
||||
{
|
||||
NSCommon::smart_ptr<OOX::File> pVmlDrawingFile(m_pCurVmlDrawing);
|
||||
m_pCurVmlDrawing = NULL;
|
||||
const OOX::RId oRId = m_pCurWorksheet->Add(pVmlDrawingFile);
|
||||
m_pCurWorksheet->m_oLegacyDrawing.Init();
|
||||
m_pCurWorksheet->m_oLegacyDrawing->m_oId.Init();
|
||||
m_pCurWorksheet->m_oLegacyDrawing->m_oId->SetValue(oRId.get());
|
||||
}
|
||||
|
||||
smart_ptr<OOX::File> oCurFile(m_pCurWorksheet);
|
||||
const OOX::RId oRId = m_oWorkbook.Add(oCurFile);
|
||||
m_pCurSheet->m_oRid.Init();
|
||||
@ -2580,114 +2601,129 @@ namespace BinXlsxRW
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
}
|
||||
int ReadWorksheet(BYTE type, long length, void* poResult)
|
||||
}
|
||||
int ReadWorksheetSeekPositions(BYTE type, long length, void* poResult)
|
||||
{
|
||||
_UINT32* aSeekPositions = static_cast<_UINT32*>(poResult);
|
||||
aSeekPositions[2 * type - 1] = m_oBufferedStream.GetPos();
|
||||
aSeekPositions[2 * type] = length;
|
||||
return c_oSerConstants::ReadUnknown;
|
||||
}
|
||||
int ReadWorksheet(_UINT32* aSeekPositions, NSFile::CStreamWriter& oStreamWriter, void* poResult)
|
||||
{
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSerWorksheetsTypes::WorksheetProp == type)
|
||||
{
|
||||
READ2_DEF(length, res, this->ReadWorksheetProp, poResult);
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::Cols == type)
|
||||
{
|
||||
m_pCurWorksheet->m_oCols.Init();
|
||||
READ1_DEF(length, res, this->ReadWorksheetCols, poResult);
|
||||
}
|
||||
else if (c_oSerWorksheetsTypes::SheetViews == type)
|
||||
{
|
||||
m_pCurWorksheet->m_oSheetViews.Init();
|
||||
READ1_DEF(length, res, this->ReadSheetViews, poResult);
|
||||
}
|
||||
else if (c_oSerWorksheetsTypes::SheetPr == type)
|
||||
{
|
||||
m_pCurWorksheet->m_oSheetPr.Init();
|
||||
READ1_DEF(length, res, this->ReadSheetPr, m_pCurWorksheet->m_oSheetPr.GetPointer());
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::SheetFormatPr == type)
|
||||
{
|
||||
m_pCurWorksheet->m_oSheetFormatPr.Init();
|
||||
READ2_DEF(length, res, this->ReadSheetFormatPr, m_pCurWorksheet->m_oSheetFormatPr.GetPointer());
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::PageMargins == type)
|
||||
{
|
||||
m_pCurWorksheet->m_oPageMargins.Init();
|
||||
READ2_DEF(length, res, this->ReadPageMargins, m_pCurWorksheet->m_oPageMargins.GetPointer());
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::PageSetup == type)
|
||||
{
|
||||
m_pCurWorksheet->m_oPageSetup.Init();
|
||||
READ2_DEF(length, res, this->ReadPageSetup, m_pCurWorksheet->m_oPageSetup.GetPointer());
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::PrintOptions == type)
|
||||
{
|
||||
m_pCurWorksheet->m_oPrintOptions.Init();
|
||||
READ2_DEF(length, res, this->ReadPrintOptions, m_pCurWorksheet->m_oPrintOptions.GetPointer());
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::Hyperlinks == type)
|
||||
{
|
||||
m_pCurWorksheet->m_oHyperlinks.Init();
|
||||
READ1_DEF(length, res, this->ReadHyperlinks, poResult);
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::MergeCells == type)
|
||||
{
|
||||
m_pCurWorksheet->m_oMergeCells.Init();
|
||||
READ1_DEF(length, res, this->ReadMergeCells, poResult);
|
||||
|
||||
m_pCurWorksheet->m_oMergeCells->m_oCount.Init();
|
||||
m_pCurWorksheet->m_oMergeCells->m_oCount->SetValue((unsigned int)m_pCurWorksheet->m_oMergeCells->m_arrItems.size());
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::Drawings == type)
|
||||
{
|
||||
OOX::CPath pathDrawingsDir = m_sDestinationDir + FILE_SEPARATOR_STR + _T("xl") + FILE_SEPARATOR_STR + _T("drawings");
|
||||
OOX::CSystemUtility::CreateDirectories(pathDrawingsDir.GetPath());
|
||||
|
||||
OOX::CPath pathDrawingsRelsDir = pathDrawingsDir.GetPath() + FILE_SEPARATOR_STR + _T("_rels");
|
||||
OOX::CSystemUtility::CreateDirectories(pathDrawingsRelsDir.GetPath());
|
||||
m_pCurWorksheet->toXMLStart(oStreamWriter);
|
||||
LONG nOldPos = m_oBufferedStream.GetPos();
|
||||
LONG nPos;
|
||||
LONG length;
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::SheetPr);
|
||||
OOX::Spreadsheet::CSheetPr oSheetPr;
|
||||
READ1_DEF(length, res, this->ReadSheetPr, &oSheetPr);
|
||||
SEEK_TO_POS_END(oSheetPr);
|
||||
|
||||
m_pOfficeDrawingConverter->SetDstContentRels();
|
||||
m_pCurDrawing = new OOX::Spreadsheet::CDrawing(NULL);
|
||||
|
||||
READ1_DEF(length, res, this->ReadDrawings, m_pCurDrawing);
|
||||
|
||||
NSCommon::smart_ptr<OOX::File> pDrawingFile(m_pCurDrawing);
|
||||
const OOX::RId oRId = m_pCurWorksheet->Add(pDrawingFile);
|
||||
|
||||
m_pCurWorksheet->m_oDrawing.Init();
|
||||
m_pCurWorksheet->m_oDrawing->m_oId.Init();
|
||||
m_pCurWorksheet->m_oDrawing->m_oId->SetValue(oRId.get());
|
||||
OOX::Spreadsheet::CSheetViews oSheetViews;
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::SheetViews);
|
||||
READ1_DEF(length, res, this->ReadSheetViews, &oSheetViews);
|
||||
SEEK_TO_POS_END2();
|
||||
if(oSheetViews.m_arrItems.empty())
|
||||
oSheetViews.m_arrItems.push_back(new OOX::Spreadsheet::CSheetView());
|
||||
OOX::Spreadsheet::CSheetView* pSheetView = oSheetViews.m_arrItems.front();
|
||||
if(false == pSheetView->m_oWorkbookViewId.IsInit())
|
||||
{
|
||||
pSheetView->m_oWorkbookViewId.Init();
|
||||
pSheetView->m_oWorkbookViewId->SetValue(0);
|
||||
}
|
||||
oSheetViews.toXML(oStreamWriter);
|
||||
|
||||
OOX::CPath pathDrawingsRels = pathDrawingsRelsDir.GetPath() + FILE_SEPARATOR_STR + m_pCurDrawing->m_sOutputFilename + _T(".rels");
|
||||
m_pOfficeDrawingConverter->SaveDstContentRels(pathDrawingsRels.GetPath());
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::SheetData == type)
|
||||
OOX::Spreadsheet::CSheetFormatPr oSheetFormatPr;
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::SheetFormatPr);
|
||||
READ2_DEF(length, res, this->ReadSheetFormatPr, &oSheetFormatPr);
|
||||
SEEK_TO_POS_END2();
|
||||
if(!oSheetFormatPr.m_oDefaultRowHeight.IsInit())
|
||||
{
|
||||
m_pCurWorksheet->m_oSheetData.Init();
|
||||
READ1_DEF(length, res, this->ReadSheetData, poResult);
|
||||
oSheetFormatPr.m_oDefaultRowHeight.Init();
|
||||
oSheetFormatPr.m_oDefaultRowHeight->SetValue(15);
|
||||
}
|
||||
else if (c_oSerWorksheetsTypes::ConditionalFormatting == type)
|
||||
{
|
||||
OOX::Spreadsheet::CConditionalFormatting* pConditionalFormatting = new OOX::Spreadsheet::CConditionalFormatting();
|
||||
READ1_DEF(length, res, this->ReadConditionalFormatting, pConditionalFormatting);
|
||||
m_pCurWorksheet->m_arrConditionalFormatting.push_back(pConditionalFormatting);
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::Comments == type)
|
||||
{
|
||||
oSheetFormatPr.toXML(oStreamWriter);
|
||||
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::Cols);
|
||||
OOX::Spreadsheet::CCols oCols;
|
||||
READ1_DEF(length, res, this->ReadWorksheetCols, &oCols);
|
||||
SEEK_TO_POS_END(oCols);
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::SheetData);
|
||||
OOX::Spreadsheet::CSheetData oSheetData;
|
||||
if (NULL == m_oSaveParams.pCSVWriter)
|
||||
{
|
||||
oSheetData.toXMLStart(oStreamWriter);
|
||||
READ1_DEF(length, res, this->ReadSheetData, NULL);
|
||||
oSheetData.toXMLEnd(oStreamWriter);
|
||||
}
|
||||
else if(m_arWorksheets.size() == m_oWorkbook.GetActiveSheetIndex())
|
||||
{
|
||||
m_oSaveParams.pCSVWriter->WriteSheetStart(m_pCurWorksheet);
|
||||
READ1_DEF(length, res, this->ReadSheetData, NULL);
|
||||
m_oSaveParams.pCSVWriter->WriteSheetEnd(m_pCurWorksheet);
|
||||
}
|
||||
SEEK_TO_POS_END2();
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::Autofilter);
|
||||
OOX::Spreadsheet::CAutofilter oAutofilter;
|
||||
BinaryTableReader oBinaryTableReader(m_oBufferedStream, m_pCurWorksheet);
|
||||
READ1_DEF(length, res, oBinaryTableReader.ReadAutoFilter, &oAutofilter);
|
||||
SEEK_TO_POS_END(oAutofilter);
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::MergeCells);
|
||||
OOX::Spreadsheet::CMergeCells oMergeCells;
|
||||
READ1_DEF(length, res, this->ReadMergeCells, &oMergeCells);
|
||||
oMergeCells.m_oCount.Init();
|
||||
oMergeCells.m_oCount->SetValue((unsigned int)oMergeCells.m_arrItems.size());
|
||||
SEEK_TO_POS_END(oMergeCells);
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::ConditionalFormatting);
|
||||
OOX::Spreadsheet::CConditionalFormatting oConditionalFormatting;
|
||||
READ1_DEF(length, res, this->ReadConditionalFormatting, &oConditionalFormatting);
|
||||
SEEK_TO_POS_END(oConditionalFormatting);
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::Hyperlinks);
|
||||
OOX::Spreadsheet::CHyperlinks oHyperlinks;
|
||||
READ1_DEF(length, res, this->ReadHyperlinks, &oHyperlinks);
|
||||
SEEK_TO_POS_END(oHyperlinks);
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::PrintOptions);
|
||||
OOX::Spreadsheet::CPrintOptions oPrintOptions;
|
||||
READ2_DEF(length, res, this->ReadPrintOptions, &oPrintOptions);
|
||||
SEEK_TO_POS_END(oPrintOptions);
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::PageMargins);
|
||||
OOX::Spreadsheet::CPageMargins oPageMargins;
|
||||
READ2_DEF(length, res, this->ReadPageMargins, &oPageMargins);
|
||||
SEEK_TO_POS_END(oPageMargins);
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::PageSetup);
|
||||
OOX::Spreadsheet::CPageSetup oPageSetup;
|
||||
READ2_DEF(length, res, this->ReadPageSetup, &oPageSetup);
|
||||
SEEK_TO_POS_END(oPageSetup);
|
||||
|
||||
//important before Drawings
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::Comments);
|
||||
BinaryCommentReader oBinaryCommentReader(m_oBufferedStream, m_pCurWorksheet);
|
||||
oBinaryCommentReader.Read(length, poResult);
|
||||
|
||||
|
||||
if(m_pCurWorksheet->m_mapComments.size() > 0)
|
||||
{
|
||||
m_pCurVmlDrawing->m_mapComments = &m_pCurWorksheet->m_mapComments;
|
||||
|
||||
boost::unordered_map<std::wstring, unsigned int> mapByAuthors;
|
||||
boost::unordered_map<std::wstring, unsigned int> mapByAuthors;
|
||||
OOX::Spreadsheet::CComments* pComments = new OOX::Spreadsheet::CComments(NULL);
|
||||
|
||||
|
||||
pComments->m_oCommentList.Init();
|
||||
std::vector<OOX::Spreadsheet::CComment*>& aComments = pComments->m_oCommentList->m_arrItems;
|
||||
|
||||
std::vector<OOX::Spreadsheet::CComment*>& aComments = pComments->m_oCommentList->m_arrItems;
|
||||
|
||||
pComments->m_oAuthors.Init();
|
||||
|
||||
for (boost::unordered_map<std::wstring, OOX::Spreadsheet::CCommentItem*>::const_iterator it = m_pCurWorksheet->m_mapComments.begin(); it != m_pCurWorksheet->m_mapComments.end(); ++it)
|
||||
for (boost::unordered_map<std::wstring, OOX::Spreadsheet::CCommentItem*>::const_iterator it = m_pCurWorksheet->m_mapComments.begin(); it != m_pCurWorksheet->m_mapComments.end(); ++it)
|
||||
{
|
||||
if(it->second->IsValid())
|
||||
{
|
||||
@ -2702,18 +2738,18 @@ namespace BinXlsxRW
|
||||
if(pCommentItem->m_sAuthor.IsInit())
|
||||
{
|
||||
const std::wstring& sAuthor = pCommentItem->m_sAuthor.get();
|
||||
boost::unordered_map<std::wstring, unsigned int>::const_iterator pFind = mapByAuthors.find(sAuthor);
|
||||
|
||||
boost::unordered_map<std::wstring, unsigned int>::const_iterator pFind = mapByAuthors.find(sAuthor);
|
||||
|
||||
int nAuthorId;
|
||||
if(pFind != mapByAuthors.end())
|
||||
nAuthorId = pFind->second;
|
||||
else
|
||||
{
|
||||
nAuthorId = (int)mapByAuthors.size();
|
||||
|
||||
|
||||
mapByAuthors.insert(std::make_pair(sAuthor, nAuthorId));
|
||||
|
||||
pComments->m_oAuthors->m_arrItems.push_back( sAuthor );
|
||||
|
||||
pComments->m_oAuthors->m_arrItems.push_back( sAuthor );
|
||||
}
|
||||
pNewComment->m_oAuthorId.Init();
|
||||
pNewComment->m_oAuthorId->SetValue(nAuthorId);
|
||||
@ -2729,42 +2765,79 @@ namespace BinXlsxRW
|
||||
NSCommon::smart_ptr<OOX::File> pCommentsFile(pComments);
|
||||
m_pCurWorksheet->Add(pCommentsFile);
|
||||
}
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::Autofilter == type)
|
||||
{
|
||||
BinaryTableReader oBinaryTableReader(m_oBufferedStream);
|
||||
m_pCurWorksheet->m_oAutofilter.Init();
|
||||
READ1_DEF(length, res, oBinaryTableReader.ReadAutoFilter, m_pCurWorksheet->m_oAutofilter.GetPointer());
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::TableParts == type)
|
||||
{
|
||||
BinaryTableReader oBinaryTableReader(m_oBufferedStream);
|
||||
m_pCurWorksheet->m_oTableParts.Init();
|
||||
oBinaryTableReader.Read(length, m_pCurWorksheet);
|
||||
|
||||
m_pCurWorksheet->m_oTableParts->m_oCount.Init();
|
||||
m_pCurWorksheet->m_oTableParts->m_oCount->SetValue((unsigned int)m_pCurWorksheet->m_oTableParts->m_arrItems.size());
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::SparklineGroups == type)
|
||||
{
|
||||
OOX::Drawing::COfficeArtExtension* pOfficeArtExtension = new OOX::Drawing::COfficeArtExtension();
|
||||
pOfficeArtExtension->m_oSparklineGroups.Init();
|
||||
SEEK_TO_POS_END2();
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::Drawings);
|
||||
OOX::CPath pathDrawingsDir = m_sDestinationDir + FILE_SEPARATOR_STR + _T("xl") + FILE_SEPARATOR_STR + _T("drawings");
|
||||
OOX::CSystemUtility::CreateDirectories(pathDrawingsDir.GetPath());
|
||||
|
||||
OOX::CPath pathDrawingsRelsDir = pathDrawingsDir.GetPath() + FILE_SEPARATOR_STR + _T("_rels");
|
||||
OOX::CSystemUtility::CreateDirectories(pathDrawingsRelsDir.GetPath());
|
||||
|
||||
m_pOfficeDrawingConverter->SetDstContentRels();
|
||||
m_pCurDrawing = new OOX::Spreadsheet::CDrawing(NULL);
|
||||
OOX::Spreadsheet::COleObjects oOleObjects;
|
||||
m_pCurOleObjects = &oOleObjects;
|
||||
READ1_DEF(length, res, this->ReadDrawings, m_pCurDrawing);
|
||||
|
||||
NSCommon::smart_ptr<OOX::File> pDrawingFile(m_pCurDrawing);
|
||||
const OOX::RId oRId = m_pCurWorksheet->Add(pDrawingFile);
|
||||
OOX::Spreadsheet::CDrawingWorksheet oDrawingWorksheet;
|
||||
oDrawingWorksheet.m_oId.Init();
|
||||
oDrawingWorksheet.m_oId->SetValue(oRId.get());
|
||||
oDrawingWorksheet.toXML(oStreamWriter);
|
||||
//ole & comment
|
||||
if(m_pCurVmlDrawing->m_aXml.size() > 0 || (NULL != m_pCurVmlDrawing->m_mapComments && m_pCurVmlDrawing->m_mapComments->size() > 0))
|
||||
{
|
||||
NSCommon::smart_ptr<OOX::File> pVmlDrawingFile(m_pCurVmlDrawing);
|
||||
m_pCurVmlDrawing = NULL;
|
||||
const OOX::RId oRId = m_pCurWorksheet->Add(pVmlDrawingFile);
|
||||
OOX::Spreadsheet::CLegacyDrawingWorksheet oLegacyDrawing;
|
||||
oLegacyDrawing.m_oId.Init();
|
||||
oLegacyDrawing.m_oId->SetValue(oRId.get());
|
||||
oLegacyDrawing.toXML(oStreamWriter);
|
||||
}
|
||||
if (oOleObjects.m_mapOleObjects.size() > 0)
|
||||
{
|
||||
oOleObjects.toXML(oStreamWriter);
|
||||
}
|
||||
|
||||
OOX::CPath pathDrawingsRels = pathDrawingsRelsDir.GetPath() + FILE_SEPARATOR_STR + m_pCurDrawing->m_sOutputFilename + _T(".rels");
|
||||
m_pOfficeDrawingConverter->SaveDstContentRels(pathDrawingsRels.GetPath());
|
||||
SEEK_TO_POS_END2();
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::TableParts);
|
||||
BinaryTableReader oBinaryTableReader(m_oBufferedStream, m_pCurWorksheet);
|
||||
OOX::Spreadsheet::CTableParts oTableParts;
|
||||
oBinaryTableReader.Read(length, &oTableParts);
|
||||
oTableParts.m_oCount.Init();
|
||||
oTableParts.m_oCount->SetValue((unsigned int)oTableParts.m_arrItems.size());
|
||||
SEEK_TO_POS_END(oTableParts);
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::SparklineGroups);
|
||||
OOX::Drawing::COfficeArtExtension* pOfficeArtExtension = new OOX::Drawing::COfficeArtExtension();
|
||||
pOfficeArtExtension->m_oSparklineGroups.Init();
|
||||
|
||||
READ1_DEF(length, res, this->ReadSparklineGroups, pOfficeArtExtension->m_oSparklineGroups.GetPointer());
|
||||
|
||||
pOfficeArtExtension->m_sUri.Init();
|
||||
pOfficeArtExtension->m_sUri->append(_T("{05C60535-1F16-4fd2-B633-F4F36F0B64E0}"));
|
||||
pOfficeArtExtension->m_sAdditionalNamespace = _T("xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\"");
|
||||
m_pCurWorksheet->m_oExtLst.Init();
|
||||
m_pCurWorksheet->m_oExtLst->m_arrExt.push_back(pOfficeArtExtension);
|
||||
}
|
||||
else if(c_oSerWorksheetsTypes::PivotTable == type)
|
||||
{
|
||||
pOfficeArtExtension->m_sUri.Init();
|
||||
pOfficeArtExtension->m_sUri->append(_T("{05C60535-1F16-4fd2-B633-F4F36F0B64E0}"));
|
||||
pOfficeArtExtension->m_sAdditionalNamespace = _T("xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\"");
|
||||
OOX::Drawing::COfficeArtExtensionList oExtLst;
|
||||
oExtLst.m_arrExt.push_back(pOfficeArtExtension);
|
||||
oStreamWriter.WriteString(oExtLst.toXMLWithNS(_T("")));
|
||||
SEEK_TO_POS_END2();
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::WorksheetProp);
|
||||
READ2_DEF(length, res, this->ReadWorksheetProp, poResult);
|
||||
SEEK_TO_POS_END2();
|
||||
|
||||
SEEK_TO_POS_START(c_oSerWorksheetsTypes::PivotTable);
|
||||
PivotCachesTemp oPivotCachesTemp;
|
||||
|
||||
|
||||
READ1_DEF(length, res, this->ReadPivotTable, &oPivotCachesTemp);
|
||||
boost::unordered_map<long, NSCommon::smart_ptr<OOX::File>>::const_iterator pair = m_mapPivotCacheDefinitions.find(oPivotCachesTemp.nCacheId);
|
||||
|
||||
boost::unordered_map<long, NSCommon::smart_ptr<OOX::File>>::const_iterator pair = m_mapPivotCacheDefinitions.find(oPivotCachesTemp.nCacheId);
|
||||
|
||||
if(m_mapPivotCacheDefinitions.end() != pair && NULL != oPivotCachesTemp.pTable)
|
||||
{
|
||||
NSCommon::smart_ptr<OOX::File> pFileTable(oPivotCachesTemp.pTable);
|
||||
@ -2775,9 +2848,10 @@ namespace BinXlsxRW
|
||||
{
|
||||
RELEASEOBJECT(oPivotCachesTemp.pTable);
|
||||
}
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
SEEK_TO_POS_END2();
|
||||
|
||||
m_oBufferedStream.Seek(nOldPos);
|
||||
m_pCurWorksheet->toXMLEnd(oStreamWriter);
|
||||
return res;
|
||||
}
|
||||
int ReadPivotTable(BYTE type, long length, void* poResult)
|
||||
@ -2823,12 +2897,13 @@ namespace BinXlsxRW
|
||||
}
|
||||
int ReadWorksheetCols(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CCols* pCols = static_cast<OOX::Spreadsheet::CCols*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSerWorksheetsTypes::Col == type)
|
||||
{
|
||||
OOX::Spreadsheet::CCol* pCol = new OOX::Spreadsheet::CCol();
|
||||
READ2_DEF(length, res, this->ReadWorksheetCol, pCol);
|
||||
m_pCurWorksheet->m_oCols->m_arrItems.push_back(pCol);
|
||||
pCols->m_arrItems.push_back(pCol);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
@ -2889,12 +2964,13 @@ namespace BinXlsxRW
|
||||
}
|
||||
int ReadSheetViews(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CSheetViews* pSheetViews = static_cast<OOX::Spreadsheet::CSheetViews*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSerWorksheetsTypes::SheetView == type)
|
||||
{
|
||||
OOX::Spreadsheet::CSheetView* pSheetView = new OOX::Spreadsheet::CSheetView();
|
||||
READ1_DEF(length, res, this->ReadSheetView, pSheetView);
|
||||
m_pCurWorksheet->m_oSheetViews->m_arrItems.push_back(pSheetView);
|
||||
pSheetViews->m_arrItems.push_back(pSheetView);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
@ -3250,12 +3326,13 @@ namespace BinXlsxRW
|
||||
}
|
||||
int ReadHyperlinks(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CHyperlinks* pHyperlinks = static_cast<OOX::Spreadsheet::CHyperlinks*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSerWorksheetsTypes::Hyperlink == type)
|
||||
{
|
||||
OOX::Spreadsheet::CHyperlink* pHyperlink = new OOX::Spreadsheet::CHyperlink();
|
||||
READ1_DEF(length, res, this->ReadHyperlink, pHyperlink);
|
||||
m_pCurWorksheet->m_oHyperlinks->m_arrItems.push_back(pHyperlink);
|
||||
pHyperlinks->m_arrItems.push_back(pHyperlink);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
@ -3298,13 +3375,14 @@ namespace BinXlsxRW
|
||||
}
|
||||
int ReadMergeCells(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CMergeCells* pMergeCells = static_cast<OOX::Spreadsheet::CMergeCells*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSerWorksheetsTypes::MergeCell == type)
|
||||
{
|
||||
OOX::Spreadsheet::CMergeCell* pMergeCell = new OOX::Spreadsheet::CMergeCell();
|
||||
pMergeCell->m_oRef.Init();
|
||||
pMergeCell->m_oRef->append(m_oBufferedStream.GetString4(length));
|
||||
m_pCurWorksheet->m_oMergeCells->m_arrItems.push_back(pMergeCell);
|
||||
pMergeCells->m_arrItems.push_back(pMergeCell);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
@ -3404,10 +3482,6 @@ namespace BinXlsxRW
|
||||
oRIdImg = new OOX::RId(m_pCurWorksheet->Add(pFileWorksheet));
|
||||
}
|
||||
//add oleObject rels
|
||||
if(!m_pCurWorksheet->m_oOleObjects.IsInit())
|
||||
{
|
||||
m_pCurWorksheet->m_oOleObjects.Init();
|
||||
}
|
||||
|
||||
smart_ptr<OOX::File> pFileObject = pOleObject->m_OleObjectFile.smart_dynamic_cast<OOX::File>();
|
||||
const OOX::RId oRIdBin = m_pCurWorksheet->Add(pFileObject);
|
||||
@ -3442,7 +3516,7 @@ namespace BinXlsxRW
|
||||
pOleObject->m_oObjectPr->m_oAnchor->m_oFrom = pCellAnchor->m_oFrom;
|
||||
pOleObject->m_oObjectPr->m_oAnchor->m_oTo = pCellAnchor->m_oTo;
|
||||
|
||||
m_pCurWorksheet->m_oOleObjects->m_mapOleObjects[pOleObject->m_oShapeId->GetValue()] = pOleObject;
|
||||
m_pCurOleObjects->m_mapOleObjects[pOleObject->m_oShapeId->GetValue()] = pOleObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3582,9 +3656,8 @@ namespace BinXlsxRW
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSerWorksheetsTypes::Row == type)
|
||||
{
|
||||
OOX::Spreadsheet::CRow* pRow = new OOX::Spreadsheet::CRow();
|
||||
READ2_DEF(length, res, this->ReadRow, pRow);
|
||||
m_pCurWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
|
||||
OOX::Spreadsheet::CRow oRow;
|
||||
READ2_DEF(length, res, this->ReadRow, &oRow);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
@ -3633,7 +3706,18 @@ namespace BinXlsxRW
|
||||
}
|
||||
else if(c_oSerRowTypes::Cells == type)
|
||||
{
|
||||
READ1_DEF(length, res, this->ReadCells, pRow);
|
||||
if (NULL == m_oSaveParams.pCSVWriter)
|
||||
{
|
||||
pRow->toXMLStart(*m_pCurStreamWriter);
|
||||
READ1_DEF(length, res, this->ReadCells, pRow);
|
||||
pRow->toXMLEnd(*m_pCurStreamWriter);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_oSaveParams.pCSVWriter->WriteRowStart(pRow);
|
||||
READ1_DEF(length, res, this->ReadCells, pRow);
|
||||
m_oSaveParams.pCSVWriter->WriteRowEnd(pRow);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
@ -3646,24 +3730,24 @@ namespace BinXlsxRW
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSerRowTypes::Cell == type)
|
||||
{
|
||||
OOX::Spreadsheet::CCell* pCell = new OOX::Spreadsheet::CCell();
|
||||
READ1_DEF(length, res, this->ReadCell, pCell);
|
||||
OOX::Spreadsheet::CCell oCell;
|
||||
READ1_DEF(length, res, this->ReadCell, &oCell);
|
||||
|
||||
//текст error и формул пишем
|
||||
if(NULL != m_pSharedStrings && pCell->m_oType.IsInit() && pCell->m_oValue.IsInit())
|
||||
if(NULL != m_pSharedStrings && oCell.m_oType.IsInit() && oCell.m_oValue.IsInit())
|
||||
{
|
||||
SimpleTypes::Spreadsheet::ECellTypeType eCellType = pCell->m_oType->GetValue();
|
||||
SimpleTypes::Spreadsheet::ECellTypeType eCellType = oCell.m_oType->GetValue();
|
||||
bool bMoveText = false;
|
||||
if(SimpleTypes::Spreadsheet::celltypeError == eCellType)
|
||||
bMoveText = true;
|
||||
else if((SimpleTypes::Spreadsheet::celltypeSharedString == eCellType && pCell->m_oFormula.IsInit()))
|
||||
else if((SimpleTypes::Spreadsheet::celltypeSharedString == eCellType && oCell.m_oFormula.IsInit()))
|
||||
{
|
||||
bMoveText = true;
|
||||
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeStr);
|
||||
oCell.m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeStr);
|
||||
}
|
||||
if(bMoveText)
|
||||
{
|
||||
int nValue = _wtoi(pCell->m_oValue->ToString().c_str());
|
||||
int nValue = _wtoi(oCell.m_oValue->ToString().c_str());
|
||||
|
||||
if (nValue >= 0 && nValue < (int)m_pSharedStrings->m_arrItems.size())
|
||||
{
|
||||
@ -3674,14 +3758,21 @@ namespace BinXlsxRW
|
||||
if(OOX::et_x_t == pWe->getType())
|
||||
{
|
||||
OOX::Spreadsheet::CText* pText = static_cast<OOX::Spreadsheet::CText*>(pWe);
|
||||
pCell->m_oValue->m_sText = pText->m_sText;
|
||||
pCell->m_oValue->m_oSpace = pText->m_oSpace;
|
||||
oCell.m_oValue->m_sText = pText->m_sText;
|
||||
oCell.m_oValue->m_oSpace = pText->m_oSpace;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pRow->m_arrItems.push_back(pCell);
|
||||
if (NULL == m_oSaveParams.pCSVWriter)
|
||||
{
|
||||
oCell.toXML(*m_pCurStreamWriter);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_oSaveParams.pCSVWriter->WriteCell(&oCell);
|
||||
}
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
@ -4518,27 +4609,20 @@ namespace BinXlsxRW
|
||||
OOX::Spreadsheet::CXlsx oXlsx;
|
||||
std::wstring params_path = sDstPath + FILE_SEPARATOR_STR + OOX::Spreadsheet::FileTypes::Workbook.DefaultDirectory().GetPath() + FILE_SEPARATOR_STR + OOX::FileTypes::Theme.DefaultDirectory().GetPath();
|
||||
|
||||
SaveParams oSaveParams(params_path.c_str(), pOfficeDrawingConverter->GetContentTypes());
|
||||
|
||||
ReadMainTable(oXlsx, oBufferedStream, OOX::CPath(sSrcFileName).GetDirectory(), sDstPath, oSaveParams, pOfficeDrawingConverter);
|
||||
|
||||
//std::wstring sAdditionalContentTypes = oSaveParams.sAdditionalContentTypes;
|
||||
|
||||
// if(NULL != pOfficeDrawingConverter)
|
||||
//{
|
||||
// sAdditionalContentTypes += pOfficeDrawingConverter->GetContentTypes();
|
||||
//}
|
||||
oXlsx.PrepareToWrite();
|
||||
|
||||
switch(fileType)
|
||||
if(BinXlsxRW::c_oFileTypes::XLSX == fileType)
|
||||
{
|
||||
case BinXlsxRW::c_oFileTypes::CSV:
|
||||
CSVWriter::WriteFromXlsxToCsv(sDstPathCSV, oXlsx, nCodePage, sDelimiter, false);
|
||||
break;
|
||||
case BinXlsxRW::c_oFileTypes::XLSX:
|
||||
default:
|
||||
SaveParams oSaveParams(params_path.c_str(), pOfficeDrawingConverter->GetContentTypes(), NULL);
|
||||
ReadMainTable(oXlsx, oBufferedStream, OOX::CPath(sSrcFileName).GetDirectory(), sDstPath, oSaveParams, pOfficeDrawingConverter);
|
||||
oXlsx.PrepareToWrite();
|
||||
oXlsx.Write(sDstPath, *oSaveParams.pContentTypes);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSVWriter::CCSVWriter oCSVWriter(oXlsx, nCodePage, sDelimiter, false);
|
||||
oCSVWriter.Start(sDstPathCSV);
|
||||
SaveParams oSaveParams(params_path.c_str(), pOfficeDrawingConverter->GetContentTypes(), &oCSVWriter);
|
||||
ReadMainTable(oXlsx, oBufferedStream, OOX::CPath(sSrcFileName).GetDirectory(), sDstPath, oSaveParams, pOfficeDrawingConverter);
|
||||
oCSVWriter.End();
|
||||
}
|
||||
bResultOk = true;
|
||||
}
|
||||
|
||||
@ -41,6 +41,13 @@
|
||||
|
||||
namespace CSVWriter
|
||||
{
|
||||
static std::wstring g_sNewLineN = _T("\n");
|
||||
static std::wstring g_sEndJson = _T("]");
|
||||
static std::wstring g_sQuote = _T("\"");
|
||||
static std::wstring g_sDoubleQuote = _T("\"\"");
|
||||
static std::wstring g_sBkt = _T("[");
|
||||
static std::wstring g_sBktComma = _T(",[");
|
||||
|
||||
void escapeJson(const std::wstring& sInput, NSStringUtils::CStringBuilder& oBuilder)
|
||||
{
|
||||
//http://stackoverflow.com/questions/7724448/simple-json-string-escape-for-c
|
||||
@ -69,7 +76,7 @@ namespace CSVWriter
|
||||
}
|
||||
}
|
||||
}
|
||||
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, const std::wstring &sWriteString, UINT &nCodePage, bool bIsEnd)
|
||||
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, const std::wstring &sWriteString, UINT &nCodePage, bool bIsEnd = false)
|
||||
{
|
||||
if (NULL == pFile || NULL == pWriteBuffer)
|
||||
return;
|
||||
@ -113,59 +120,25 @@ namespace CSVWriter
|
||||
}
|
||||
void WriteFromXlsxToCsv(const std::wstring &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& sDelimiter, bool bJSON)
|
||||
{
|
||||
NSFile::CFileBinary oFile;
|
||||
oFile.CreateFileW(sFileDst);
|
||||
|
||||
// Нужно записать шапку
|
||||
if (46 == nCodePage)//todo 46 временно CP_UTF8
|
||||
{
|
||||
BYTE arUTF8[3] = {0xEF, 0xBB, 0xBF};
|
||||
oFile.WriteFile(arUTF8, 3);
|
||||
}
|
||||
else if (48 == nCodePage)//todo 48 временно CP_UTF16
|
||||
{
|
||||
BYTE arUTF16[2] = {0xFF, 0xFE};
|
||||
oFile.WriteFile(arUTF16, 2);
|
||||
}
|
||||
else if (49 == nCodePage)//todo 49 временно CP_unicodeFFFE
|
||||
{
|
||||
BYTE arBigEndian[2] = {0xFE, 0xFF};
|
||||
oFile.WriteFile(arBigEndian, 2);
|
||||
}
|
||||
|
||||
std::wstring sNewLineN = _T("\n");
|
||||
LONG lActiveSheet = 0;
|
||||
INT nCurrentIndex = 0;
|
||||
WCHAR *pWriteBuffer = NULL;
|
||||
|
||||
std::wstring sSheetRId = _T("Sheet1"); // Читаем не по rId, а по имени листа
|
||||
CCSVWriter oWriter(oXlsx, nCodePage, sDelimiter, bJSON);
|
||||
oWriter.Start(sFileDst);
|
||||
if ( oXlsx.m_pWorkbook )
|
||||
{
|
||||
// Get active sheet
|
||||
if ( oXlsx.m_pWorkbook->m_oBookViews.IsInit() && !oXlsx.m_pWorkbook->m_oBookViews->m_arrItems.empty())
|
||||
{
|
||||
if ( oXlsx.m_pWorkbook->m_oBookViews->m_arrItems.front()->m_oActiveTab.IsInit())
|
||||
{
|
||||
lActiveSheet = oXlsx.m_pWorkbook->m_oBookViews->m_arrItems.front()->m_oActiveTab->GetValue();
|
||||
if (0 > lActiveSheet)
|
||||
lActiveSheet = 0;
|
||||
}
|
||||
}
|
||||
|
||||
LONG lActiveSheet = oXlsx.m_pWorkbook->GetActiveSheetIndex();
|
||||
std::wstring sSheetRId = _T("Sheet1"); // Читаем не по rId, а по имени листа
|
||||
// Get active sheet rId (для конвертации в CSV нужно использовать name, т.к. это наш бинарник из js-скриптов и еще нет rId
|
||||
// А для json-а нужно пользовать rId, т.к. при открытии они используются
|
||||
if ( oXlsx.m_pWorkbook->m_oSheets.IsInit() && !oXlsx.m_pWorkbook->m_oSheets->m_arrItems.empty())
|
||||
{
|
||||
OOX::Spreadsheet::CSheet *pSheet = NULL;
|
||||
OOX::Spreadsheet::CSheet* pSheet = NULL;
|
||||
if (lActiveSheet >= 0 && lActiveSheet < oXlsx.m_pWorkbook->m_oSheets->m_arrItems.size())
|
||||
{
|
||||
pSheet = oXlsx.m_pWorkbook->m_oSheets->m_arrItems[lActiveSheet];
|
||||
pSheet = oXlsx.m_pWorkbook-> m_oSheets->m_arrItems[lActiveSheet];
|
||||
}
|
||||
else
|
||||
{
|
||||
pSheet = oXlsx.m_pWorkbook->m_oSheets->m_arrItems.front();
|
||||
}
|
||||
|
||||
sSheetRId = bJSON ? pSheet->m_oRid->GetValue() : pSheet->m_oName.get2();
|
||||
}
|
||||
|
||||
@ -173,141 +146,192 @@ namespace CSVWriter
|
||||
if (pFind != oXlsx.m_mapWorksheets.end())
|
||||
{
|
||||
OOX::Spreadsheet::CWorksheet *pWorksheet = pFind->second;
|
||||
|
||||
if (NULL != pWorksheet && pWorksheet->m_oSheetData.IsInit())
|
||||
{
|
||||
std::wstring sEscape = _T("\"\n");
|
||||
sEscape += sDelimiter;
|
||||
std::wstring sEndJson = std::wstring(_T("]"));
|
||||
std::wstring sQuote = _T("\"");
|
||||
std::wstring sDoubleQuote = _T("\"\"");
|
||||
std::wstring sBkt = std::wstring(_T("["));
|
||||
std::wstring sBktComma = _T(",[");
|
||||
|
||||
if (bJSON)
|
||||
CSVWriter::WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sBkt, nCodePage);
|
||||
|
||||
INT nRowCurrent = 1;
|
||||
for (size_t i = 0; i < pWorksheet->m_oSheetData->m_arrItems.size(); ++i)
|
||||
oWriter.WriteSheetStart(pWorksheet);
|
||||
for (size_t i = 0; i < pWorksheet->m_oSheetData->m_arrItems.size(); ++i)
|
||||
{
|
||||
OOX::Spreadsheet::CRow *pRow = pWorksheet->m_oSheetData->m_arrItems[i];
|
||||
|
||||
INT nRow = pRow->m_oR.IsInit() ? pRow->m_oR->GetValue() : 0 == i ? nRowCurrent : nRowCurrent + 1;
|
||||
|
||||
if (bJSON)
|
||||
CSVWriter::WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, (0 == i ? sBkt: sBktComma), nCodePage);
|
||||
else
|
||||
OOX::Spreadsheet::CRow *pRow = pWorksheet->m_oSheetData->m_arrItems[i];
|
||||
oWriter.WriteRowStart(pRow);
|
||||
for (size_t j = 0; j < pRow->m_arrItems.size(); ++j)
|
||||
{
|
||||
while (nRow > nRowCurrent)
|
||||
{
|
||||
// Write new line
|
||||
++nRowCurrent;
|
||||
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage);
|
||||
}
|
||||
oWriter.WriteCell(pRow->m_arrItems[j]);
|
||||
}
|
||||
|
||||
INT nColCurrent = 1;
|
||||
bool bIsWriteCell = false; // Нужно только для записи JSON-а
|
||||
|
||||
for (size_t j = 0; j < pRow->m_arrItems.size(); ++j)
|
||||
{
|
||||
INT nRowTmp = 0;
|
||||
INT nCol = 0;
|
||||
OOX::Spreadsheet::CCell *pCell = pRow->m_arrItems[j];
|
||||
|
||||
if (pCell->isInitRef())
|
||||
{
|
||||
pCell->getRowCol(nRowTmp, nCol);
|
||||
nRowTmp++;
|
||||
nCol++;
|
||||
}
|
||||
else
|
||||
{
|
||||
nCol = 0 == j ? nColCurrent : nColCurrent + 1;
|
||||
}
|
||||
|
||||
while (nCol > nColCurrent)
|
||||
{
|
||||
if (bJSON && false == bIsWriteCell)
|
||||
{
|
||||
// Запишем пустые строки (для JSON-а)
|
||||
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sDoubleQuote, nCodePage);
|
||||
}
|
||||
// Write delimiter
|
||||
++nColCurrent;
|
||||
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sDelimiter, nCodePage);
|
||||
bIsWriteCell = false;
|
||||
}
|
||||
|
||||
// Get cell value
|
||||
std::wstring sCellValue = _T("");
|
||||
if (pCell->m_oValue.IsInit())
|
||||
{
|
||||
if (pCell->m_oType.IsInit() && SimpleTypes::Spreadsheet::celltypeNumber != pCell->m_oType->GetValue())
|
||||
{
|
||||
if(SimpleTypes::Spreadsheet::celltypeStr == pCell->m_oType->GetValue())
|
||||
{
|
||||
sCellValue = pCell->m_oValue->ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
int nValue = _wtoi(pCell->m_oValue->ToString().c_str());
|
||||
|
||||
if (nValue >= 0 && nValue < oXlsx.m_pSharedStrings->m_arrItems.size())
|
||||
{
|
||||
OOX::Spreadsheet::CSi *pSi = oXlsx.m_pSharedStrings->m_arrItems[nValue];
|
||||
if(NULL != pSi)
|
||||
{
|
||||
sCellValue = pSi->ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sCellValue = pCell->m_oValue->ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// Escape cell value
|
||||
if(bJSON)
|
||||
{
|
||||
NSStringUtils::CStringBuilder oBuilder;
|
||||
oBuilder.WriteString(_T("\""));
|
||||
escapeJson(sCellValue, oBuilder);
|
||||
oBuilder.WriteString(_T("\""));
|
||||
sCellValue = std::wstring(oBuilder.GetBuffer(), oBuilder.GetCurSize());
|
||||
}
|
||||
else if (std::wstring::npos != sCellValue.find_first_of(sEscape))
|
||||
{
|
||||
NSStringExt::Replace(sCellValue, sQuote, sDoubleQuote);
|
||||
sCellValue = sQuote + sCellValue + sQuote;
|
||||
}
|
||||
// Write cell value
|
||||
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sCellValue, nCodePage);
|
||||
bIsWriteCell = true;
|
||||
}
|
||||
|
||||
if (bJSON)
|
||||
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sEndJson, nCodePage);
|
||||
}
|
||||
|
||||
if (bJSON)
|
||||
{
|
||||
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sEndJson, nCodePage);
|
||||
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sEndJson, nCodePage, true);
|
||||
oWriter.WriteRowEnd(pRow);
|
||||
}
|
||||
oWriter.WriteSheetEnd(pWorksheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
oWriter.End();
|
||||
}
|
||||
CCSVWriter::CCSVWriter(OOX::Spreadsheet::CXlsx &m_oXlsx, UINT m_nCodePage, const std::wstring& m_sDelimiter, bool m_bJSON): m_oXlsx(m_oXlsx), m_nCodePage(m_nCodePage), m_sDelimiter(m_sDelimiter), m_bJSON(m_bJSON)
|
||||
{
|
||||
m_pWriteBuffer = NULL;
|
||||
m_nCurrentIndex = 0;
|
||||
m_sEscape = _T("\"\n");
|
||||
m_sEscape += m_sDelimiter;
|
||||
m_nRowCurrent = 1;
|
||||
m_nColCurrent = 1;
|
||||
m_bIsWriteCell = false;
|
||||
bool m_bStartRow = true;
|
||||
bool m_bStartCell = true;
|
||||
}
|
||||
CCSVWriter::~CCSVWriter()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
void CCSVWriter::Start(const std::wstring &sFileDst)
|
||||
{
|
||||
m_oFile.CreateFileW(sFileDst);
|
||||
|
||||
// Теперь мы пишем как MS Excel (новую строку записываем в файл)
|
||||
if (!bJSON)
|
||||
// Нужно записать шапку
|
||||
if (46 == m_nCodePage)//todo 46 временно CP_UTF8
|
||||
{
|
||||
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage);
|
||||
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage, true);
|
||||
BYTE arUTF8[3] = {0xEF, 0xBB, 0xBF};
|
||||
m_oFile.WriteFile(arUTF8, 3);
|
||||
}
|
||||
RELEASEARRAYOBJECTS(pWriteBuffer);
|
||||
oFile.CloseFile();
|
||||
else if (48 == m_nCodePage)//todo 48 временно CP_UTF16
|
||||
{
|
||||
BYTE arUTF16[2] = {0xFF, 0xFE};
|
||||
m_oFile.WriteFile(arUTF16, 2);
|
||||
}
|
||||
else if (49 == m_nCodePage)//todo 49 временно CP_unicodeFFFE
|
||||
{
|
||||
BYTE arBigEndian[2] = {0xFE, 0xFF};
|
||||
m_oFile.WriteFile(arBigEndian, 2);
|
||||
}
|
||||
}
|
||||
void CCSVWriter::WriteSheetStart(OOX::Spreadsheet::CWorksheet* pWorksheet)
|
||||
{
|
||||
m_nRowCurrent = 1;
|
||||
if (m_bJSON)
|
||||
CSVWriter::WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sBkt, m_nCodePage);
|
||||
}
|
||||
void CCSVWriter::WriteRowStart(OOX::Spreadsheet::CRow *pRow)
|
||||
{
|
||||
INT nRow = pRow->m_oR.IsInit() ? pRow->m_oR->GetValue() : m_bStartRow ? m_nRowCurrent : m_nRowCurrent + 1;
|
||||
|
||||
if (m_bJSON)
|
||||
CSVWriter::WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, (m_bStartRow ? g_sBkt: g_sBktComma), m_nCodePage);
|
||||
else
|
||||
{
|
||||
while (nRow > m_nRowCurrent)
|
||||
{
|
||||
// Write new line
|
||||
++m_nRowCurrent;
|
||||
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sNewLineN, m_nCodePage);
|
||||
}
|
||||
}
|
||||
m_bStartRow = false;
|
||||
m_bStartCell = true;
|
||||
m_nColCurrent = 1;
|
||||
m_bIsWriteCell = false;
|
||||
}
|
||||
void CCSVWriter::WriteCell(OOX::Spreadsheet::CCell *pCell)
|
||||
{
|
||||
INT nRowTmp = 0;
|
||||
INT nCol = 0;
|
||||
|
||||
if (pCell->isInitRef())
|
||||
{
|
||||
pCell->getRowCol(nRowTmp, nCol);
|
||||
nRowTmp++;
|
||||
nCol++;
|
||||
}
|
||||
else
|
||||
{
|
||||
nCol = m_bStartCell ? m_nColCurrent : m_nColCurrent + 1;
|
||||
}
|
||||
|
||||
while (nCol > m_nColCurrent)
|
||||
{
|
||||
if (m_bJSON && false == m_bIsWriteCell)
|
||||
{
|
||||
// Запишем пустые строки (для JSON-а)
|
||||
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sDoubleQuote, m_nCodePage);
|
||||
}
|
||||
// Write delimiter
|
||||
++m_nColCurrent;
|
||||
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, m_sDelimiter, m_nCodePage);
|
||||
m_bIsWriteCell = false;
|
||||
}
|
||||
|
||||
// Get cell value
|
||||
std::wstring sCellValue = _T("");
|
||||
if (pCell->m_oValue.IsInit())
|
||||
{
|
||||
if (pCell->m_oType.IsInit() && SimpleTypes::Spreadsheet::celltypeNumber != pCell->m_oType->GetValue())
|
||||
{
|
||||
if(SimpleTypes::Spreadsheet::celltypeStr == pCell->m_oType->GetValue())
|
||||
{
|
||||
sCellValue = pCell->m_oValue->ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
int nValue = _wtoi(pCell->m_oValue->ToString().c_str());
|
||||
|
||||
if (nValue >= 0 && nValue < m_oXlsx.m_pSharedStrings->m_arrItems.size())
|
||||
{
|
||||
OOX::Spreadsheet::CSi *pSi = m_oXlsx.m_pSharedStrings->m_arrItems[nValue];
|
||||
if(NULL != pSi)
|
||||
{
|
||||
sCellValue = pSi->ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sCellValue = pCell->m_oValue->ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// Escape cell value
|
||||
if(m_bJSON)
|
||||
{
|
||||
NSStringUtils::CStringBuilder oBuilder;
|
||||
oBuilder.WriteString(_T("\""));
|
||||
escapeJson(sCellValue, oBuilder);
|
||||
oBuilder.WriteString(_T("\""));
|
||||
sCellValue = std::wstring(oBuilder.GetBuffer(), oBuilder.GetCurSize());
|
||||
}
|
||||
else if (std::wstring::npos != sCellValue.find_first_of(m_sEscape))
|
||||
{
|
||||
NSStringExt::Replace(sCellValue, g_sQuote, g_sDoubleQuote);
|
||||
sCellValue = g_sQuote + sCellValue + g_sQuote;
|
||||
}
|
||||
// Write cell value
|
||||
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, sCellValue, m_nCodePage);
|
||||
m_bIsWriteCell = true;
|
||||
m_bStartCell = false;
|
||||
}
|
||||
void CCSVWriter::WriteRowEnd(OOX::Spreadsheet::CRow* pWorksheet)
|
||||
{
|
||||
if (m_bJSON)
|
||||
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sEndJson, m_nCodePage);
|
||||
}
|
||||
void CCSVWriter::WriteSheetEnd(OOX::Spreadsheet::CWorksheet* pWorksheet)
|
||||
{
|
||||
if (m_bJSON)
|
||||
{
|
||||
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sEndJson, m_nCodePage);
|
||||
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sEndJson, m_nCodePage, true);
|
||||
}
|
||||
}
|
||||
void CCSVWriter::End()
|
||||
{
|
||||
// Теперь мы пишем как MS Excel (новую строку записываем в файл)
|
||||
if (!m_bJSON)
|
||||
{
|
||||
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sNewLineN, m_nCodePage);
|
||||
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sNewLineN, m_nCodePage, true);
|
||||
}
|
||||
Close();
|
||||
}
|
||||
void CCSVWriter::Close()
|
||||
{
|
||||
RELEASEARRAYOBJECTS(m_pWriteBuffer);
|
||||
m_oFile.CloseFile();
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,9 +35,45 @@
|
||||
#include "../../DesktopEditor/common/File.h"
|
||||
#include "../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h"
|
||||
|
||||
namespace OOX
|
||||
{
|
||||
namespace Spreadsheet
|
||||
{
|
||||
class CRow;
|
||||
class CCell;
|
||||
}
|
||||
}
|
||||
namespace CSVWriter
|
||||
{
|
||||
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, const std::wstring &sWriteString, UINT &nCodePage, bool bIsEnd = false);
|
||||
class CCSVWriter
|
||||
{
|
||||
protected:
|
||||
NSFile::CFileBinary m_oFile;
|
||||
OOX::Spreadsheet::CXlsx& m_oXlsx;
|
||||
UINT m_nCodePage;
|
||||
const std::wstring& m_sDelimiter;
|
||||
bool m_bJSON;
|
||||
|
||||
WCHAR* m_pWriteBuffer;
|
||||
INT m_nCurrentIndex;
|
||||
std::wstring m_sEscape;
|
||||
INT m_nRowCurrent;
|
||||
INT m_nColCurrent;
|
||||
bool m_bIsWriteCell; // Нужно только для записи JSON-а
|
||||
bool m_bStartRow;
|
||||
bool m_bStartCell;
|
||||
public:
|
||||
CCSVWriter(OOX::Spreadsheet::CXlsx &oXlsx, UINT m_nCodePage, const std::wstring& sDelimiter, bool m_bJSON);
|
||||
~CCSVWriter();
|
||||
void Start(const std::wstring &sFileDst);
|
||||
void WriteSheetStart(OOX::Spreadsheet::CWorksheet* pWorksheet);
|
||||
void WriteRowStart(OOX::Spreadsheet::CRow *pRow);
|
||||
void WriteCell(OOX::Spreadsheet::CCell *pCell);
|
||||
void WriteRowEnd(OOX::Spreadsheet::CRow* pWorksheet);
|
||||
void WriteSheetEnd(OOX::Spreadsheet::CWorksheet* pWorksheet);
|
||||
void End();
|
||||
void Close();
|
||||
};
|
||||
void WriteFromXlsxToCsv(const std::wstring &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& wcDelimiter, bool bJSON);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user