Giter Club home page Giter Club logo

xlsx_reader's Introduction

xlsx_reader 读取excel xlsx文件的工具

功能

可以读取xlsx文件的文本内容,到自定义的容器之中,这个容器中的数据可以导出为json。 还支持带schema的文本读取与验证,这个schema由https://github.com/huangfeidian/typed_string定义。

依赖

  1. c++ 17
  2. tinyxml2 https://github.com/leethomason/tinyxml2
  3. miniz https://github.com/richgel999/miniz
  4. json https://github.com/nlohmann/json
  5. typed_string https://github.com/huangfeidian/typed_string

使用

参考test文件夹下的两个文件。整个工作流程分为了如下几步:

  1. 通过xlsx文件路径加载zip文件, 因为xlsx文件其实就是zip文件
  2. 将zip文件解析为workbook,主要是解析shared_string, 当前的解析比较简单,可能有不完备的地方,欢迎提bug
  3. 解析完workbook之后,根据记录的每个sheet再去解析
  4. 如果是带格式的worksheet,还提供了一些函数去转换格式化字符串 下面就是一个参考的代码
string file_name = "../examples/pi100000.xlsx";
int wait = 0;
cout << "size of typed value is " << sizeof(arena_typed_value) << endl;
auto archive_content = make_shared<archive>(file_name);
cout << "press any key to load the xlsx file" << endl;
cin >> wait;
workbook<typed_worksheet> current_workbook(archive_content);


cout << "press any key to show memory statistics" << endl;
cin >> wait;
for (const auto& one_sheet : current_workbook._worksheets)
{
    cout << "worksheet " << one_sheet->get_name() << " memory consumption is " << one_sheet->memory_consumption() << endl;
}
auto sheet_idx_opt = current_workbook.get_sheet_index_by_name("tile_1");
const typed_worksheet& cur_worksheet = current_workbook.get_worksheet(sheet_idx_opt.value());
vector<string_view> header_names = { "tile_id", "circle_id", "width", "sequence", "ref_color", "opacity", "filled" };
vector<uint32_t> header_indexes = cur_worksheet.get_header_index_vector(header_names);
for (std::uint32_t i = 0; i < header_names.size(); i++)
{
    std::cout << "head " << header_names[i] << " at " << header_indexes[i] << endl;
}
auto row_convert_result = cur_worksheet.try_convert_row<string_view, string_view, int, int, string_view, float, bool>(1, header_indexes);
auto [opt_tile_id, opt_circle_id, opt_width, opt_seq, opt_ref_color, opt_opacity, opt_filled] = row_convert_result;

xlsx_reader's People

Contributors

huangfeidian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

xlsx_reader's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.