Commit 3d027e9f authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

XlsFile2 гиперлинки, мержи

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63671 954022d7-b5bf-4e40-9824-e11837661b57
parent 619782dd
......@@ -266,10 +266,6 @@ CFRecord& CFRecord::operator>>(bool& val)
}
CFRecord& CFRecord::operator>>(std::wstring & val)
{
throw;// EXCEPT::LE::WrongAPIUsage("This function may only be called by mistake.", __FUNCTION__);
}
CFRecord& CFRecord::operator<<(bool& val)
......@@ -278,12 +274,6 @@ CFRecord& CFRecord::operator<<(bool& val)
}
CFRecord& CFRecord::operator<<(std::wstring & val)
{
throw;// EXCEPT::LE::WrongAPIUsage("This function may only be called by mistake.", __FUNCTION__);
}
// Registers data receiver place and reserves n unsigned chars for it
void CFRecord::registerDelayedDataReceiver(CFStream::DELAYED_DATA_SAVER fn, const size_t n, const CFRecordType::TypeId receiver_id)
{
......
......@@ -121,7 +121,6 @@ public:
CFRecord& operator>>(short& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(char& val) { loadAnyData(val); return *this; };
CFRecord& operator>>(bool& val);
CFRecord& operator>>(std::wstring & val);
CFRecord& operator<<(unsigned char& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(unsigned short& val) { storeAnyData(val); return *this; };
......@@ -134,7 +133,6 @@ public:
CFRecord& operator<<(char& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(wchar_t& val) { storeAnyData(val); return *this; };
CFRecord& operator<<(bool& val);
CFRecord& operator<<(std::wstring & val);
private:
static const size_t MAX_RECORD_SIZE = 8224;
......
......@@ -39,8 +39,14 @@ void BkHim::readFields(CFRecord& record)
record >> cf;
record.skipNunBytes(2);
record >> lcb;
record.skipNunBytes(lcb);
record >> lcb;//imageBlob size
unsigned int sz = record.getDataSize() - record.getRdPtr();
if (record.checkFitReadSafe(lcb))
{
record.skipNunBytes(lcb);
}
}
} // namespace XLS
......
......@@ -27,26 +27,14 @@ public:
const CellRef getLocation() const;
//-----------------------------
Cell cell;
FormulaValue val;
BIFF_BOOL fAlwaysCalc;
Cell cell;
FormulaValue val;
BIFF_BOOL fAlwaysCalc;
BackwardOnlyParam<bool> fFill;
BIFF_BOOL fShrFmla;
BIFF_BOOL fShrFmla;
BackwardOnlyParam<bool> fClearErrors;
CellParsedFormula formula;
public:
//BO_ATTRIB_MARKUP_BEGIN
//BO_ATTRIB_MARKUP_COMPLEX(cell)
//BO_ATTRIB_MARKUP_ATTRIB(val)
//BO_ATTRIB_MARKUP_ATTRIB(fAlwaysCalc)
//BO_ATTRIB_MARKUP_ATTRIB(fFill)
//BO_ATTRIB_MARKUP_ATTRIB(fShrFmla)
//BO_ATTRIB_MARKUP_ATTRIB(fClearErrors)
//BO_ATTRIB_MARKUP_COMPLEX(formula)
//BO_ATTRIB_MARKUP_END
CellParsedFormula formula;
};
typedef boost::shared_ptr<Formula> FormulaPtr;
......
......@@ -27,7 +27,7 @@ public:
//-----------------------------
Ref8U ref8;
ForwardOnlyParam<std::wstring > hlinkClsid;
OSHARED::HyperlinkObject hyperlink;
OSHARED::HyperlinkObject hyperlink;
};
......
......@@ -45,7 +45,18 @@ void MergeCells::readFields(CFRecord& record)
int MergeCells::serialize(std::wostream & stream)
{
CP_XML_WRITER(stream)
{
for (long i = 0 ; i < rgref.size(); i++)
{
Ref8* ref = dynamic_cast<Ref8*>(rgref[i].get());
CP_XML_NODE(L"mergeCell")
{
CP_XML_ATTR(L"ref", ref->toString());
}
}
}
return 0;
}
......
......@@ -16,7 +16,6 @@ public:
void load(CFRecord& record);
virtual void store(CFRecord& record);
private:
bool is_part_of_a_revision_;
};
......
......@@ -49,11 +49,9 @@ public:
void operator+=(const CellRef& appended_ref);
void operator-=(const CellRef& subtracted_ref);
private:
virtual void load(CFRecord& record) {};
virtual void store(CFRecord& record) {};
protected:
long rowFirst;
long rowLast;
bool rowFirstRelative;
......
......@@ -15,12 +15,9 @@ public:
FileMoniker(XLS::CFRecord& record);
XLS::BiffStructurePtr clone();
//virtual void setXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag);
//virtual void getXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag);
virtual void load(XLS::CFRecord& record);
virtual void store(XLS::CFRecord& record);
private:
unsigned short cAnti;
std::string ansiPath;
unsigned short endServer;
......
......@@ -12,14 +12,11 @@ class FormulaValue : public BiffAttribute
public:
BiffStructurePtr clone();
//virtual void toXML(BiffStructurePtr & parent, const std::wstring & attrib_name);
//virtual const bool fromXML(BiffStructurePtr & parent, const std::wstring & attrib_name);
virtual void load(CFRecord& record);
virtual void store(CFRecord& record);
const unsigned char getType() const;
private:
union
{
struct
......
......@@ -13,12 +13,9 @@ class HyperlinkMoniker : public XLS::BiffStructure
public:
XLS::BiffStructurePtr clone();
//virtual void toXML(BiffStructurePtr & parent);
//virtual const bool fromXML(BiffStructurePtr & parent);
virtual void load(XLS::CFRecord& record);
virtual void store(XLS::CFRecord& record);
private:
std::wstring monikerClsid;
boost::shared_ptr<BiffStructure> data;
};
......
......@@ -15,12 +15,9 @@ class HyperlinkObject : public XLS::BiffStructure
public:
XLS::BiffStructurePtr clone();
//virtual void setXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag);
//virtual void getXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag);
virtual void load(XLS::CFRecord& record);
virtual void store(XLS::CFRecord& record);
private:
unsigned int streamVersion;
bool hlstmfHasMoniker;
......
......@@ -15,38 +15,6 @@ ParsedFormula::ParsedFormula(const CellRef& cell_base_ref)
{
}
//void ParsedFormula::setXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag)
//{
// if(!rgce.isEmpty())
// {
// rgce.toXML(xml_tag);
// }
//// RgbExtra is not necessary for XSLT
//// if(!rgcb.isEmpty())
//// {
//// rgcb.toXML(xml_tag);
//// }
//
// static std::wstring attr_name(L"assembled_formula");
// xml_tag->setAttribute(attr_name, getAssembledFormula(xml_tag->GetparentNode()).c_str());
//}
//void ParsedFormula::getXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag)
//{
// std::wstring assembled_formula = getStructAttribute(xml_tag, L"assembled_formula");
// if(!assembled_formula || std::wstring (L"") == assembled_formula) // for shares formulas, array formulas, or tables
// {
// rgce.fromXML(xml_tag);
// }
// else
// {
// parseStringFormula(static_cast<wchar_t*>(assembled_formula), xml_tag);
// }
//}
void ParsedFormula::setCCE(const size_t cce_val)
{
rgce.setCCE(cce_val);
......
......@@ -21,14 +21,13 @@ public:
const size_t getCCE() const;
const bool HasPtgTbl() const;
private:
const std::wstring getAssembledFormula(BiffStructurePtr & parent) const;
const bool parseStringFormula(const std::wstring formula, BiffStructurePtr & parent);
protected:
Rgce rgce;
RgbExtra rgcb;
private:
size_t cce; // Size of rgce variable. Setting explicit is mandatory
bool cce_is_set;
};
......
......@@ -22,25 +22,6 @@ XLS::BiffStructurePtr URLMoniker::clone()
return XLS::BiffStructurePtr(new URLMoniker(*this));
}
//
//void URLMoniker::setXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag)
//{
// xml_tag->setAttribute(L"url", STR::escapeUrlW(url).c_str());
// if(!!serialGUID)
// {
// xml_tag->setAttribute(L"serialGUID", serialGUID);
// xml_tag->setAttribute(L"serialVersion", serialVersion);
// uriFlags.toXML(xml_tag);
// }
//}
//
//void URLMoniker::getXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag)
//{
// url = static_cast<wchar_t*>(static_cast<std::wstring >(getStructAttribute(xml_tag, L"url")));
//}
void URLMoniker::store(XLS::CFRecord& record)
{
unsigned int length = (url.length() + 1) * 2;
......@@ -51,7 +32,13 @@ void URLMoniker::store(XLS::CFRecord& record)
void URLMoniker::load(XLS::CFRecord& record)
{
unsigned int length;
record >> length >> url;
record >> length;
try
{
record >> url;
}catch(...)
{
}
if(!record.isEOF())
{
......
#pragma once
#include "BiffStructure.h"
#include "BitMarkedStructs.h"
#include <Logic/Biff_structures/URICreateFlags.h>
namespace OSHARED
......@@ -16,15 +16,14 @@ public:
URLMoniker(XLS::CFRecord& record);
XLS::BiffStructurePtr clone();
//virtual void setXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag);
//virtual void getXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag);
virtual void load(XLS::CFRecord& record);
virtual void store(XLS::CFRecord& record);
private:
std::wstring url;
std::wstring serialGUID;
std::wstring serialGUID;
unsigned int serialVersion;
URICreateFlags uriFlags;
};
......
......@@ -9,9 +9,12 @@
#include <Logic/Biff_records/String.h>
#include <Logic/Biff_records/Continue.h>
#include <simple_xml_writer.h>
namespace XLS
{;
extern int cellStyleXfs_count;
FORMULA::FORMULA(std::vector<CellRef>& shared_formulas_locations_ref) : shared_formulas_locations_ref_(shared_formulas_locations_ref)
{
......@@ -34,30 +37,40 @@ const bool FORMULA::loadContent(BinProcessor& proc)
{
proc.optional<Uncalced>();
Formula formula;
if(!proc.mandatory(formula))
{
return false;
}
/* The above is equal to:
Formula *formula = NULL;
if(!proc.mandatory<Formula>())
{
return false;
}
*/
location = formula.getLocation();
m_Formula = elements_.back();
elements_.pop_back();
formula = dynamic_cast<Formula *>(m_Formula.get());
location = formula->getLocation();
Array array_formula(location);
bool array_present = proc.optional(array_formula);
if(!array_present &&
!proc.optional<Table>())
if (proc.optional(array_formula))
{
m_ArrayFormula = elements_.back();
elements_.pop_back();
}
if (proc.optional<Table>())
{
m_TableFormula = elements_.back();
elements_.pop_back();
}
if(!m_ArrayFormula && !m_TableFormula)
{
//proc.optional<ShrFmla>(); // replaced with below:
ShrFmla shr_formula(location);
if(proc.optional(shr_formula))
{
m_SharedFormula = elements_.back();
elements_.pop_back();
shared_formulas_locations_ref_.push_back(location);
}
//proc.optional<SUB>(); // I haven't found any mention about SUB in the docs
......@@ -76,6 +89,46 @@ const CellRef FORMULA::getLocation() const
return location;
}
int FORMULA::serialize(std::wostream & stream)
{
Formula *formula = dynamic_cast<Formula *>(m_Formula.get());
if (formula == NULL) return 0;
CP_XML_WRITER(stream)
{
std::wstring ref = formula->cell.getLocation().toString();
CP_XML_NODE(L"c")
{
CP_XML_ATTR(L"r", ref);
if ((formula->cell.ixfe.value()) && (formula->cell.ixfe > cellStyleXfs_count))
{
CP_XML_ATTR(L"s", formula->cell.ixfe - cellStyleXfs_count);
}
CP_XML_NODE(L"f")
{
CP_XML_STREAM() << formula->formula.getAssembledFormula(BiffStructurePtr());
}
switch (formula->val.getType())
{
case 0: CP_XML_ATTR(L"t", L"str"); break;
case 1: CP_XML_ATTR(L"t", L"b"); break;
case 2: CP_XML_ATTR(L"t", L"e"); break;
case 4:
{
CP_XML_NODE(L"v")
{
CP_XML_STREAM() << STR::double2str(formula->val.data.xnum);
}
}break;
}
}
}
return 0;
}
} // namespace XLS
......@@ -21,8 +21,16 @@ public:
virtual const bool loadContent(BinProcessor& proc);
static const ElementType type = typeFORMULA;
int serialize(std::wostream & stream);
const CellRef getLocation() const;
BaseObjectPtr m_Formula;
BaseObjectPtr m_TableFormula;
BaseObjectPtr m_ArrayFormula;
BaseObjectPtr m_SharedFormula;
CellRef location;
std::vector<CellRef>& shared_formulas_locations_ref_;
......
......@@ -30,7 +30,14 @@ const bool HLINK::loadContent(BinProcessor& proc)
{
return false;
}
proc.optional<HLinkTooltip>();
m_HLink = elements_.back();
elements_.pop_back();
if (proc.optional<HLinkTooltip>())
{
m_HLinkTooltip = elements_.back();
elements_.pop_back();
}
return true;
}
......
......@@ -19,6 +19,9 @@ public:
virtual const bool loadContent(BinProcessor& proc);
static const ElementType type = typeHLINK;
BaseObjectPtr m_HLink;
BaseObjectPtr m_HLinkTooltip;
};
} // namespace XLS
......
......@@ -166,10 +166,12 @@ const bool WorksheetSubstream::loadContent(BinProcessor& proc)
proc.optional<PHONETICINFO>();
proc.optional<CONDFMTS>(); // Let it be optional
if (proc.repeated<HLINK>(0, 0) > 0)
count = proc.repeated<HLINK>(0, 0) ;
while(count > 0)
{
m_HLINK = elements_.back();
m_HLINK.insert(m_HLINK.begin(), elements_.back());
elements_.pop_back();
count--;
}
proc.optional<DVAL>();
......
......@@ -33,7 +33,7 @@ public:
BaseObjectPtr m_CELLTABLE;
BaseObjectPtr m_SHFMLA_SET;
BaseObjectPtr m_Dimensions;
BaseObjectPtr m_HLINK;
std::vector<BaseObjectPtr> m_HLINK;
};
} // namespace XLS
......
......@@ -15,8 +15,13 @@
#include "../XlsFormat/Logic/Biff_unions/GLOBALS.h"
#include "../XlsFormat/Logic/Biff_unions/COLUMNS.h"
#include "../XlsFormat/Logic/Biff_unions/SHAREDSTRINGS.h"
#include "../XlsFormat/Logic/Biff_unions/HLINK.h"
#include <Logic/Biff_records/HLink.h>
#include <Logic/Biff_structures/URLMoniker.h>
#include <Logic/Biff_structures/FileMoniker.h>
#include "xlsx_conversion_context.h"
#include "xlsx_package.h"
......@@ -91,11 +96,13 @@ XlsConverter::XlsConverter(const std::wstring & path, const ProgressCallback* Ca
output_document = new oox::package::xlsx_document();
xlsx_context = new oox::xlsx_conversion_context(output_document);
}
XlsConverter::~XlsConverter()
{
if (xlsx_context) delete xlsx_context;
if (output_document) delete output_document;
}
#define PROGRESSEVENT_ID 0
bool XlsConverter::UpdateProgress(long nComplete)
......@@ -147,12 +154,17 @@ void XlsConverter::convert(XLS::BaseObject *xls_unknown)
switch (type)
{
case XLS::typeHLINK:
{
XLS::HLINK * hlink = dynamic_cast<XLS::HLINK *>(xls_unknown);
convert(hlink);
}break;
case XLS::typeAnyObject:
default:
{
for (std::list<XLS::BaseObjectPtr>::iterator it = xls_unknown->elements_.begin(); it != xls_unknown->elements_.end(); it++)
{
(*it)->serialize(xlsx_context->current_stream());
(*it)->serialize(xlsx_context->current_sheet().sheetData());
}
}
}
......@@ -218,6 +230,11 @@ void XlsConverter::convert(XLS::WorksheetSubstream* sheet)
}
}
}
for (long i = 0 ; i < sheet->m_HLINK.size(); i++)
{
convert(sheet->m_HLINK[i].get());
}
if (sheet->m_PAGESETUP)
{
sheet->m_PAGESETUP->serialize(xlsx_context->current_sheet().pageProperties());
......@@ -291,6 +308,40 @@ void XlsConverter::convert(XLS::FORMATTING* formating)
output_document->get_xl_files().set_styles( oox::package::simple_element::create(L"styles.xml", strm.str()) );
}
std::wstring XlsConverter::GetTargetMoniker(XLS::BiffStructure *moniker)
{
if (moniker->getClassName() == L"URLMoniker")
{
OSHARED::URLMoniker* urlMoniker = dynamic_cast<OSHARED::URLMoniker* >(moniker);
if (urlMoniker)return urlMoniker->url;
}
else if (moniker->getClassName() == L"FileMoniker")
{
OSHARED::FileMoniker* fileMoniker = dynamic_cast<OSHARED::FileMoniker* >(moniker);
if (fileMoniker)
{
if (!fileMoniker->unicodePath.empty()) return fileMoniker->unicodePath;
else return std::wstring(fileMoniker->ansiPath.begin(), fileMoniker->ansiPath.end());//codePage ??? todooo
}
}
return L"";
}
void XlsConverter::convert(XLS::HLINK * HLINK_)
{
XLS::HLink * hLink = dynamic_cast<XLS::HLink*>(HLINK_->m_HLink.get());
std::wstring target = GetTargetMoniker(hLink->hyperlink.oleMoniker.data.get());
std::wstring display = hLink->hyperlink.displayName;
if (display.empty()) display = target;
xlsx_context->get_table_context().add_hyperlink( hLink->ref8.toString(), target, display);
}
void XlsConverter::convert(XLS::THEME* theme)
{
if (theme == NULL) return;
......
......@@ -17,6 +17,8 @@ namespace oox
namespace XLS
{
class BaseObject;
class BiffStructure;
typedef boost::shared_ptr<BaseObject> BaseObjectPtr;
class GlobalWorkbookInfo;
......@@ -29,6 +31,7 @@ namespace XLS
class FORMATTING;
class THEME;
class SHAREDSTRINGS;
class HLINK;
}
......@@ -60,6 +63,9 @@ private:
void convert(XLS::FORMATTING * formating);
void convert(XLS::THEME * theme);
void convert(XLS::SHAREDSTRINGS * sharedstrings);
void convert(XLS::HLINK * hlink);
std::wstring GetTargetMoniker(XLS::BiffStructure *moniker);
};
......@@ -5,11 +5,8 @@
#include "simple_xml_writer.h"
//#include "measuredigits.h"
#include "xlsx_package.h"
//#include "xlsx_utils.h"
//#include "xlsx_cell_format.h"
//#include "../odf/calcs_styles.h"
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
......@@ -29,33 +26,20 @@ xlsx_conversion_context::~xlsx_conversion_context()
{
}
std::wostream & xlsx_conversion_context::current_stream()
{
if (!sheets_.empty())
return current_sheet().sheetData();
else
return other_stream;
}
//std::wostream & xlsx_conversion_context::current_stream()
//{
// return current_stream_;
//}
//
//void xlsx_conversion_context::current_stream(std::wostream & stream)
//{
// current_stream_ = stream;
//}
void xlsx_conversion_context::start_document()
{
// std::vector<const odf_reader::style_instance *> instances;
//
//instances.push_back(odfContext.styleContainer().style_default_by_type(odf_types::style_family::TableCell));
//instances.push_back(odfContext.styleContainer().style_by_name(L"Default",odf_types::style_family::TableCell,false));
// odf_reader::text_format_properties_content textFormatProperties = calc_text_properties_content(instances);
// odf_reader::paragraph_format_properties parFormatProperties = calc_paragraph_properties_content(instances);
// odf_reader::style_table_cell_properties_attlist cellFormatProperties = calc_table_cell_properties(instances);
// oox::xlsx_cell_format cellFormat;
//
//cellFormat.set_cell_type(XlsxCellType::s);
// cellFormat.set_num_format(oox::odf_string_to_build_in(0));
// default_style_ = get_style_manager().xfId(&textFormatProperties, &parFormatProperties, &cellFormatProperties, &cellFormat, L"",true);
}
xlsx_xml_worksheet & xlsx_conversion_context::current_sheet()
{
if (!sheets_.empty())
......@@ -69,87 +53,16 @@ xlsx_xml_worksheet & xlsx_conversion_context::current_sheet()
}
bool xlsx_conversion_context::start_table(const std::wstring & name)
{
//if (get_table_context().depth() > 0)
// return false;
sheets_.push_back(xlsx_xml_worksheet::create(name));
get_table_context().start_table(name);
//current_sheet().cols() << L"<cols>";
return true;
return true;
}
void xlsx_conversion_context::end_table()
{
//const double lastWidht = table_column_last_width();
//if (lastWidht > 0.0)
//{
// unsigned int cMin = get_table_context().columns_count() + 1;
// unsigned int cMax = (std::max)((unsigned int)1024, get_table_context().columns_count() + 100);
// CP_XML_WRITER(current_sheet().cols())
// {
// CP_XML_NODE(L"col")
// {
////CP_XML_ATTR(L"collapsed", L"false");
////CP_XML_ATTR(L"hidden", L"false");
// CP_XML_ATTR(L"max", cMax);
// CP_XML_ATTR(L"min", cMin);
// //CP_XML_ATTR(L"style", 0);
// CP_XML_ATTR(L"width", lastWidht);
// CP_XML_ATTR(L"customWidth", 0);
// }
// }
//}
//current_sheet().cols() << L"</cols>";
//get_table_context().serialize_table_format(current_sheet().sheetFormat());
// get_table_context().serialize_merge_cells(current_sheet().mergeCells());
// get_table_context().serialize_hyperlinks(current_sheet().hyperlinks());
//get_table_context().dump_rels_hyperlinks(current_sheet().hyperlinks_rels());
//get_drawing_context().set_odf_packet_path(root()->get_folder());
//get_drawing_context().process_charts(get_table_metrics());
//get_drawing_context().process_images(get_table_metrics());
//get_drawing_context().process_shapes(get_table_metrics());
//if (!get_drawing_context().empty())
// {
// std::wstringstream strm;
// get_drawing_context().write_drawing(strm);
//
// const std::pair<std::wstring, std::wstring> drawingName
// = xlsx_drawing_context_handle_.add_drawing_xml(strm.str(), get_drawing_context().get_drawings() );
// current_sheet().set_drawing_link(drawingName.first, drawingName.second);
// CP_XML_WRITER(current_sheet().drawing())
// {
// CP_XML_NODE(L"drawing")
// {
// CP_XML_ATTR(L"r:id", drawingName.second);
// }
// }
// }
//if (!get_comments_context().empty())
// {
// std::wstringstream strm;
// get_comments_context().write_comments(strm);
//
// std::wstringstream vml_strm;
// get_comments_context().write_comments_vml(vml_strm);
//
// const std::pair<std::wstring, std::wstring> commentsName
// = xlsx_comments_context_handle_.add_comments_xml(strm.str(), vml_strm.str(),get_comments_context().get_comments() );
// const std::pair<std::wstring, std::wstring> vml_drawingName
// =xlsx_comments_context_handle_.get_vml_drawing_xml();
// current_sheet().set_comments_link(commentsName.first, commentsName.second);
// current_sheet().set_vml_drawing_link(vml_drawingName.first, vml_drawingName.second);
// }
get_table_context().serialize_hyperlinks(current_sheet().hyperlinks());
get_table_context().dump_rels_hyperlinks(current_sheet().hyperlinks_rels());
get_table_context().end_table();
}
......
......@@ -27,28 +27,7 @@ public:
void start_document();
void end_document();
std::wostream & current_stream();
std::wostream & shared_strings() {return xlsx_shared_strings_;}
// void start_chart(std::wstring const & name);
// void end_chart();
//
//void start_body();
// void end_body();
// void start_office_spreadsheet(const odf_reader::office_element * elm);
// void end_office_spreadsheet();
// const odf_reader::office_element * get_spreadsheet();
// void start_paragraph(const std::wstring & styleName);
// void end_paragraph();
// void start_span(const std::wstring & styleName);
// void end_span();
bool start_table(const std::wstring & name);
bool start_table(const std::wstring & name);
void end_table();
......@@ -86,7 +65,8 @@ public:
// void process_styles();
xlsx_text_context & get_text_context() { return xlsx_text_context_; }
std::wostream & shared_strings() {return xlsx_shared_strings_;}
xlsx_text_context & get_text_context() { return xlsx_text_context_; }
xlsx_table_context & get_table_context() { return xlsx_table_context_; }
// const xlsx_table_context & get_table_context() const { return xlsx_table_context_; }
// xlsx_style_manager & get_style_manager() { return xlsx_style_; }
......@@ -106,7 +86,6 @@ public:
private:
std::wstringstream other_stream;
void create_new_sheet(std::wstring const & name);
package::xlsx_document *output_document_;
......
#include "xlsx_hyperlinks.h"
#include "oox_rels.h"
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <simple_xml_writer.h>
namespace oox {
class xlsx_hyperlinks::Impl
{
public:
Impl() {}
~Impl() {}
struct record
{
std::wstring ref;
std::wstring display;
std::wstring location;
std::wstring id;
std::wstring href;
std::wstring type;
};
void dump_rels(rels & Rels) const
{
BOOST_FOREACH(const record & rec, records_)
{
if (rec.type == L"External")
{
Rels.add( relationship(rec.id, L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", rec.location, rec.type) );
}
}
}
std::wstring add(std::wstring const & ref, std::wstring const & target1, std::wstring const & display)
{
std::wstring target =target1;
int res = target.rfind(L"/");
if (res >=0 && res+1==target.length())
{
target.resize(target.length()-1);
}
record r;
r.ref = ref;
r.display = display;
r.id = std::wstring(L"hId") + boost::lexical_cast<std::wstring>(records_.size()+1);
r.location = target;
r.type = L"External" ;
if (r.display.length()<1)
r.display =target;
records_.push_back(r);
return r.id;
}
void serialize(std::wostream & _Wostream) const
{
CP_XML_WRITER(_Wostream)
{
CP_XML_NODE(L"hyperlinks")
{
BOOST_FOREACH(record const & r, records_)
{
CP_XML_NODE(L"hyperlink")
{
CP_XML_ATTR(L"ref", r.ref);
CP_XML_ATTR(L"display", r.display);
if (!r.location.empty() && r.type == L"Internal")
{
CP_XML_ATTR(L"location", r.location);
}
if (!r.id.empty() && r.type == L"External")
{
CP_XML_ATTR(L"r:id", r.id);
}
}
}
}
}
}
private:
std::vector<record> records_;
};
xlsx_hyperlinks::xlsx_hyperlinks() : impl_( new xlsx_hyperlinks::Impl() )
{
}
xlsx_hyperlinks::~xlsx_hyperlinks()
{
}
std::wstring xlsx_hyperlinks::add(std::wstring const & ref, std::wstring const & target, std::wstring const & display)
{
return impl_->add(ref, target, display);
}
void xlsx_hyperlinks::dump_rels(rels & Rels) const
{
impl_->dump_rels(Rels);
}
void xlsx_hyperlinks::serialize(std::wostream & _stream) const
{
impl_->serialize(_stream);
}
}
#pragma once
#include "../Common/common.h"
namespace oox {
class rels;
class xlsx_hyperlinks
{
public:
xlsx_hyperlinks();
~xlsx_hyperlinks();
std::wstring add( std::wstring const & ref, std::wstring const & target, std::wstring const & display);
void dump_rels(rels & Rels) const;
void serialize(std::wostream & _stream) const;
private:
class Impl;
_CP_PTR(Impl) impl_;
};
}
\ No newline at end of file
......@@ -128,16 +128,10 @@ void xlsx_xml_worksheet::write_to(std::wostream & strm)
// !!!
CP_XML_STREAM() << impl_->mergeCells_.str();
if (!impl_->hyperlinks_.str().empty())
{
CP_XML_NODE(L"hyperlinks")
{
CP_XML_STREAM() << impl_->hyperlinks_.str();
}
}
CP_XML_STREAM() << impl_->hyperlinks_.str();
CP_XML_STREAM() << impl_->drawing_.str();
if (impl_->commentsId_.length()>0)
{
CP_XML_NODE(L"legacyDrawing")
......
#include "xlsx_table_state.h"
#include "logging.h"
#include "xlsxconversioncontext.h"
#include <cpdoccore/xml/simple_xml_writer.h>
namespace cpdoccore {
namespace oox {
xlsx_table_state::xlsx_table_state(xlsx_conversion_context & Context, const std::wstring & StyleName, const std::wstring & tableName)
: context_(Context),
table_style_(StyleName),
tableName_(tableName),
current_table_column_(-1),
current_table_row_(-1),
columns_spanned_num_(0),
columns_count_(0),
xlsx_drawing_context_(Context.get_drawing_context_handle()),
xlsx_comments_context_(Context.get_comments_context_handle()),
table_column_last_width_(0.0)
{
memset(&group_row_,0,sizeof(_group_row));
}
void xlsx_table_state::start_column(unsigned int repeated, const std::wstring & defaultCellStyleName)
{
for (unsigned int i = 0; i <repeated; ++i)
column_default_cell_style_name_.push_back(defaultCellStyleName);
columns_count_ += repeated;
columns_.push_back(repeated);
}
unsigned int xlsx_table_state::columns_count() const
{
return columns_count_;
}
void xlsx_table_state::set_table_row_group(int count, bool collapsed, int level)
{
group_row_.enabled = true;
group_row_.count = count;
group_row_.collapsed = collapsed;
group_row_.level = level;
}
void xlsx_table_state::start_row(const std::wstring & StyleName, const std::wstring & defaultCellStyleName)
{
empty_row_ = true;
// reset column num, column spanned style
current_table_column_ = -1;
current_table_row_++;
columns_spanned_style_ = L"";
row_default_cell_style_name_ = defaultCellStyleName;
// set row style name
table_row_style_ = StyleName;
}
void xlsx_table_state::non_empty_row()
{
empty_row_= false;
}
bool xlsx_table_state::is_empty_row() const
{
return empty_row_;
}
std::wstring xlsx_table_state::default_row_cell_style() const
{
return row_default_cell_style_name_;
}
std::wstring xlsx_table_state::default_column_cell_style() const
{
if (current_table_column_ < column_default_cell_style_name_.size())
return column_default_cell_style_name_.at(current_table_column_);
else
{
// !! - ods???
return L"";
}
}
void xlsx_table_state::end_row()
{
table_row_style_ = L"";
}
std::wstring xlsx_table_state::current_row_style() const
{
return table_row_style_;
}
void xlsx_table_state::start_cell(size_t columnsSpanned, size_t rowsSpanned)
{
current_table_column_++;
//
if (columnsSpanned != 0 || rowsSpanned != 0)
merge_cells_.add_merge(current_table_column_, current_table_row_, columnsSpanned, rowsSpanned);
if ( current_columns_spaned() > 0 )
{
_CP_LOG << L"[warning] current columns spanned > 0\n";
}
columns_spanned_num_ = static_cast<int>(columnsSpanned);
// ,
//
for (size_t i = 0; i <= columns_spanned_num_; ++i)
{
if (current_table_column_+i >= (int)(rows_spanned_.size()))
rows_spanned_.push_back(xlsx_row_spanned());
}
if (rows_spanned_.size() <= current_table_column_)
{
_CP_LOG << L"[warning] set_rows_spanned error\n";
}
else
{
if (rows_spanned_[current_table_column_].num() > 0)
{
_CP_LOG << L"[warning] current rows spanned > 0\n";
}
rows_spanned_[current_table_column_].num(static_cast<unsigned int>(rowsSpanned));
rows_spanned_[current_table_column_].column_spanned(static_cast<unsigned int>(columnsSpanned));
for (size_t i = 0; i <= columns_spanned_num_; ++i)
{
rows_spanned_[current_table_column_ + i].set_style_id(-1);
}
}
}
void xlsx_table_state::end_cell()
{
}
void xlsx_table_state::set_current_cell_style_id(unsigned int xfId)
{
for (size_t i = 0; i <= columns_spanned_num_; ++i)
{
rows_spanned_[current_table_column_ + i].set_style_id((int)xfId);
}
}
int xlsx_table_state::get_current_cell_style_id()
{
return rows_spanned_[current_table_column_].get_style_id();
}
void xlsx_table_state::start_covered_cell()
{
current_table_column_++;
// ,
//
if (current_table_column_ >= (int)(rows_spanned_.size()))
rows_spanned_.push_back(xlsx_row_spanned());
// ,
//
if (columns_spanned_num_ > 0)
columns_spanned_num_--;
if (rows_spanned_[current_table_column_].num() > 0)
rows_spanned_[current_table_column_].decrease();
if (current_table_column_ > 0)
{
const unsigned int pred = rows_spanned_[current_table_column_ - 1].column_spanned();
if (pred > 0)
{
rows_spanned_[current_table_column_].column_spanned(pred - 1);
rows_spanned_[current_table_column_].num(rows_spanned_[current_table_column_ - 1].num());
}
}
}
void xlsx_table_state::end_covered_cell()
{
}
int xlsx_table_state::current_column() const
{
return current_table_column_;
}
int xlsx_table_state::current_row() const
{
return current_table_row_;
}
unsigned int xlsx_table_state::current_columns_spaned() const
{
return columns_spanned_num_;
}
unsigned int xlsx_table_state::current_rows_spanned(unsigned int Column) const
{
if (rows_spanned_.size() <= Column)
{
_CP_LOG << L"[warning] current_rows_spanned error\n";
return 0;
}
else
{
return rows_spanned_[Column].num();
}
}
double charsToSize(unsigned int charsCount, double maxDigitSize)
{
return 1.0 * int((maxDigitSize * charsCount + 5.0) / maxDigitSize * 256.0) / 256.0;
}
void xlsx_table_state::serialize_table_format(std::wostream & _Wostream)
{
CP_XML_WRITER(_Wostream)
{
CP_XML_NODE(L"sheetView")
{
// -showGridLines
// -showRowColHeaders
// -rightToLeft
// -zoomScale
}
CP_XML_NODE(L"sheetFormatPr")
{
double default_height = (context_.getMaxDigitSize().second * 72. / 96. * 100.) /100.;//in point size.
//odf::style_instance * rowStyle = odfContext.styleContainer().style_by_name(styleName, odf_types::style_family::TableRow,false/*false*/);
//if (!rowStyle)
// break;
//if (!rowStyle->content())
// break;
//const odf_reader::style_table_row_properties * prop = rowStyle->content()->get_style_table_row_properties();
//if (!prop)
// break;
//if (const _CP_OPT(odf_types::length) & height = prop->style_table_row_properties_attlist_.style_row_height_)
//{
// row_height = height->get_value_unit(odf_types::length::pt);
// std::wstringstream ht_s;
// ht_s.precision(3);
// ht_s << std::fixed << row_height;
// ht = ht_s.str();
//}
//CP_XML_ATTR(L"defaultColWidth", merges_.size());
CP_XML_ATTR(L"defaultRowHeight",default_height);
}
}
}
void xlsx_table_state::serialize_merge_cells(std::wostream & _Wostream)
{
return merge_cells_.xlsx_serialize(_Wostream);
}
void xlsx_table_state::serialize_hyperlinks(std::wostream & _Wostream)
{
return xlsx_hyperlinks_.xlsx_serialize(_Wostream);
}
void xlsx_table_state::dump_rels_hyperlinks(rels & Rels)
{
return xlsx_hyperlinks_.dump_rels(Rels);
}
void xlsx_table_state::start_hyperlink()
{
}
std::wstring xlsx_table_state::end_hyperlink(std::wstring const & ref, std::wstring const & href, std::wstring const & display)
{
return xlsx_hyperlinks_.add(ref, href, display);
}
}
}
#pragma once
#include <vector>
#include "xlsx_row_spanned.h"
#include "xlsx_merge_cells.h"
#include "xlsx_table_metrics.h"
#include "xlsx_drawing_context.h"
#include "xlsx_comments_context.h"
#include "xlsx_hyperlinks.h"
namespace cpdoccore {
namespace oox {
class xlsx_conversion_context;
class xlsx_table_state
{
public:
xlsx_table_state(xlsx_conversion_context & Context, const std::wstring & StyleName, const std::wstring & tableName);
std::wstring current_style() const { return table_style_; }
void start_column(unsigned int repeated, const std::wstring & defaultCellStyleName);
void start_row(const std::wstring & StyleName, const std::wstring & defaultCellStyleName);
void non_empty_row();
bool is_empty_row() const;
void end_row();
std::wstring current_row_style() const;
std::wstring default_row_cell_style() const;
std::wstring default_column_cell_style() const;
void set_table_row_group(int count, bool collapsed, int level);
void start_cell(size_t columnsSpanned, size_t rowsSpanned);
void end_cell();
void start_covered_cell();
void end_covered_cell();
void set_current_cell_style_id(unsigned int xfId);
int get_current_cell_style_id();
int current_column() const;
int current_row() const;
unsigned int current_columns_spaned() const;
unsigned int current_rows_spanned(unsigned int Column) const;
unsigned int columns_count() const;
xlsx_table_metrics & get_table_metrics() { return xlsx_table_metrics_; }
xlsx_drawing_context & get_drawing_context() { return xlsx_drawing_context_; }
xlsx_comments_context & get_comments_context() { return xlsx_comments_context_; }
void table_column_last_width(double w) { table_column_last_width_ = w; }
double table_column_last_width() const { return table_column_last_width_; };
void start_hyperlink();
std::wstring end_hyperlink(std::wstring const & ref, std::wstring const & href, std::wstring const & display);
void serialize_table_format(std::wostream & _Wostream);
void serialize_merge_cells(std::wostream & _Wostream);
void serialize_hyperlinks(std::wostream & _Wostream);
void dump_rels_hyperlinks(rels & Rels);
std::wstring get_current_table_name() const { return tableName_; }
struct _group_row
{
bool enabled;
int count;
int level;
bool collapsed;
}group_row_;
private:
xlsx_conversion_context & context_;
std::wstring table_style_;
std::wstring tableName_;
std::wstring table_row_style_;
std::vector<std::wstring> column_default_cell_style_name_;
std::wstring row_default_cell_style_name_;
std::wstring cell_style_;
int current_table_column_;
int current_table_row_;
unsigned int columns_spanned_num_;
std::wstring columns_spanned_style_;
std::vector<xlsx_row_spanned> rows_spanned_;
std::vector<unsigned int> columns_;
unsigned int columns_count_;
xlsx_merge_cells merge_cells_;
xlsx_table_metrics xlsx_table_metrics_;
xlsx_drawing_context xlsx_drawing_context_;
xlsx_comments_context xlsx_comments_context_;
bool empty_row_;
double table_column_last_width_;
xlsx_hyperlinks xlsx_hyperlinks_;
};
}
}
......@@ -36,7 +36,6 @@ void xlsx_table_context::start_table(const std::wstring & name)
void xlsx_table_context::end_table()
{
//table_state_stack_.pop_back();
}
//
//std::wstring xlsx_table_context::get_current_table_name() const
......@@ -149,11 +148,8 @@ void xlsx_table_context::end_table()
//{
// return state().serialize_hyperlinks(_Wostream);
//}
//void xlsx_table_context::dump_rels_hyperlinks(rels & Rels)
//{
// return state().dump_rels_hyperlinks(Rels);
//}
//
//xlsx_table_metrics & xlsx_table_context::get_table_metrics()
//{
// return state().get_table_metrics();
......@@ -183,10 +179,18 @@ void xlsx_table_context::end_table()
// return state().start_hyperlink();
//}
//
// std::wstring xlsx_table_context::end_hyperlink(std::wstring const & ref, std::wstring const & href, std::wstring const & display)
//{
// return state().end_hyperlink(ref, href, display);
//}
//
std::wstring xlsx_table_context::add_hyperlink(std::wstring const & ref, std::wstring const & target, std::wstring const & display)
{
return xlsx_hyperlinks_.add( ref, target, display);
}
void xlsx_table_context::dump_rels_hyperlinks(rels & Rels)
{
return xlsx_hyperlinks_.dump_rels(Rels);
}
void xlsx_table_context::serialize_hyperlinks(std::wostream & _Wostream)
{
return xlsx_hyperlinks_.serialize(_Wostream);
}
}
......@@ -3,8 +3,9 @@
#include <string>
#include <list>
//#include "ooxtablerowspanned.h"
//#include "xlsx_table_state.h"
//#include "xlsx_drawing_context.h"
//#include "xlsx_comments_context.h"
#include "xlsx_hyperlinks.h"
namespace oox {
......@@ -29,59 +30,24 @@ public:
// void end_cell();
// std::wstring default_row_cell_style() const;
// std::wstring default_column_cell_style() const;
// void start_covered_cell();
// void end_covered_cell();
// void start_cell_content();
// int end_cell_content();
// void set_current_cell_style_id(unsigned int xfId);
// int get_current_cell_style_id();
// int current_column() const;
// int current_row() const;
//void set_table_row_group(int count, bool collapsed, int level);
// void start_row(const std::wstring & StyleName, const std::wstring & defaultCellStyleName);
// void non_empty_row();
// bool is_empty_row() const;
// void end_row();
// void start_column(unsigned int repeated, const std::wstring & defaultCellStyleName);
// size_t depth() const { return table_state_stack_.size(); }
// unsigned int columns_count();
// void serialize_merge_cells(std::wostream & _Wostream);
//void serialize_table_format(std::wostream & _Wostream);
//xlsx_table_metrics & get_table_metrics();
//
////xlsx_drawing_context & get_drawing_context();
//xlsx_drawing_context & get_drawing_context();
//// xlsx_comments_context & get_comments_context();
//xlsx_comments_context & get_comments_context();
//
// void table_column_last_width(double w);
// double table_column_last_width() const;
// xlsx_table_state & state();
// const xlsx_table_state & state() const;
// void start_hyperlink();
//std::wstring end_hyperlink(std::wstring const & ref, std::wstring const & href, std::wstring const & display);
// void dump_rels_hyperlinks(rels & Rels);
// void serialize_hyperlinks(std::wostream & _Wostream);
std::wstring add_hyperlink(std::wstring const & ref, std::wstring const & target, std::wstring const & display);
void dump_rels_hyperlinks(rels & Rels);
void serialize_hyperlinks(std::wostream & _Wostream);
private:
xlsx_conversion_context & context_;
xlsx_text_context & xlsx_text_context_;
//std::list<xlsx_table_state> table_state_stack_;
xlsx_hyperlinks xlsx_hyperlinks_;
};
......

#include "xlsx_textcontext.h"
#include "xlsx_conversion_context.h"
#include "xlsx_sharedstrings.h"
#include <iostream>
#include <list>
......
......@@ -356,6 +356,14 @@
RelativePath="..\XlsXlsxConverter\xlsx_conversion_context.h"
>
</File>
<File
RelativePath="..\XlsXlsxConverter\xlsx_hyperlinks.cpp"
>
</File>
<File
RelativePath="..\XlsXlsxConverter\xlsx_hyperlinks.h"
>
</File>
<File
RelativePath="..\XlsXlsxConverter\xlsx_output_xml.cpp"
>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment