temporary_file.hpp 626 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include <array>
  3. #include <cstdio>
  4. #include <string>
  5. #include <detail/external/include_windows.hpp>
  6. #include <helpers/path_helper.hpp>
  7. namespace {
  8. static std::string create_temporary_filename()
  9. {
  10. return "temp.xlsx";
  11. }
  12. } // namespace
  13. class temporary_file
  14. {
  15. public:
  16. temporary_file() : path_(create_temporary_filename())
  17. {
  18. if(path_.exists())
  19. {
  20. std::remove(path_.string().c_str());
  21. }
  22. }
  23. ~temporary_file()
  24. {
  25. std::remove(path_.string().c_str());
  26. }
  27. xlnt::path get_path() const { return path_; }
  28. private:
  29. const xlnt::path path_;
  30. };