Compare commits

...

6 Commits

Author SHA1 Message Date
2682e1fbac Ooxml - fix vml image without image 2018-02-02 14:52:15 +03:00
f5c3ae779b . 2018-02-02 13:59:58 +03:00
068c60afa0 fix bug #36740 - extending error code
x2t version 2.4.515
2018-02-01 19:33:59 +03:00
5b8ca5b417 OdfFormatWriter - write columns table parts in formulas as ref 2018-02-01 18:55:57 +03:00
acfd12ea30 fix bug #36740 2018-02-01 16:42:34 +03:00
a04b83cada . 2018-02-01 12:28:46 +03:00
33 changed files with 621 additions and 475 deletions

View File

@ -416,7 +416,7 @@ namespace MathEquation
virtual void BeginEquation()
{
int nCurPos = WriteItemStart(BinDocxRW::c_oSerParType::OMath);
int nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::OMath);
m_aEquationStack.push(nCurPos);
}
virtual void EndEquation()
@ -618,7 +618,7 @@ namespace MathEquation
nRows = m_aRowsCounter.top();
m_aRowsCounter.pop();
}
int nPos = m_oStream.GetPosition();
int nPos = 0;
if (!m_aRowsPosCounter.empty())
{
nPos = m_aRowsPosCounter.top();

View File

@ -85,7 +85,7 @@ namespace BinXlsxRW{
sMediaPath = pathMediaDir.GetPath();
sEmbedPath = pathEmbedDir.GetPath();
}
bool CXlsxSerializer::loadFromFile(const std::wstring& sSrcFileName, const std::wstring& sDstPath, const std::wstring& sXMLOptions, const std::wstring& sMediaDir, const std::wstring& sEmbedDir)
int CXlsxSerializer::loadFromFile(const std::wstring& sSrcFileName, const std::wstring& sDstPath, const std::wstring& sXMLOptions, const std::wstring& sMediaDir, const std::wstring& sEmbedDir)
{
std::wstring strFileInDir = NSSystemPath::GetDirectoryName(sSrcFileName);
@ -97,11 +97,10 @@ namespace BinXlsxRW{
oDrawingConverter.SetMediaDstPath(sMediaDir);
oDrawingConverter.SetEmbedDstPath(sEmbedDir);
BinXlsxRW::BinaryFileReader oBinaryFileReader;
oBinaryFileReader.ReadFile(sSrcFileName, sDstPath, &oDrawingConverter, sXMLOptions);
return true;
BinXlsxRW::BinaryFileReader oBinaryFileReader;
return oBinaryFileReader.ReadFile(sSrcFileName, sDstPath, &oDrawingConverter, sXMLOptions);
}
bool CXlsxSerializer::saveToFile(const std::wstring& sDstFileName, const std::wstring& sSrcPath, const std::wstring& sXMLOptions)
int CXlsxSerializer::saveToFile(const std::wstring& sDstFileName, const std::wstring& sSrcPath, const std::wstring& sXMLOptions)
{
COfficeFontPicker* pFontPicker = new COfficeFontPicker();
pFontPicker->Init(m_sFontDir);
@ -137,10 +136,10 @@ namespace BinXlsxRW{
oOfficeDrawingConverter.SetFontPicker(pFontPicker);
BinXlsxRW::BinaryFileWriter oBinaryFileWriter(fp);
oBinaryFileWriter.Open(sSrcPath, sDstFileName, pEmbeddedFontsManager, &oOfficeDrawingConverter, sXMLOptions, m_bIsNoBase64);
int result = oBinaryFileWriter.Open(sSrcPath, sDstFileName, pEmbeddedFontsManager, &oOfficeDrawingConverter, sXMLOptions, m_bIsNoBase64);
RELEASEOBJECT(pFontPicker);
return true;
return result;
}
bool CXlsxSerializer::saveChart(NSBinPptxRW::CBinaryFileReader* pReader, long lLength, const std::wstring& sFilepath, const long& lChartNumber)
{

View File

@ -62,8 +62,8 @@ namespace BinXlsxRW {
static void CreateXlsxFolders (const std::wstring& sXmlOptions, const std::wstring& sDstPath, std::wstring& sMediaPath, std::wstring& sEmbedPath);
bool loadFromFile (const std::wstring& sSrcFileName, const std::wstring& sDstPath, const std::wstring& sXMLOptions, const std::wstring& sMediaDir, const std::wstring& sEmbedPath);
bool saveToFile (const std::wstring& sSrcFileName, const std::wstring& sDstPath, const std::wstring& sXMLOptions);
int loadFromFile (const std::wstring& sSrcFileName, const std::wstring& sDstPath, const std::wstring& sXMLOptions, const std::wstring& sMediaDir, const std::wstring& sEmbedPath);
int saveToFile (const std::wstring& sSrcFileName, const std::wstring& sDstPath, const std::wstring& sXMLOptions);
bool saveChart (NSBinPptxRW::CBinaryFileReader* pReader, long lLength, const std::wstring& sFilename, const long& lChartNumber);

View File

@ -1170,7 +1170,7 @@ void docx_conversion_context::docx_convert_delayed()
{
odf_reader::office_element * elm = delayed_elements_.front();
elm->docx_convert(*this);
delayed_elements_.pop_front();
delayed_elements_.erase(delayed_elements_.begin(), delayed_elements_.begin() + 1);
}
delayed_converting_=false;
}

View File

@ -763,7 +763,7 @@ private:
std::wstring automatic_parent_style_;
std::wstring current_master_page_name_;
std::wstring text_list_style_name_;
std::list<std::wstring> list_style_stack_;
std::vector<std::wstring> list_style_stack_;
bool first_element_list_item_;
bool page_break_after_;
@ -781,9 +781,9 @@ private:
int new_list_style_number_; // счетчик для нумерации имен созданных в процессе конвертации стилей
NoteType process_note_;
std::list<odf_reader::office_element *> delayed_elements_;
std::vector<odf_reader::office_element*> delayed_elements_;
std::list< const odf_reader::style_text_properties * > text_properties_stack_;
std::vector< const odf_reader::style_text_properties*> text_properties_stack_;
std::map<std::wstring, text_tracked_context::_state> map_current_changes_;
boost::unordered_map<std::wstring, std::wstring> list_style_renames_;// цепочки переименований нумераций
};

View File

@ -73,7 +73,7 @@ public:
private:
docx_conversion_context & context_;
std::wstring table_style_;
std::list<std::wstring> table_row_style_stack_;
std::vector<std::wstring> table_row_style_stack_;
std::wstring default_row_cell_style_name_;
int current_table_column_;
unsigned int columns_spanned_num_;
@ -188,7 +188,7 @@ public:
private:
docx_conversion_context & context_;
std::list<docx_table_state> table_states_;
std::vector<docx_table_state> table_states_;
};

View File

@ -82,7 +82,7 @@ private:
std::wstring table_style_;
std::list<std::wstring> table_row_style_stack_;
std::vector<std::wstring> table_row_style_stack_;
std::wstring default_row_cell_style_name_;
int current_table_column_;
@ -214,7 +214,7 @@ public:
private:
std::wstringstream output_stream_;
pptx_conversion_context & context_;
std::list<pptx_table_state> table_states_;
std::vector<pptx_table_state> table_states_;
};
void oox_serialize_tcPr(std::wostream & strm, std::vector<const odf_reader::style_instance *> & style_inst, oox::pptx_conversion_context & Context);

View File

@ -126,13 +126,13 @@ private:
std::wstring base_style_name_;
odf_types::style_family::type base_style_family_;//Presentation Or SpreadSheet
/////////////lists////////////
std::list<std::wstring> list_style_stack_;
//-------------------------------------------------------------------------------
std::vector<std::wstring> list_style_stack_;
bool first_element_list_item_;
// счетчик для нумерации имен созданных в процессе конвертации стилей
int new_list_style_number_;
// цепочки переименований нумераций
boost::unordered_map<std::wstring, std::wstring> list_style_renames_;
int new_list_style_number_; // счетчик для нумерации имен созданных в процессе конвертации стилей
boost::unordered_map<std::wstring, std::wstring> list_style_renames_; // цепочки переименований нумераций
void write_list_styles(std::wostream & strm);
//void write_list_properties(std::wostream & strm);

View File

@ -1624,9 +1624,9 @@ void odf_chart_context::set_cash(std::wstring format, std::vector<std::wstring>
ref1 = std::wstring(L"local-table.") + utils::getColAddress(start_col) + boost::lexical_cast<std::wstring>(start_row);
//
if (by_row)
ref2 = std::wstring(L"local-table.") + utils::getColAddress(start_col) + boost::lexical_cast<std::wstring>(start_row + count_cash_values);
ref2 = std::wstring(L"local-table.") + utils::getColAddress(start_col) + std::to_wstring(start_row + count_cash_values);
else
ref2 = std::wstring(L"local-table.") + utils::getColAddress(start_col + count_cash_values) + boost::lexical_cast<std::wstring>(start_row);
ref2 = std::wstring(L"local-table.") + utils::getColAddress(start_col + count_cash_values) + std::to_wstring(start_row);
ref = ref1 + L":" + ref2;
}

View File

@ -540,6 +540,7 @@ void odf_number_styles_context::create_date_style(number_format_state & state, o
boost::algorithm::to_lower(s);
boost::wregex re(L"([a-zA-Z]+)(\\W+)");//(L"(\\w+)");
std::list<std::wstring> result;
bool b = boost::regex_split(std::back_inserter(result),s, re);
result.push_back(s);//последний ..выносится - так уж работает boost.regex_split
@ -627,12 +628,12 @@ void odf_number_styles_context::create_time_style(number_format_state & state, o
int res;
int sz=0;
for (std::list<std::wstring>::iterator i=result.begin(); i!=result.end(); ++i)
for (std::list<std::wstring>::iterator it = result.begin(); it != result.end(); ++it)
{
office_element_ptr elm;
s = *i;
s = *it;
sz = s.length();
if ((res=s.find(L"h")) >=0)
if ((res=s.find(L"h")) >= 0)
{
create_element(L"number", L"hours", elm, odf_context_);
number_hours* number_hours_ = dynamic_cast<number_hours*>(elm.get());

View File

@ -31,7 +31,7 @@
*/
#pragma once
#include <list>
#include <vector>
#include "odp_page_state.h"
#include "odf_table_context.h"
@ -83,7 +83,7 @@ private:
odf_table_context table_context_;
odf_comment_context comment_context_;
std::list<odp_page_state> page_state_list_;
std::vector<odp_page_state> page_state_list_;
int count_slides_;
friend class odp_conversion_context;

View File

@ -115,6 +115,10 @@ void ods_conversion_context::set_table_part_autofilter(bool val)
{
table_context_.set_table_part_autofilter(val);
}
void ods_conversion_context::add_table_part_column(std::wstring name)
{
table_context_.add_table_part_column(name);
}
void ods_conversion_context::end_table_part()
{
table_context_.end_table_part();

View File

@ -110,6 +110,7 @@ public:
void start_table_part (std::wstring name, std::wstring ref);
void end_table_part ();
void set_table_part_autofilter(bool val);
void add_table_part_column(std::wstring name);
void start_conditional_formats();
void end_conditional_formats(){}

View File

@ -78,8 +78,36 @@ void ods_table_context::start_table_part(std::wstring name, std::wstring ref)
table_database_ranges_.root->add_child_element(elm);
table_database_ranges_.elements.push_back(elm);
table_part_state part_state;
part_state.name = name;
part_state.ref = ref;
int r = ref.rfind(L":");
if (r < 0) return;//тута однозначно .. по правилам оох
utils::parsing_ref (ref.substr(0, r), part_state.col_start, part_state.row_start);
utils::parsing_ref (ref.substr(r + 1, ref.size() - r), part_state.col_end, part_state.row_end);
state().table_parts_.push_back(part_state);
}
void ods_table_context::add_table_part_column(std::wstring name)
{
if (state().table_parts_.empty()) return;
size_t column = state().table_parts_.back().columns.size();
std::wstring sCol = utils::getColAddress(state().table_parts_.back().col_start + column - 1);
std::wstring ref;//table name ????
ref += sCol + std::to_wstring(state().table_parts_.back().row_start);
ref += L":";
ref += sCol + std::to_wstring(state().table_parts_.back().row_end);
state().table_parts_.back().columns.push_back(std::make_pair(name, ref));
}
void ods_table_context::set_table_part_autofilter(bool val)
{
if (!val) return;
@ -152,15 +180,13 @@ void ods_table_context::add_defined_range(const std::wstring & name, const std::
if (sheet_id >=0)
{
int i=0;
for (std::list<ods_table_state>::iterator iter = table_state_list_.begin(); iter != table_state_list_.end(); iter++)
for (size_t i = 0; i < table_state_list_.size(); ++i)
{
if (i == sheet_id)
{
iter->add_definded_expression(elm);
table_state_list_[i].add_definded_expression(elm);
break;
}
i++;
}
}
else
@ -187,31 +213,23 @@ void ods_table_context::add_defined_expression(const std::wstring & name, const
named_expression->table_name_ = name;
named_expression->table_expression_ = odf_value;
if (sheet_id >=0)
if (sheet_id >=0 && sheet_id < table_state_list_.size())
{
int i=0;
for (std::list<ods_table_state>::iterator iter = table_state_list_.begin(); iter != table_state_list_.end(); iter++)
odf_base_cell = table_state_list_[sheet_id].office_table_name_ + L".$A$1";
table_state_list_[sheet_id].add_definded_expression(elm);
if ( printable)
{
if (i == sheet_id)
{
odf_base_cell = iter->office_table_name_ + L".$A$1";
iter->add_definded_expression(elm);
if ( printable)
{
XmlUtils::replace_all( odf_value, L"[", L"");
XmlUtils::replace_all( odf_value, L"]", L"");
XmlUtils::replace_all( odf_value, L";", L" ");
XmlUtils::replace_all( odf_value, L"[", L"");
XmlUtils::replace_all( odf_value, L"]", L"");
XmlUtils::replace_all( odf_value, L";", L" ");
iter->set_print_range(odf_value);
}
break;
}
i++;
table_state_list_[sheet_id].set_print_range(odf_value);
}
}
else
{
if (!table_defined_expressions_.root)create_element(L"table", L"named-expressions",table_defined_expressions_.root,&context_);
if (!table_defined_expressions_.root)create_element(L"table", L"named-expressions", table_defined_expressions_.root,&context_);
table_defined_expressions_.root->add_child_element(elm);
}

View File

@ -52,8 +52,6 @@ struct table_additional_elements_state
std::vector<office_element_ptr> elements;
};
/// \class ods_table_context
class ods_table_context
{
public:
@ -76,13 +74,14 @@ public:
void start_table_part(std::wstring name, std::wstring ref);
void set_table_part_autofilter(bool val);
void add_table_part_column(std::wstring name);
void end_table_part();
private:
ods_conversion_context & context_;
std::list<ods_table_state> table_state_list_;
std::vector<ods_table_state> table_state_list_;
table_additional_elements_state table_defined_expressions_;
table_additional_elements_state table_database_ranges_;

View File

@ -634,15 +634,15 @@ void ods_table_state::set_merge_cells(int start_col, int start_row, int end_col,
if (spanned_cols > 10000)spanned_cols = 1024;
for (std::list<ods_cell_state>::iterator cell = cells_.begin(); cell != cells_.end(); cell++)
for (size_t i = 0; i < cells_.size(); ++i)
{
if (cell->row > end_row) break;
if (cells_[i].row > end_row) break;
if (cell->row >= start_row)
if (cells_[i].row >= start_row)
{
if (cell->col >= start_col)
if (cells_[i].col >= start_col)
{
table_table_cell* cell_elm = dynamic_cast<table_table_cell*>(cell->elm.get());
table_table_cell* cell_elm = dynamic_cast<table_table_cell*>(cells_[i].elm.get());
if (cell_elm == NULL)return;
cell_elm->table_table_cell_attlist_extra_.table_number_columns_spanned_ = spanned_cols;
@ -668,6 +668,24 @@ void ods_table_state::set_cell_formula(std::wstring & formula)
}
std::wstring odfFormula = formulas_converter_table.convert_formula(formula);
if (std::wstring::npos != odfFormula.find(L"["))
{
for (size_t i = 0; i < table_parts_.size(); i++)
{
if (table_parts_[i].in_ref(current_table_column_, current_table_row_))
{
for (size_t j = 0; j < table_parts_[i].columns.size(); j ++)
{
std::wstring name = table_parts_[i].name + L"[" + table_parts_[i].columns[j].first + L"]";
//Таблица1[ Сумма за кв. 3 ]
XmlUtils::replace_all(odfFormula, name, table_parts_[i].columns[j].second);
}
break;
}
}
}
table_table_cell* cell = dynamic_cast<table_table_cell*>(cells_.back().elm.get());
if (cell == NULL)return;
@ -684,7 +702,7 @@ std::wstring ods_table_state::replace_cell_row(boost::wsmatch const & what)
int col_formula=0, row_formula=0;
utils::parsing_ref(ref_formula, col_formula, row_formula);col_formula--;//инче отсчет с 1
ref_formula = utils::getColAddress(col_formula)+boost::lexical_cast<std::wstring>(row_formula+current_table_row_ -tmp_row_);
ref_formula = utils::getColAddress(col_formula) + std::to_wstring(row_formula +current_table_row_ - tmp_row_);
return ref_formula;

View File

@ -69,7 +69,8 @@ class odf_text_context;
class table_table;
class style;
namespace utils {
namespace utils
{
static std::wstring getColAddress(size_t col)
{
static const size_t r = (L'Z' - L'A' + 1);
@ -78,8 +79,8 @@ namespace utils {
if (r0 > 0)
{
const std::wstring rest = getColAddress(col - r*r0);
const std::wstring res = getColAddress(r0-1) + rest;
const std::wstring rest = getColAddress(col - r * r0);
const std::wstring res = getColAddress(r0 - 1) + rest;
return res;
}
else
@ -210,6 +211,24 @@ struct ods_shared_formula_state
int moving_type; //1 - col, 2 - row
};
struct table_part_state
{
std::wstring name;
std::wstring ref;
int col_start = 0;
int row_start = 0;
int col_end = 0;
int row_end = 0;
bool in_ref(int col, int row)
{
return (col >= col_start && col <= col_end && row >= row_start && row <= row_end);
}
std::vector<std::pair<std::wstring, std::wstring>> columns; //name, odf_ref
};
struct ods_array_formula_state
{
std::wstring formula;
@ -341,12 +360,14 @@ private:
std::vector<office_element_ptr> current_level_;//постоянно меняющийся список уровней ("0-й элемент - сама таблица)
std::list<ods_cell_state> cells_;
std::vector<ods_cell_state> cells_;
long cells_size_;
std::vector<ods_hyperlink_state> hyperlinks_;
std::vector<ods_shared_formula_state> shared_formulas_;
std::vector<table_part_state> table_parts_;
odf_drawing_context drawing_context_;
friend class ods_table_context;

View File

@ -268,6 +268,30 @@ void XlsxConverter::convert(OOX::Spreadsheet::CWorksheet *oox_sheet)
pos++;
}
//todooo для оптимизации - перенести мержи в начало
//выносные части таблицы
if (oox_sheet->m_oTableParts.IsInit())
{
for (size_t i=0 ; i < oox_sheet->m_oTableParts->m_arrItems.size(); i++)
{
OOX::Spreadsheet::CTablePart *oox_table_part = oox_sheet->m_oTableParts->m_arrItems[i];
if (!oox_table_part)continue;
if (!oox_table_part->m_oRId.IsInit())continue;
smart_ptr<OOX::File> oFile = oox_sheet->Find(oox_table_part->m_oRId->GetValue());
if (oFile.IsInit() && OOX::Spreadsheet::FileTypes::Table == oFile->type())
{
OOX::Spreadsheet::CTableFile* pTableFile = (OOX::Spreadsheet::CTableFile*)oFile.operator->();
if ((pTableFile) && (pTableFile->m_oTable.IsInit()))
{
oox_current_child_document = dynamic_cast<OOX::IFileContainer*>(pTableFile);
convert(pTableFile->m_oTable.GetPointer());
oox_current_child_document = NULL;
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//колонки
ods_context->start_columns();
@ -328,29 +352,7 @@ void XlsxConverter::convert(OOX::Spreadsheet::CWorksheet *oox_sheet)
}
ods_context->end_conditional_formats();
}
//выносные части таблицы
if (oox_sheet->m_oTableParts.IsInit())
{
for (size_t i=0 ; i < oox_sheet->m_oTableParts->m_arrItems.size(); i++)
{
OOX::Spreadsheet::CTablePart *oox_table_part = oox_sheet->m_oTableParts->m_arrItems[i];
if (!oox_table_part)continue;
if (!oox_table_part->m_oRId.IsInit())continue;
smart_ptr<OOX::File> oFile = oox_sheet->Find(oox_table_part->m_oRId->GetValue());
if (oFile.IsInit() && OOX::Spreadsheet::FileTypes::Table == oFile->type())
{
OOX::Spreadsheet::CTableFile* pTableFile = (OOX::Spreadsheet::CTableFile*)oFile.operator->();
if ((pTableFile) && (pTableFile->m_oTable.IsInit()))
{
oox_current_child_document = dynamic_cast<OOX::IFileContainer*>(pTableFile);
convert(pTableFile->m_oTable.GetPointer());
oox_current_child_document = NULL;
}
}
}
}
/////////////////////////////////////////////////////////////////////////
convert(oox_sheet->m_oSheetViews.GetPointer());
convert(oox_sheet->m_oHeaderFooter.GetPointer());
@ -418,11 +420,27 @@ void XlsxConverter::convert(OOX::Spreadsheet::CTable *oox_table_part)
if (oox_table_part->m_oAutoFilter.IsInit())
ods_context->set_table_part_autofilter(true);
convert(oox_table_part->m_oTableColumns.GetPointer());
OoxConverter::convert(oox_table_part->m_oExtLst.GetPointer());
ods_context->end_table_part();
}
void XlsxConverter::convert(OOX::Spreadsheet::CTableColumns *oox_table_part_columns)
{
if (!oox_table_part_columns) return;
for (size_t i = 0; i < oox_table_part_columns->m_arrItems.size(); i++)
{
std::wstring name;
if (oox_table_part_columns->m_arrItems[i]->m_oName.IsInit())
name = oox_table_part_columns->m_arrItems[i]->m_oName.get2();
ods_context->add_table_part_column(name);
}
}
void XlsxConverter::convert(OOX::Spreadsheet::CCommentItem * oox_comment)
{
if (!oox_comment) return;

View File

@ -48,6 +48,7 @@ namespace OOX
class CWorksheet;
class CTable;
class CTableColumns;
class CCol;
class CRow;
class CCell;
@ -157,6 +158,7 @@ namespace Oox2Odf
void convert(OOX::Spreadsheet::CWorksheet *oox_sheet);
void convert(OOX::Spreadsheet::CDefinedName *oox_defined);
void convert(OOX::Spreadsheet::CTable *oox_table_part);
void convert(OOX::Spreadsheet::CTableColumns *oox_table_part_columns);
void convert(OOX::Spreadsheet::CPictureWorksheet *oox_background);
void convert(OOX::Spreadsheet::CHeaderFooter *oox_header_footer);

View File

@ -187,12 +187,12 @@ void NSPresentationEditor::CPPTXWriter::WriteContentTypes()
{
std::wstring strContentTypes = L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\
<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">\
<Default Extension=\"bmp\" ContentType=\"image/bmp\" />\
<Default Extension=\"png\" ContentType=\"image/png\" />\
<Default Extension=\"jpeg\" ContentType=\"image/jpeg\" />\
<Default Extension=\"wmf\" ContentType=\"image/x-wmf\" />\
<Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\" />\
<Default Extension=\"xml\" ContentType=\"application/xml\" />\
<Default Extension=\"bmp\" ContentType=\"image/bmp\"/>\
<Default Extension=\"png\" ContentType=\"image/png\"/>\
<Default Extension=\"jpeg\" ContentType=\"image/jpeg\"/>\
<Default Extension=\"wmf\" ContentType=\"image/x-wmf\"/>\
<Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\"/>\
<Default Extension=\"xml\" ContentType=\"application/xml\"/>\
<Default Extension=\"gif\" ContentType=\"image/gif\"/>\
<Default Extension=\"emf\" ContentType=\"image/x-emf\"/>\
<Default Extension=\"wav\" ContentType=\"audio/wav\"/>\
@ -207,7 +207,7 @@ void NSPresentationEditor::CPPTXWriter::WriteContentTypes()
<Default Extension=\"xls\" ContentType=\"application/vnd.ms-excel\"/>\
<Default Extension=\"xlsx\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\"/>\
<Default Extension=\"bin\" ContentType=\"application/vnd.openxmlformats-officedocument.oleObject\" />\
<Default Extension=\"jpg\" ContentType=\"application/octet-stream\"/>";
<Default Extension=\"jpg\" ContentType=\"image/jpeg\"/>";
if (m_pDocument->m_bMacros)
{

View File

@ -3986,8 +3986,19 @@ void CDrawingConverter::CheckBrushShape(PPTX::Logic::SpTreeElem* oElem, XmlUtils
nullable_string sRid;
oNodeFill.ReadAttributeBase(L"r:id", sRid);
if (sRid.is_init())
{
PPTX::Logic::BlipFill* pBlipFill = new PPTX::Logic::BlipFill();
{
PPTX::Logic::BlipFill* pBlipFill = NULL;
if (pPicture)
{
pBlipFill = &pPicture->blipFill;
}
else
{
pBlipFill = new PPTX::Logic::BlipFill();
pSpPr->Fill.m_type = PPTX::Logic::UniFill::blipFill;
pSpPr->Fill.Fill = pBlipFill;
}
pBlipFill->m_namespace = L"a";
pBlipFill->blip = new PPTX::Logic::Blip();
pBlipFill->blip->embed = new OOX::RId(*sRid);
@ -4000,9 +4011,6 @@ void CDrawingConverter::CheckBrushShape(PPTX::Logic::SpTreeElem* oElem, XmlUtils
{
pBlipFill->stretch = new PPTX::Logic::Stretch();
}
pSpPr->Fill.m_type = PPTX::Logic::UniFill::blipFill;
pSpPr->Fill.Fill = pBlipFill;
}
nullable_string sRotate;
oNodeFill.ReadAttributeBase(L"rotate", sRotate);
@ -4129,7 +4137,19 @@ void CDrawingConverter::CheckBrushShape(PPTX::Logic::SpTreeElem* oElem, XmlUtils
nullable_string sType;
oNodeFillID.ReadAttributeBase(L"type", sType);
PPTX::Logic::BlipFill* pBlipFill = new PPTX::Logic::BlipFill();
PPTX::Logic::BlipFill* pBlipFill = NULL;
if (pPicture)
{
pBlipFill = &pPicture->blipFill;
}
else
{
pBlipFill = new PPTX::Logic::BlipFill();
pSpPr->Fill.m_type = PPTX::Logic::UniFill::blipFill;
pSpPr->Fill.Fill = pBlipFill;
}
pBlipFill->m_namespace = L"a";
pBlipFill->blip = new PPTX::Logic::Blip();
@ -4181,51 +4201,50 @@ void CDrawingConverter::CheckBrushShape(PPTX::Logic::SpTreeElem* oElem, XmlUtils
else
pBlipFill->srcRect->b = str0;
}
if (pShape)
{
pSpPr->Fill.m_type = PPTX::Logic::UniFill::blipFill;
pSpPr->Fill.Fill = pBlipFill;
}
if (pPicture)
{
pSpPr->Fill.m_type = PPTX::Logic::UniFill::notInit;
pPicture->blipFill = *pBlipFill;
}
}
}
}
// default params
if (!pSpPr->Fill.Fill.is_init())
if (pPicture)
{
if (pPPTShape->IsWordArt())
{
PPTX::Logic::NoFill* pNoFill = new PPTX::Logic::NoFill();
pNoFill->m_namespace = L"a";
pSpPr->Fill.m_type = PPTX::Logic::UniFill::notInit;
pSpPr->Fill.m_type = PPTX::Logic::UniFill::noFill;
pSpPr->Fill.Fill = pNoFill;
if (false == pPicture->blipFill.blip.is_init())
{//MSF_Lec3-4.docx
oElem->InitElem(NULL);
}
else
}
else
{
// default params for fill shape
if (!pSpPr->Fill.Fill.is_init())
{
PPTX::Logic::SolidFill* pSolid = new PPTX::Logic::SolidFill();
pSolid->m_namespace = L"a";
pSolid->Color.Color = new PPTX::Logic::SrgbClr();
pSolid->Color.Color->SetRGB(0xFF, 0xFF, 0xFF);
pSpPr->Fill.m_type = PPTX::Logic::UniFill::solidFill;
pSpPr->Fill.Fill = pSolid;
if (sOpacity.is_init())
if (pPPTShape->IsWordArt())
{
BYTE lAlpha = NS_DWC_Common::getOpacityFromString(*sOpacity);
PPTX::Logic::ColorModifier oMod;
oMod.name = L"alpha";
int nA = (int)(lAlpha * 100000.0 / 255.0);
oMod.val = nA;
pSolid->Color.Color->Modifiers.push_back(oMod);
PPTX::Logic::NoFill* pNoFill = new PPTX::Logic::NoFill();
pNoFill->m_namespace = L"a";
pSpPr->Fill.m_type = PPTX::Logic::UniFill::noFill;
pSpPr->Fill.Fill = pNoFill;
}
else
{
PPTX::Logic::SolidFill* pSolid = new PPTX::Logic::SolidFill();
pSolid->m_namespace = L"a";
pSolid->Color.Color = new PPTX::Logic::SrgbClr();
pSolid->Color.Color->SetRGB(0xFF, 0xFF, 0xFF);
pSpPr->Fill.m_type = PPTX::Logic::UniFill::solidFill;
pSpPr->Fill.Fill = pSolid;
if (sOpacity.is_init())
{
BYTE lAlpha = NS_DWC_Common::getOpacityFromString(*sOpacity);
PPTX::Logic::ColorModifier oMod;
oMod.name = L"alpha";
int nA = (int)(lAlpha * 100000.0 / 255.0);
oMod.val = nA;
pSolid->Color.Color->Modifiers.push_back(oMod);
}
}
}
}

View File

@ -335,6 +335,17 @@ namespace PPTX
std::wstring strOlePath = pReader->GetString(_embed_data_size);
m_OleObjectFile->set_filename(strOlePath, false); //temp !!! for ImageManager original file name
}
else if (embedded_type == 4)
{
pReader->Seek(pReader->GetPos() - 4); //roll back to size record
std::wstring sXmlContent;
pReader->m_pMainDocument->getXmlContentElem(OOX::et_m_oMathPara, *pReader, sXmlContent);
if (!sXmlContent.empty())
{
m_sAlternateContenteXml = sXmlContent;
}
}
else if (embedded_type == 1)
{
m_OleObjectFile = new OOX::OleObject(NULL, true, pReader->m_nDocumentType == XMLWRITER_DOC_TYPE_DOCX);

View File

@ -221,6 +221,8 @@ namespace PPTX
nullable_int m_oDxaOrig;
nullable_int m_oDyaOrig;
nullable_string m_sAlternateContenteXml;
};
class Pic : public WrapperWritingElement

View File

@ -78,11 +78,10 @@ namespace Txt2Docx
void Converter::write(/*const std::wstring& path*/XmlUtils::CStringWriter & stringWriter)
{
for (std::vector<OOX::WritingElement*>::iterator it = converter_->m_outputFile.m_arrItems.begin();
it != converter_->m_outputFile.m_arrItems.end(); ++it)
for (size_t i = 0; i < converter_->m_outputFile.m_arrItems.size(); ++i)
{
if ( *it )
stringWriter.WriteString((*it)->toXML());
if ( converter_->m_outputFile.m_arrItems[i] )
stringWriter.WriteString(converter_->m_outputFile.m_arrItems[i]->toXML());
}
//BOOL res = converter_->m_outputFile.Write(std_string2string(path.string()));
return;
@ -119,8 +118,10 @@ namespace Txt2Docx
font.m_sHAnsi.Init(); *font.m_sHAnsi = L"Courier New";
font.m_sCs.Init(); *font.m_sCs = L"Courier New";
for (std::vector<std::wstring>::iterator line = m_inputFile.m_listContent.begin(); line != m_inputFile.m_listContent.end(); line++)
for (size_t i = 0; i < m_inputFile.m_listContent.size(); ++i)
{
std::wstring & line = m_inputFile.m_listContent[i];
OOX::Logic::CParagraph *paragraph = new OOX::Logic::CParagraph();
OOX::Logic::CParagraphProperty *pPr = new OOX::Logic::CParagraphProperty();
OOX::Logic::CRunProperty *rPr = new OOX::Logic::CRunProperty();
@ -132,17 +133,17 @@ namespace Txt2Docx
paragraph->m_arrItems.push_back(pPr);
paragraph->m_oParagraphProperty = pPr; //копия для удобства
while(line->find(_T("\x08")) != line->npos)
while(line.find(_T("\x08")) != line.npos)
{
line->erase(line->find(_T("\x08")), 1);//, "");
line.erase(line.find(_T("\x08")), 1);//, "");
}
while(line->find(_T("\x09")) != line->npos)
while(line.find(_T("\x09")) != line.npos)
{
int pos = line->find(_T("\x09"));
int pos = line.find(_T("\x09"));
if (pos > 0)
{
std::wstring s = line->substr(0, pos - 1);
std::wstring s = line.substr(0, pos - 1);
if (!s.empty())
{
OOX::Logic::CRunProperty *rPr_ = new OOX::Logic::CRunProperty();
@ -152,12 +153,12 @@ namespace Txt2Docx
}
}
paragraph->AddTab();
line->erase(0, pos + 1);
line.erase(0, pos + 1);
}
if (!line->empty())
if (!line.empty())
{
std::wstring s_ = XmlUtils::EncodeXmlString(*line);
std::wstring s_ = XmlUtils::EncodeXmlString(line);
paragraph->AddText(s_, rPr);
}
pDocument->m_arrItems.push_back(paragraph);

View File

@ -150,7 +150,6 @@ namespace OOX
private:
void ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
{
// Читаем атрибуты
WritingElement_ReadAttributes_Start( oReader )
WritingElement_ReadAttributes_Read_if ( oReader, _T("name"), m_oName )
@ -159,7 +158,7 @@ namespace OOX
WritingElement_ReadAttributes_Read_if ( oReader, _T("showLastColumn"), m_oShowLastColumn )
WritingElement_ReadAttributes_Read_if ( oReader, _T("showRowStripes"), m_oShowRowStripes )
WritingElement_ReadAttributes_End( oReader )
WritingElement_ReadAttributes_End( oReader )
}
public:
nullable<std::wstring > m_oName;
@ -242,16 +241,15 @@ namespace OOX
private:
void ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
{
// Читаем атрибуты
WritingElement_ReadAttributes_Start( oReader )
WritingElement_ReadAttributes_Read_if ( oReader, _T("id"), m_oId )
WritingElement_ReadAttributes_Read_if ( oReader, _T("name"), m_oName )
WritingElement_ReadAttributes_Read_if ( oReader, _T("totalsRowLabel"), m_oTotalsRowLabel )
WritingElement_ReadAttributes_Read_if ( oReader, _T("totalsRowFunction"), m_oTotalsRowFunction )
WritingElement_ReadAttributes_Read_if ( oReader, _T("dataDxfId"), m_oDataDxfId )
WritingElement_ReadAttributes_Read_if ( oReader, _T("id"), m_oId )
WritingElement_ReadAttributes_Read_if ( oReader, _T("name"), m_oName )
WritingElement_ReadAttributes_Read_if ( oReader, _T("totalsRowLabel"), m_oTotalsRowLabel )
WritingElement_ReadAttributes_Read_if ( oReader, _T("totalsRowFunction"),m_oTotalsRowFunction )
WritingElement_ReadAttributes_Read_if ( oReader, _T("dataDxfId"), m_oDataDxfId )
WritingElement_ReadAttributes_End( oReader )
WritingElement_ReadAttributes_End( oReader )
}
public:
nullable<SimpleTypes::CUnsignedDecimalNumber<> > m_oId;

View File

@ -240,3 +240,4 @@
#define AVS_FILEUTILS_ERROR_CONVERT_NEED_PARAMS (AVS_ERROR_FIRST + AVS_FILEUTILS_ERROR_FIRST + 0x0059)
#define AVS_FILEUTILS_ERROR_CONVERT_DRM (AVS_ERROR_FIRST + AVS_FILEUTILS_ERROR_FIRST + 0x005a)
#define AVS_FILEUTILS_ERROR_CONVERT_PASSWORD (AVS_ERROR_FIRST + AVS_FILEUTILS_ERROR_FIRST + 0x005b)
#define AVS_FILEUTILS_ERROR_CONVERT_ICU (AVS_ERROR_FIRST + AVS_FILEUTILS_ERROR_FIRST + 0x005c)

View File

@ -1,4 +1,4 @@
VERSION = 2.4.514.0
VERSION = 2.4.515.0
DEFINES += INTVER=$$VERSION
# CONFIGURATION

View File

@ -509,7 +509,7 @@ namespace NExtractTools
m_oCXlsxSerializer.setIsNoBase64(params.getIsNoBase64());
m_oCXlsxSerializer.setFontDir(params.getFontPath());
return m_oCXlsxSerializer.saveToFile (sTo, sXlsxDir, bXmlOptions ? params.getXmlOptions() : L"") ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
return m_oCXlsxSerializer.saveToFile (sTo, sXlsxDir, bXmlOptions ? params.getXmlOptions() : L"");
}
// xslx -> xslt
@ -572,7 +572,7 @@ namespace NExtractTools
if(SUCCEEDED_X2T(nRes))
{
nRes = m_oCXlsxSerializer.loadFromFile (sTargetBin, sTo, sXmlOptions, sMediaPath, sEmbedPath) ? nRes : AVS_FILEUTILS_ERROR_CONVERT;
nRes = m_oCXlsxSerializer.loadFromFile (sTargetBin, sTo, sXmlOptions, sMediaPath, sEmbedPath);
}
//удаляем EditorWithChanges, потому что он не в Temp
if (sFrom != sTargetBin)
@ -970,7 +970,8 @@ namespace NExtractTools
m_oCXlsxSerializer.setIsNoBase64(params.getIsNoBase64());
m_oCXlsxSerializer.setFontDir(params.getFontPath());
int nRes = m_oCXlsxSerializer.saveToFile (sResultXlstFileEditor, sCSV, params.getXmlOptions()) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
int nRes = m_oCXlsxSerializer.saveToFile (sResultXlstFileEditor, sCSV, params.getXmlOptions());
if (SUCCEEDED_X2T(nRes))
{
nRes = (S_OK == oCOfficeUtils.CompressFileOrDirectory(sResultXlstDir, sTo)) ? nRes : AVS_FILEUTILS_ERROR_CONVERT;
@ -1001,10 +1002,10 @@ namespace NExtractTools
std::wstring sMediaPath;
std::wstring sEmbedPath;
int nRes = m_oCXlsxSerializer.saveToFile (sResultXlstFileEditor, sCSV, params.getXmlOptions()) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
int nRes = m_oCXlsxSerializer.saveToFile (sResultXlstFileEditor, sCSV, params.getXmlOptions());
if (SUCCEEDED_X2T(nRes))
{
nRes = m_oCXlsxSerializer.loadFromFile(sResultXlstFileEditor, sTempUnpackedXLSX, params.getXmlOptions(), sMediaPath, sEmbedPath) ? nRes : AVS_FILEUTILS_ERROR_CONVERT;
nRes = m_oCXlsxSerializer.loadFromFile(sResultXlstFileEditor, sTempUnpackedXLSX, params.getXmlOptions(), sMediaPath, sEmbedPath);
if (SUCCEEDED_X2T(nRes))
{
nRes = (S_OK == oCOfficeUtils.CompressFileOrDirectory(sTempUnpackedXLSX, sTo, true)) ? nRes : AVS_FILEUTILS_ERROR_CONVERT;
@ -1021,7 +1022,7 @@ namespace NExtractTools
m_oCXlsxSerializer.setIsNoBase64(params.getIsNoBase64());
m_oCXlsxSerializer.setFontDir(params.getFontPath());
return m_oCXlsxSerializer.saveToFile(sTo, sFrom, params.getXmlOptions()) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
return m_oCXlsxSerializer.saveToFile(sTo, sFrom, params.getXmlOptions());
}
// xlst -> csv
int xlst2csv (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
@ -1046,7 +1047,7 @@ namespace NExtractTools
std::wstring sMediaPath;
std::wstring sEmbedPath;
return m_oCXlsxSerializer.loadFromFile (sTempXlstFileEditor, sCSV, params.getXmlOptions(), sMediaPath, sEmbedPath) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
return m_oCXlsxSerializer.loadFromFile (sTempXlstFileEditor, sCSV, params.getXmlOptions(), sMediaPath, sEmbedPath);
}
// xslx -> csv
int xlsx2csv (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
@ -1070,13 +1071,13 @@ namespace NExtractTools
m_oCXlsxSerializer.setFontDir(params.getFontPath());
std::wstring sXMLOptions = _T("");
int nRes = m_oCXlsxSerializer.saveToFile (sResultXlstFileEditor, sTempUnpackedXLSX, sXMLOptions) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
int nRes = m_oCXlsxSerializer.saveToFile (sResultXlstFileEditor, sTempUnpackedXLSX, sXMLOptions);
if (SUCCEEDED_X2T(nRes))
{
std::wstring sMediaPath;
std::wstring sEmbedPath;
nRes = m_oCXlsxSerializer.loadFromFile (sResultXlstDir, sCSV, sXMLOptions, sMediaPath, sEmbedPath) ? nRes : AVS_FILEUTILS_ERROR_CONVERT;
nRes = m_oCXlsxSerializer.loadFromFile (sResultXlstDir, sCSV, sXMLOptions, sMediaPath, sEmbedPath);
}
return nRes;
@ -1107,7 +1108,7 @@ namespace NExtractTools
m_oCXlsxSerializer.CreateXlsxFolders (sXmlOptions, sTemp, sMediaPath, sEmbedPath);
nRes = m_oCXlsxSerializer.loadFromFile(sTargetBin, sToTemp, sXmlOptions, sMediaPath, sEmbedPath) ? nRes : AVS_FILEUTILS_ERROR_CONVERT;
nRes = m_oCXlsxSerializer.loadFromFile(sTargetBin, sToTemp, sXmlOptions, sMediaPath, sEmbedPath);
//пишем в Temp и копируем, чтобы не возникало лишних файлов рядом с sTo, а лучше перейти на отдельный метод
if(SUCCEEDED_X2T(nRes))
@ -3746,10 +3747,7 @@ namespace NExtractTools
m_oCXlsxSerializer.setFontDir(params.getFontPath());
int res = m_oCXlsxSerializer.saveToFile (sTo, sResultXlsxDir, params.getXmlOptions()) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
return res;
return m_oCXlsxSerializer.saveToFile (sTo, sResultXlsxDir, params.getXmlOptions());
}
return AVS_FILEUTILS_ERROR_CONVERT;
}

View File

@ -637,7 +637,7 @@ namespace NExtractTools
{
std::wstring sRes;
int nCsvEncoding = 46;//65001 utf8
std::wstring cDelimiter = L"";
std::wstring cDelimiter = L",";
if(NULL != m_nCsvTxtEncoding)
nCsvEncoding = *m_nCsvTxtEncoding;

View File

@ -44,6 +44,7 @@
#include "../../Common/OfficeFileFormats.h"
#include "../../Common/Base64.h"
#include "../../Common/OfficeFileErrorDescription.h"
#include "../../ASCOfficeDocxFile2/DocWrapper/FontProcessor.h"
#include "../../ASCOfficePPTXFile/Editor/FontCutter.h"
@ -64,7 +65,6 @@ namespace BinXlsxRW
BinaryTableWriter(NSBinPptxRW::CBinaryFileWriter &oCBufferedStream):m_oBcw(oCBufferedStream)
{
}
public:
void Write(const OOX::Spreadsheet::CWorksheet& oWorksheet, const OOX::Spreadsheet::CTableParts& oTableParts)
{
int nCurPos = 0;
@ -4322,9 +4322,11 @@ namespace BinXlsxRW
{
RELEASEOBJECT(m_oBcw);
}
void Open(const std::wstring& sInputDir, const std::wstring& sFileDst, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager,
int Open(const std::wstring& sInputDir, const std::wstring& sFileDst, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager,
NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter, const std::wstring& sXMLOptions, bool bIsNoBase64)
{
int result = 0;
OOX::CPath path(sFileDst);
//создаем папку для media
std::wstring mediaDir = path.GetDirectory() + L"media";
@ -4348,17 +4350,31 @@ namespace BinXlsxRW
OOX::Spreadsheet::CXlsx *pXlsx = NULL;
switch(fileType)
{
case BinXlsxRW::c_oFileTypes::CSV:
pXlsx = new OOX::Spreadsheet::CXlsx();
CSVReader::ReadFromCsvToXlsx(sInputDir, *pXlsx, nCodePage, sDelimiter);
break;
case BinXlsxRW::c_oFileTypes::XLSX:
default:
pXlsx = new OOX::Spreadsheet::CXlsx(OOX::CPath(sInputDir));
break;
case BinXlsxRW::c_oFileTypes::CSV:
{
pXlsx = new OOX::Spreadsheet::CXlsx();
result = CSVReader::ReadFromCsvToXlsx(sInputDir, *pXlsx, nCodePage, sDelimiter);
}break;
case BinXlsxRW::c_oFileTypes::XLSX:
default:
{
pXlsx = new OOX::Spreadsheet::CXlsx(OOX::CPath(sInputDir));
}break;
}
if (0 != result)
{
RELEASEOBJECT(pXlsx);
return result;
}
pXlsx->PrepareWorkbook();
if (NULL == pXlsx->m_pWorkbook)
{
RELEASEOBJECT(pXlsx);
return AVS_FILEUTILS_ERROR_CONVERT;
}
if (BinXlsxRW::c_oFileTypes::JSON == saveFileType)
{
//todo 46 временно CP_UTF8
@ -4393,11 +4409,17 @@ namespace BinXlsxRW
oFile.WriteFile(pbBase64Buffer, nBase64BufferLen);
oFile.CloseFile();
}
else
{
result = AVS_FILEUTILS_ERROR_CONVERT;
}
RELEASEARRAYOBJECTS(pbBase64Buffer);
}
}
RELEASEOBJECT(pXlsx);
return result;
}
void intoBindoc(OOX::Spreadsheet::CXlsx &oXlsx, NSBinPptxRW::CBinaryFileWriter &oBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter)
{

View File

@ -36,7 +36,7 @@
#include "../../DesktopEditor/common/File.h"
#include "../../Common/DocxFormat/Source/Base/unicode_util.h"
#include "../../Common/OfficeFileErrorDescription.h"
#include "../../UnicodeConverter/UnicodeConverter.h"
#include "../../UnicodeConverter/UnicodeConverter_Encodings.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h"
@ -104,7 +104,7 @@ namespace CSVReader
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf32;
return ansi_2_unicode(data, data_size);
return std::wstring();
}
std::wstring utf32Str ((wchar_t *) pStrUtf32);
@ -138,7 +138,7 @@ namespace CSVReader
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf32;
return ansi_2_unicode(data, data_size);
return std::wstring();
}
std::wstring utf32Str ((wchar_t *) pStrUtf32);
@ -172,7 +172,7 @@ namespace CSVReader
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf16;
return ansi_2_unicode(data, data_size);
return std::wstring();
}
std::wstring utf16Str ((wchar_t *) pStrUtf16);
@ -225,19 +225,22 @@ namespace CSVReader
pCell->setRowCol(nRow, nCol);
oRow.m_arrItems.push_back(pCell);
}
void ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& sDelimiter)
int ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& sDelimiter)
{
// Создадим Workbook
NSFile::CFileBinary oFile;
if (false == oFile.OpenFile(sFileName)) return AVS_FILEUTILS_ERROR_CONVERT;
//-----------------------------------------------------------------------------------
// Создадим Workbook
oXlsx.CreateWorkbook();
// Создадим стили
// Создадим стили
oXlsx.CreateStyles();
// Добавим стили для wrap-а
// Добавим стили для wrap-а
oXlsx.m_pStyles->m_oCellXfs.Init();
oXlsx.m_pStyles->m_oCellXfs->m_oCount.Init();
oXlsx.m_pStyles->m_oCellXfs->m_oCount->SetValue(2);
// Normall default
// Normall default
OOX::Spreadsheet::CXfs* pXfs = NULL;
pXfs = new OOX::Spreadsheet::CXfs();
pXfs->m_oBorderId.Init();
@ -251,7 +254,7 @@ namespace CSVReader
oXlsx.m_pStyles->m_oCellXfs->m_arrItems.push_back(pXfs);
// Wrap style
// Wrap style
pXfs = new OOX::Spreadsheet::CXfs();
pXfs->m_oBorderId.Init();
pXfs->m_oBorderId->SetValue(0);
@ -286,176 +289,184 @@ namespace CSVReader
oXlsx.m_pWorkbook->m_oSheets.Init();
oXlsx.m_pWorkbook->m_oSheets->m_arrItems.push_back(pSheet);
NSFile::CFileBinary oFile;
if(oFile.OpenFile(sFileName))
//-----------------------------------------------------------------------------------
DWORD nFileSize = 0;
BYTE* pFileData = new BYTE[oFile.GetFileSize()];
oFile.ReadFile(pFileData, oFile.GetFileSize(), nFileSize);
oFile.CloseFile();
//skip bom
DWORD nInputBufferSize = nFileSize;
BYTE* pInputBuffer = pFileData;
if (nInputBufferSize >= 3 && 0xef == pInputBuffer[0] && 0xbb == pInputBuffer[1] && 0xbf == pInputBuffer[2])
{
DWORD nFileSize = 0;
BYTE* pFileData = new BYTE[oFile.GetFileSize()];
oFile.ReadFile(pFileData, oFile.GetFileSize(), nFileSize);
oFile.CloseFile();
//skip bom
DWORD nInputBufferSize = nFileSize;
BYTE* pInputBuffer = pFileData;
if (nInputBufferSize >= 3 && 0xef == pInputBuffer[0] && 0xbb == pInputBuffer[1] && 0xbf == pInputBuffer[2])
{
nInputBufferSize -= 3;
pInputBuffer += 3;
}
else if (nInputBufferSize >= 2 && ((0xfe == pInputBuffer[0] && 0xff == pInputBuffer[1]) || (0xff == pInputBuffer[0] && 0xfe == pInputBuffer[1])))
{
nInputBufferSize -= 2;
pInputBuffer += 2;
}
std::wstring sFileDataW;
nInputBufferSize -= 3;
pInputBuffer += 3;
}
else if (nInputBufferSize >= 2 && ((0xfe == pInputBuffer[0] && 0xff == pInputBuffer[1]) || (0xff == pInputBuffer[0] && 0xfe == pInputBuffer[1])))
{
nInputBufferSize -= 2;
pInputBuffer += 2;
}
std::wstring sFileDataW;
if (nCodePage == 1000)
{
sFileDataW = ansi_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 46)//utf-8
{
sFileDataW = utf8_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 48)//utf-16
{
sFileDataW = utf16_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 50) // utf-32
{
sFileDataW = utf32_2_unicode(pInputBuffer, nInputBufferSize);
}
else
{
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
}
if (nCodePage == 1000)
{
sFileDataW = ansi_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 46)//utf-8
{
sFileDataW = utf8_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 48)//utf-16
{
sFileDataW = utf16_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 50) // utf-32
{
sFileDataW = utf32_2_unicode(pInputBuffer, nInputBufferSize);
}
else
{
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
INT nSize = sFileDataW.length();
const WCHAR *pTemp =sFileDataW.c_str();
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
}
//------------------------------------------------------------------------------------------------------------------------------
WCHAR wcDelimiterLeading = L'\0';
WCHAR wcDelimiterTrailing = L'\0';
int nDelimiterSize = 0;
if (sDelimiter.length() > 0)
size_t nSize = sFileDataW.length();
if (nSize < 1 && nInputBufferSize > 0)
{
return AVS_FILEUTILS_ERROR_CONVERT_ICU;
}
const WCHAR *pTemp = sFileDataW.c_str();
WCHAR wcDelimiterLeading = L'\0';
WCHAR wcDelimiterTrailing = L'\0';
int nDelimiterSize = 0;
if (sDelimiter.length() > 0)
{
wcDelimiterLeading = sDelimiter[0];
nDelimiterSize = 1;
if (2 == sizeof(wchar_t) && 0xD800 <= wcDelimiterLeading && wcDelimiterLeading <= 0xDBFF && sDelimiter.length() > 1)
{
wcDelimiterLeading = sDelimiter[0];
nDelimiterSize = 1;
if (2 == sizeof(wchar_t) && 0xD800 <= wcDelimiterLeading && wcDelimiterLeading <= 0xDBFF && sDelimiter.length() > 1)
{
wcDelimiterTrailing = sDelimiter[1];
nDelimiterSize = 2;
}
}
const WCHAR wcNewLineN = _T('\n');
const WCHAR wcNewLineR = _T('\r');
const WCHAR wcQuote = _T('"');
const WCHAR wcTab = _T('\t');
bool bIsWrap = false;
WCHAR wcCurrent;
INT nStartCell = 0;
std::stack<INT> oDeleteChars;
bool bInQuote = false;
INT nIndexRow = 0;
INT nIndexCol = 0;
OOX::Spreadsheet::CRow *pRow = new OOX::Spreadsheet::CRow();
pRow->m_oR.Init();
pRow->m_oR->SetValue(nIndexRow + 1);
for (INT nIndex = 0; nIndex < nSize; ++nIndex)
{
wcCurrent = pTemp[nIndex];
if (wcDelimiterLeading == wcCurrent && (L'\0' == wcDelimiterTrailing || (nIndex + 1 < nSize && wcDelimiterTrailing == pTemp[nIndex + 1])))
{
if (bInQuote)
continue;
// New Cell
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
bIsWrap = false;
nStartCell = nIndex + nDelimiterSize;
if (nStartCell == nSize)
{
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
pRow = NULL;
}
}
else if (wcNewLineN == wcCurrent || wcNewLineR == wcCurrent)
{
if (bInQuote)
{
// Добавим Wrap
bIsWrap = true;
continue;
}
// New line
if (nStartCell != nIndex)
{
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
bIsWrap = false;
}
if (wcNewLineR == wcCurrent && nIndex + 1 != nSize && wcNewLineN == pTemp[nIndex + 1])
{
// На комбинацию \r\n должен быть только 1 перенос
++nIndex;
}
nStartCell = nIndex + 1;
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
pRow = new OOX::Spreadsheet::CRow();
pRow->m_oR.Init();
pRow->m_oR->SetValue(++nIndexRow + 1);
nIndexCol = 0;
}
else if (wcQuote == wcCurrent)
{
// Quote
if (false == bInQuote && nStartCell == nIndex && nIndex + 1 != nSize)
{
// Начало новой ячейки (только если мы сразу после разделителя и не в конце файла)
bInQuote = !bInQuote;
nStartCell = nIndex + 1;
}
else if ( bInQuote )
{
// Нужно удалить кавычку ограничитель
oDeleteChars.push(nIndex);
// Если следующий символ кавычка, то мы не закончили ограничитель строки (1997,Ford,E350,"Super, ""luxurious"" truck")
if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1])
++nIndex;
else
bInQuote = !bInQuote;
}
}
else if (wcTab == wcCurrent)
{
// delete tab if not delimiter
oDeleteChars.push(nIndex);
}
}
if (nStartCell != nSize)
{
// New line
std::wstring sCellText(pTemp + nStartCell, nSize - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
}
else
{
RELEASEOBJECT(pRow);
wcDelimiterTrailing = sDelimiter[1];
nDelimiterSize = 2;
}
}
const WCHAR wcNewLineN = _T('\n');
const WCHAR wcNewLineR = _T('\r');
const WCHAR wcQuote = _T('"');
const WCHAR wcTab = _T('\t');
bool bIsWrap = false;
WCHAR wcCurrent;
INT nStartCell = 0;
std::stack<INT> oDeleteChars;
bool bInQuote = false;
INT nIndexRow = 0;
INT nIndexCol = 0;
OOX::Spreadsheet::CRow *pRow = new OOX::Spreadsheet::CRow();
pRow->m_oR.Init();
pRow->m_oR->SetValue(nIndexRow + 1);
for (size_t nIndex = 0; nIndex < nSize; ++nIndex)
{
wcCurrent = pTemp[nIndex];
if (wcDelimiterLeading == wcCurrent && (L'\0' == wcDelimiterTrailing || (nIndex + 1 < nSize && wcDelimiterTrailing == pTemp[nIndex + 1])))
{
if (bInQuote)
continue;
// New Cell
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
bIsWrap = false;
nStartCell = nIndex + nDelimiterSize;
if (nStartCell == nSize)
{
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
pRow = NULL;
}
}
else if (wcNewLineN == wcCurrent || wcNewLineR == wcCurrent)
{
if (bInQuote)
{
// Добавим Wrap
bIsWrap = true;
continue;
}
// New line
if (nStartCell != nIndex)
{
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
bIsWrap = false;
}
if (wcNewLineR == wcCurrent && nIndex + 1 != nSize && wcNewLineN == pTemp[nIndex + 1])
{
// На комбинацию \r\n должен быть только 1 перенос
++nIndex;
}
nStartCell = nIndex + 1;
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
pRow = new OOX::Spreadsheet::CRow();
pRow->m_oR.Init();
pRow->m_oR->SetValue(++nIndexRow + 1);
nIndexCol = 0;
}
else if (wcQuote == wcCurrent)
{
// Quote
if (false == bInQuote && nStartCell == nIndex && nIndex + 1 != nSize)
{
// Начало новой ячейки (только если мы сразу после разделителя и не в конце файла)
bInQuote = !bInQuote;
nStartCell = nIndex + 1;
}
else if ( bInQuote )
{
// Нужно удалить кавычку ограничитель
oDeleteChars.push(nIndex);
// Если следующий символ кавычка, то мы не закончили ограничитель строки (1997,Ford,E350,"Super, ""luxurious"" truck")
if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1])
++nIndex;
else
bInQuote = !bInQuote;
}
}
else if (wcTab == wcCurrent)
{
// delete tab if not delimiter
oDeleteChars.push(nIndex);
}
}
if (nStartCell != nSize)
{
// New line
std::wstring sCellText(pTemp + nStartCell, nSize - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
}
else
{
RELEASEOBJECT(pRow);
}
oXlsx.m_arWorksheets.push_back(pWorksheet);
oXlsx.m_mapWorksheets.insert(std::make_pair(sSheetRId, pWorksheet));
return 0;
}
}

View File

@ -41,7 +41,7 @@
namespace CSVReader
{
void AddCell(std::wstring &sText, INT nStartCell, std::stack<INT> &oDeleteChars, OOX::Spreadsheet::CRow &oRow, INT nRow, INT nCol, bool bIsWrap);
void ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& wcDelimiter);
int ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& wcDelimiter);
}
#endif //CSV_READER

View File

@ -34,6 +34,7 @@
#include "../../Common/Base64.h"
#include "../../Common/ATLDefine.h"
#include "../../Common/OfficeFileErrorDescription.h"
#include "../../DesktopEditor/common/Path.h"
#include "../../DesktopEditor/common/Directory.h"
@ -4321,141 +4322,142 @@ namespace BinXlsxRW
bool bResultOk = false;
NSFile::CFileBinary oFile;
if(oFile.OpenFile(sSrcFileName))
if (false == oFile.OpenFile(sSrcFileName)) return AVS_FILEUTILS_ERROR_CONVERT;
DWORD nBase64DataSize = 0;
BYTE* pBase64Data = new BYTE[oFile.GetFileSize()];
oFile.ReadFile(pBase64Data, oFile.GetFileSize(), nBase64DataSize);
oFile.CloseFile();
//проверяем формат
bool bValidFormat = false;
std::wstring sSignature(g_sFormatSignature);
size_t nSigLength = sSignature.length();
if(nBase64DataSize > nSigLength)
{
DWORD nBase64DataSize = 0;
BYTE* pBase64Data = new BYTE[oFile.GetFileSize()];
oFile.ReadFile(pBase64Data, oFile.GetFileSize(), nBase64DataSize);
oFile.CloseFile();
std::string sCurSig((char*)pBase64Data, nSigLength);
std::wstring wsCurSig(sCurSig.begin(), sCurSig.end());
//проверяем формат
bool bValidFormat = false;
std::wstring sSignature(g_sFormatSignature);
size_t nSigLength = sSignature.length();
if(nBase64DataSize > nSigLength)
if(sSignature == wsCurSig)
{
std::string sCurSig((char*)pBase64Data, nSigLength);
std::wstring wsCurSig(sCurSig.begin(), sCurSig.end());
if(sSignature == wsCurSig)
{
bValidFormat = true;
}
bValidFormat = true;
}
if(bValidFormat)
}
if (bValidFormat)
{
//Читаем из файла версию и длину base64
int nIndex = (int)nSigLength;
int nType = 0;
std::string version = "";
std::string dst_len = "";
while (true)
{
//Читаем из файла версию и длину base64
int nIndex = (int)nSigLength;
int nType = 0;
std::string version = "";
std::string dst_len = "";
while (true)
nIndex++;
BYTE _c = pBase64Data[nIndex];
if (_c == ';')
{
nIndex++;
BYTE _c = pBase64Data[nIndex];
if (_c == ';')
{
if(0 == nType)
{
nType = 1;
continue;
}
else
{
nIndex++;
break;
}
}
if(0 == nType)
version += _c;
else
dst_len += _c;
}
int nVersion = g_nFormatVersion;
if(!version.empty())
{
version = version.substr(1);
g_nCurFormatVersion = nVersion = std::stoi(version.c_str());
}
bool bIsNoBase64 = nVersion == g_nFormatVersionNoBase64;
NSBinPptxRW::CBinaryFileReader& oBufferedStream = *pOfficeDrawingConverter->m_pReader;
int nDataSize = 0;
BYTE* pData = NULL;
if (!bIsNoBase64)
{
nDataSize = atoi(dst_len.c_str());
pData = new BYTE[nDataSize];
if(Base64::Base64Decode((const char*)(pBase64Data + nIndex), nBase64DataSize - nIndex, pData, &nDataSize))
{
oBufferedStream.Init(pData, 0, nDataSize);
nType = 1;
continue;
}
else
{
RELEASEARRAYOBJECTS(pData);
nIndex++;
break;
}
}
if(0 == nType)
version += _c;
else
dst_len += _c;
}
int nVersion = g_nFormatVersion;
if(!version.empty())
{
version = version.substr(1);
g_nCurFormatVersion = nVersion = std::stoi(version.c_str());
}
bool bIsNoBase64 = nVersion == g_nFormatVersionNoBase64;
NSBinPptxRW::CBinaryFileReader& oBufferedStream = *pOfficeDrawingConverter->m_pReader;
int nDataSize = 0;
BYTE* pData = NULL;
if (!bIsNoBase64)
{
nDataSize = atoi(dst_len.c_str());
pData = new BYTE[nDataSize];
if(Base64::Base64Decode((const char*)(pBase64Data + nIndex), nBase64DataSize - nIndex, pData, &nDataSize))
{
oBufferedStream.Init(pData, 0, nDataSize);
}
else
{
nDataSize = nBase64DataSize;
pData = pBase64Data;
oBufferedStream.Init(pData, 0, nDataSize);
oBufferedStream.Seek(nIndex);
}
if(NULL != pData)
{
// File Type
std::wstring sDstPathCSV = sDstPath;
BYTE fileType;
UINT nCodePage;
std::wstring sDelimiter;
BYTE saveFileType;
SerializeCommon::ReadFileType(sXMLOptions, fileType, nCodePage, sDelimiter, saveFileType);
// Делаем для CSV перебивку пути, иначе создается папка с одинаковым имеем (для rels) и файл не создается.
if (BinXlsxRW::c_oFileTypes::CSV == fileType)
sDstPath = NSSystemPath::GetDirectoryName(sDstPath);
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)
{
case BinXlsxRW::c_oFileTypes::CSV:
CSVWriter::WriteFromXlsxToCsv(sDstPathCSV, oXlsx, nCodePage, sDelimiter, false);
break;
case BinXlsxRW::c_oFileTypes::XLSX:
default:
oXlsx.Write(sDstPath, *oSaveParams.pContentTypes);
break;
}
bResultOk = true;
}
if (!bIsNoBase64)
{
RELEASEARRAYOBJECTS(pData);
}
}
RELEASEARRAYOBJECTS(pBase64Data);
else
{
nDataSize = nBase64DataSize;
pData = pBase64Data;
oBufferedStream.Init(pData, 0, nDataSize);
oBufferedStream.Seek(nIndex);
}
if(NULL != pData)
{
// File Type
std::wstring sDstPathCSV = sDstPath;
BYTE fileType;
UINT nCodePage;
std::wstring sDelimiter;
BYTE saveFileType;
SerializeCommon::ReadFileType(sXMLOptions, fileType, nCodePage, sDelimiter, saveFileType);
// Делаем для CSV перебивку пути, иначе создается папка с одинаковым имеем (для rels) и файл не создается.
if (BinXlsxRW::c_oFileTypes::CSV == fileType)
sDstPath = NSSystemPath::GetDirectoryName(sDstPath);
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)
{
case BinXlsxRW::c_oFileTypes::CSV:
CSVWriter::WriteFromXlsxToCsv(sDstPathCSV, oXlsx, nCodePage, sDelimiter, false);
break;
case BinXlsxRW::c_oFileTypes::XLSX:
default:
oXlsx.Write(sDstPath, *oSaveParams.pContentTypes);
break;
}
bResultOk = true;
}
if (!bIsNoBase64)
{
RELEASEARRAYOBJECTS(pData);
}
}
return S_OK;
RELEASEARRAYOBJECTS(pBase64Data);
if (bResultOk) return 0;
else return AVS_FILEUTILS_ERROR_CONVERT;
}
int ReadMainTable(OOX::Spreadsheet::CXlsx& oXlsx, NSBinPptxRW::CBinaryFileReader& oBufferedStream, const std::wstring& sFileInDir, const std::wstring& sOutDir, SaveParams& oSaveParams, NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter)
{