Guest User

Untitled

a guest
Jun 9th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <xlnt/xlnt.hpp>
  4. #include <windows.h>
  5.  
  6. static std::string utf8_to_ansi(const std::string &utf8)
  7. {
  8.     WCHAR unicode[1500];
  9.     char ansi[1500];
  10.  
  11.     memset(unicode, 0, sizeof(unicode));
  12.     memset(ansi, 0, sizeof(ansi));
  13.  
  14.     ::MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, unicode, sizeof(unicode));
  15.     ::WideCharToMultiByte(CP_ACP, 0, unicode, -1, ansi, sizeof(ansi), NULL, NULL);
  16.  
  17.     return std::string(ansi);
  18. }
  19.  
  20.  
  21. int
  22. main()
  23. {
  24.     xlnt::workbook wb;
  25.     wb.load("d:/test.xlsx");
  26.     auto ws = wb.active_sheet();
  27.     std::cout << "Processing spread sheet" << std::endl;
  28.     for (const auto& row : ws.rows(false)) {
  29.         for (const auto& cell : row) {
  30.             const auto utf8_encoded = cell.to_string();
  31.             std::cout << utf8_to_ansi(utf8_encoded) << std::endl;
  32.         }
  33.     }
  34.     std::cout << "Processing complete " << std::endl;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment