commit 79085484b0b15f1da5195825418303c6720d5b1b Author: taynpg Date: Tue Jan 14 12:36:26 2025 +0800 init:初版可用 diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..402f22e --- /dev/null +++ b/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +PointerAlignment: Left +AccessModifierOffset: -4 +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + AfterClass: true +Cpp11BracedListStyle: true +ReflowComments: true +SpacesBeforeTrailingComments: 3 +TabWidth: 4 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ColumnLimit: 80 +AllowShortBlocksOnASingleLine: Never +AllowShortFunctionsOnASingleLine: None +AllowShortEnumsOnASingleLine: false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b861d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build +.vs +.cache +cmake-* \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f5e7bbc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ofen"] + path = ofen + url = https://www.sinxmiao.cn/taynpg/ofen diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e042de7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,110 @@ +{ + "files.autoSave": "onFocusChange", + "editor.fontSize": 14, + "editor.fontFamily": "'Source Code Pro', 'Courier New', monospace", + "terminal.integrated.fontFamily": "Source Code Pro", + "cmake.configureOnOpen": true, + "cmake.debugConfig": { + "console": "integratedTerminal", + "setupCommands": [ + { + "description": "-gdb-set charset utf-8", + "text": "-gdb-set charset UTF-8" + }, + { + "description": "Enable gdb pretty-printing", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "args": [ + ] + }, + "cmake.configureSettings": { + "CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + }, + "cmake.options.statusBarVisibility": "visible", + "cmake.generator": "Ninja", + "C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json", + "C_Cpp.default.cppStandard": "c++17", + "editor.inlayHints.enabled": "off", + "editor.unicodeHighlight.allowedLocales": { + "ja": true, + "zh-hant": true, + "zh-hans": true + }, + "files.associations": { + "vector": "cpp", + "algorithm": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "deque": "cpp", + "exception": "cpp", + "filesystem": "cpp", + "format": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "functional": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "queue": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "utility": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8389024 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.16) + +project(rbs_tool LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if (MSVC) + add_compile_options(/source-charset:utf-8) +endif() + +message(STATUS "System: ${CMAKE_SYSTEM_NAME}") +message(STATUS "Compiler CXX ID: ${CMAKE_CXX_COMPILER_ID}") +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/) + +if (MSVC) + find_package(Xlnt CONFIG REQUIRED) +endif() + +add_subdirectory(ofen) +add_executable(rbs_tool main.cpp) +target_link_libraries(rbs_tool PRIVATE ofen) +if (MSVC) + target_link_libraries(rbs_tool PRIVATE xlnt::xlnt) +else() + target_link_libraries(rbs_tool PRIVATE xlnt) +endif() \ No newline at end of file diff --git a/REAME.md b/REAME.md new file mode 100644 index 0000000..4e05bbf --- /dev/null +++ b/REAME.md @@ -0,0 +1,5 @@ +# 简介 + +命令行第二个参数,输入一个`xlsx`文件,输出在程序所在目录下。 + +当前程序默认操作第一张表。 \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e48ea98 --- /dev/null +++ b/main.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include + +namespace fs = std::filesystem; +int main(int argc, char* argv[]) +{ + if (argc < 2) { + std::cout << "Second arg is xlsx file path." << std::endl; + return 0; + } + std::string input_file(argv[1]); + std::string full_path = ofen::COfPath::to_full(input_file); + std::cout << "Load File:" << full_path << std::endl; + + if (!fs::exists(full_path)) { + std::cerr << "File not found." << std::endl; + return -1; + } + + std::string file_name = fs::path(full_path).filename().string(); + std::string out_file_name = ofen::COfStr::get_ofile_name(file_name); + try { + xlnt::workbook wb; + wb.load(full_path); + xlnt::workbook wb_out; + xlnt::worksheet ws_out = wb_out.active_sheet(); + + std::cout << "Sheets in the workbook:" << std::endl; + for (const auto& sheet_name : wb.sheet_titles()) { + std::cout << " - " << sheet_name << std::endl; + } + std::string sheet_name = wb.sheet_titles().front(); + xlnt::worksheet ws = wb.sheet_by_title(sheet_name); + + auto rows = ws.highest_row(); + auto columns = ws.highest_column().index; + std::cout << "Sheet: " << sheet_name << " has " << rows << " rows and " + << columns << " columns." << std::endl; + + for (std::uint32_t i = 0; i < rows; ++i) { + for (std::uint32_t j = 0; j < columns; ++j) { + auto cell = ws.cell(j + 1, i + 1); + if (cell.has_value()) { + std::string cur = cell.to_string(); + auto ret = ofen::CCodec::rbs(cur); + ws_out.cell(j + 1, i + 1).value(ret); + } + } + } + wb_out.save(out_file_name); + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + std::cout << "Done" << std::endl; + return 0; +} \ No newline at end of file diff --git a/ofen b/ofen new file mode 160000 index 0000000..2be0e96 --- /dev/null +++ b/ofen @@ -0,0 +1 @@ +Subproject commit 2be0e9631729cf85e79b23fb921209182e0907be