work out how to handle worksheet rels during streaming parsing

This commit is contained in:
Thomas Fussell 2017-06-21 09:17:06 -04:00
parent a9fd6b064e
commit 72b8bd6b67
5 changed files with 492 additions and 530 deletions

View File

@ -115,6 +115,7 @@ public:
void open(std::istream &stream); void open(std::istream &stream);
private: private:
std::vector<std::string> worksheet_queue_;
std::unique_ptr<detail::xlsx_consumer> consumer_; std::unique_ptr<detail::xlsx_consumer> consumer_;
std::unique_ptr<workbook> workbook_; std::unique_ptr<workbook> workbook_;
}; };

View File

@ -108,7 +108,7 @@ std::vector<std::uint8_t> decrypt_xlsx_agile(
++segment; ++segment;
} }
decrypted_package.resize(total_size); decrypted_package.resize(static_cast<std::size_t>(total_size));
return decrypted_package; return decrypted_package;
} }
@ -153,7 +153,8 @@ encryption_info::standard_encryption_info read_standard_encryption_info(std::ist
throw xlnt::exception("invalid header"); throw xlnt::exception("invalid header");
} }
const auto csp_name_length = (header_length - (info_stream.tellg() - index_at_start)) / 2; const auto csp_name_length = static_cast<std::size_t>((header_length
- (info_stream.tellg() - index_at_start)) / 2);
auto csp_name = xlnt::detail::read_string<char16_t>(info_stream, csp_name_length); auto csp_name = xlnt::detail::read_string<char16_t>(info_stream, csp_name_length);
csp_name.pop_back(); // remove extraneous trailing null csp_name.pop_back(); // remove extraneous trailing null
if (csp_name != u"Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)" if (csp_name != u"Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"

File diff suppressed because it is too large Load Diff

View File

@ -82,16 +82,6 @@ private:
/// </summary> /// </summary>
cell read_cell(); cell read_cell();
/// <summary>
/// Ends reading of the current worksheet in the workbook and optionally
/// returns a worksheet object corresponding to the worksheet with the title
/// returned by begin_worksheet(). An exception will be thrown if this is
/// not open as a streaming consumer.
/// </summary>
worksheet end_worksheet();
bool has_worksheet();
/// <summary> /// <summary>
/// Read all the files needed from the XLSX archive and initialize all of /// Read all the files needed from the XLSX archive and initialize all of
/// the data in the workbook to match. /// the data in the workbook to match.
@ -198,27 +188,27 @@ private:
/// <summary> /// <summary>
/// xl/sheets/*.xml /// xl/sheets/*.xml
/// </summary> /// </summary>
void read_chartsheet(const std::string &title); void read_chartsheet(const std::string &rel_id);
/// <summary> /// <summary>
/// xl/sheets/*.xml /// xl/sheets/*.xml
/// </summary> /// </summary>
void read_dialogsheet(const std::string &title); void read_dialogsheet(const std::string &rel_id);
/// <summary> /// <summary>
/// xl/sheets/*.xml /// xl/sheets/*.xml
/// </summary> /// </summary>
void read_worksheet(const std::string &title); void read_worksheet(const std::string &rel_id);
/// <summary> /// <summary>
/// xl/sheets/*.xml /// xl/sheets/*.xml
/// </summary> /// </summary>
std::string read_worksheet_begin(); std::string read_worksheet_begin(const std::string &rel_id);
/// <summary> /// <summary>
/// xl/sheets/*.xml /// xl/sheets/*.xml
/// </summary> /// </summary>
void read_worksheet_end(); worksheet read_worksheet_end(const std::string &rel_id);
// Sheet Relationship Target Parts // Sheet Relationship Target Parts
@ -411,13 +401,9 @@ private:
bool preserve_space_ = false; bool preserve_space_ = false;
std::vector<relationship> worksheet_queue_;
detail::cell_impl *stream_cell_; detail::cell_impl *stream_cell_;
detail::worksheet_impl *stream_worksheet_; detail::worksheet_impl *stream_worksheet_;
bool in_sheet_data_;
}; };
} // namespace detail } // namespace detail

View File

@ -103,17 +103,20 @@ cell streaming_workbook_reader::read_cell()
bool streaming_workbook_reader::has_worksheet() bool streaming_workbook_reader::has_worksheet()
{ {
return consumer_->has_worksheet(); return !worksheet_queue_.empty();
} }
std::string streaming_workbook_reader::begin_worksheet() std::string streaming_workbook_reader::begin_worksheet()
{ {
return consumer_->read_worksheet_begin(); auto next_worksheet_rel = worksheet_queue_.back();
return consumer_->read_worksheet_begin(next_worksheet_rel);
} }
worksheet streaming_workbook_reader::end_worksheet() worksheet streaming_workbook_reader::end_worksheet()
{ {
return consumer_->end_worksheet(); auto next_worksheet_rel = worksheet_queue_.back();
worksheet_queue_.pop_back();
return consumer_->read_worksheet_end(next_worksheet_rel);
} }
void streaming_workbook_reader::open(const std::vector<std::uint8_t> &data) void streaming_workbook_reader::open(const std::vector<std::uint8_t> &data)