initial implementation of wstring filenames

This commit is contained in:
Thomas Fussell 2016-10-30 21:17:51 -04:00
parent 72c6569020
commit 012dd0984e
4 changed files with 34 additions and 13 deletions

View File

@ -365,11 +365,19 @@ public:
void load(const xlnt::path &filename);
void load(std::istream &stream);
void load(const std::string &filename, const std::string &password);
void load(const std::string &filename, const std::string &password);
void load(const xlnt::path &filename, const std::string &password);
void load(std::istream &stream, const std::string &password);
void load(const std::vector<std::uint8_t> &data, const std::string &password);
#ifdef WIN32
void save(const std::wstring &filename);
void save(const std::wstring &filename, const std::string &password);
void load(const std::wstring &filename);
void load(const std::wstring &filename, const std::string &password);
#endif
bool has_view() const;
workbook_view get_view() const;
void set_view(const workbook_view &view);

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <fstream>
#include <iostream>
@ -7,7 +7,7 @@
#include <helpers/path_helper.hpp>
#include <xlnt/workbook/workbook.hpp>
#define TEST_CRYPTO true
#define TEST_CRYPTO false
#ifndef TEST_CRYPTO
#define TEST_CRYPTO false
@ -64,4 +64,10 @@ public:
TS_ASSERT_EQUALS(sheet2.get_cell("A1").comment().plain_text(), "Sheet2 comment");
TS_ASSERT_EQUALS(sheet2.get_cell("A1").comment().author(), "Microsoft Office User");
}
void test_read_unicode_filename()
{
xlnt::workbook wb;
wb.load(L"data\\19_unicode_Λ.xlsx");
}
};

View File

@ -686,11 +686,9 @@ void workbook::load(std::istream &stream)
void workbook::load(const std::vector<std::uint8_t> &data)
{
clear();
detail::xlsx_consumer consumer(*this);
xlnt::detail::vector_istreambuf data_buffer(data);
std::istream data_stream(&data_buffer);
consumer.read(data_stream);
load(data_stream);
}
void workbook::load(const std::string &filename)
@ -700,10 +698,8 @@ void workbook::load(const std::string &filename)
void workbook::load(const path &filename)
{
clear();
detail::xlsx_consumer consumer(*this);
std::ifstream file_stream(filename.string(), std::ios::binary);
consumer.read(file_stream);
load(file_stream);
}
void workbook::load(const std::string &filename, const std::string &password)
@ -719,11 +715,9 @@ void workbook::load(const path &filename, const std::string &password)
void workbook::load(const std::vector<std::uint8_t> &data, const std::string &password)
{
clear();
detail::xlsx_consumer consumer(*this);
xlnt::detail::vector_istreambuf data_buffer(data);
std::istream data_stream(&data_buffer);
consumer.read(data_stream, password);
load(data_stream, password);
}
void workbook::load(std::istream &stream, const std::string &password)
@ -747,7 +741,6 @@ void workbook::save(const std::string &filename) const
void workbook::save(const path &filename) const
{
detail::xlsx_producer producer(*this);
std::ofstream file_stream(filename.string(), std::ios::binary);
save(file_stream);
}
@ -758,6 +751,20 @@ void workbook::save(std::ostream &stream) const
producer.write(stream);
}
#ifdef WIN32
void workbook::save(const std::wstring &filename)
{
std::ofstream file_stream(filename, std::ios::binary);
save(file_stream);
}
void workbook::load(const std::wstring &filename)
{
std::ifstream file_stream(filename, std::ios::binary);
load(file_stream);
}
#endif
void workbook::set_guess_types(bool guess)
{
d_->guess_types_ = guess;

Binary file not shown.