ExcelFile#
-
class pandas::ExcelFile#
pandas C++ class.
Example#
#include <pandas/pandas.h>
using namespace pandas;
// Use ExcelFile
ExcelFile obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
pd_excel.h:831 |
|
|
pd_excel.h:835 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
pd_excel.h:842 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
pd_excel.h:845 |
|
|
std::string |
pd_excel.h:841 |
|
|
std::string |
pd_excel.h:901 |
|
|
void |
pd_excel.h:896 |
|
|
void |
pd_excel.h:899 |
|
|
void |
pd_excel.h:900 |
|
|
void |
pd_excel.h:898 |
|
|
void |
pd_excel.h:897 |
|
|
std::string |
pd_excel.h:840 |
|
|
std::vector<std::string> |
pd_excel.h:839 |
|
|
static std::string |
pd_excel.h:902 |
Code Examples#
The following examples are extracted from the test suite.
is_open (pd_test_2_all.cpp:4092)
4082 }
4083 if (writer.datetime_format() != "YYYY-MM-DD HH:MM:SS.fff") {
4084 std::cout << " [FAIL] : datetime_format property incorrect" << std::endl;
4085 throw std::runtime_error("datetime_format property incorrect");
4086 }
4087 if (writer.if_sheet_exists() != "replace") {
4088 std::cout << " [FAIL] : if_sheet_exists property incorrect" << std::endl;
4089 throw std::runtime_error("if_sheet_exists property incorrect");
4090 }
4091
4092 if (!writer.is_open()) {
4093 std::cout << " [FAIL] : is_open should be true" << std::endl;
4094 throw std::runtime_error("is_open should be true");
4095 }
4096
4097 writer.close();
4098
4099 if (writer.is_open()) {
4100 std::cout << " [FAIL] : is_open should be false after close" << std::endl;
4101 throw std::runtime_error("is_open should be false after close");
4102 }
close (pd_test_2_all.cpp:3486)
3476 // Check ZIP signature (PK..)
3477 file.seekg(0, std::ios::beg);
3478 char sig[4];
3479 file.read(sig, 4);
3480 if (sig[0] != 'P' || sig[1] != 'K' || sig[2] != 0x03 || sig[3] != 0x04) {
3481 std::cout << " [FAIL] : in pd_test_excel_basic() : Invalid ZIP signature" << std::endl;
3482 throw std::runtime_error("pd_test_excel_basic failed: invalid ZIP signature");
3483 }
3484
3485 file.close();
3486 std::cout << " -> tests passed" << std::endl;
3487 }
3488
3489 // Test Excel export with custom sheet name
3490 void pd_test_excel_sheet_name() {
3491 std::cout << "========= Excel export with sheet name =============";
3492
3493 std::map<std::string, std::vector<double>> data = {
3494 {"X", {1.1, 2.2, 3.3}},
3495 {"Y", {4.4, 5.5, 6.6}}
engine (pd_test_2_all.cpp:4075)
4065 void pd_test_excel_writer_properties() {
4066 std::cout << "========= ExcelWriter properties ===================";
4067
4068 pandas::ExcelWriter writer("temp/test_writer_props.xlsx", "xlsxwriter",
4069 "YYYY/MM/DD", "YYYY-MM-DD HH:MM:SS.fff", "w", std::nullopt, "replace");
4070
4071 if (writer.path() != "temp/test_writer_props.xlsx") {
4072 std::cout << " [FAIL] : path property incorrect" << std::endl;
4073 throw std::runtime_error("path property incorrect");
4074 }
4075 if (writer.engine() != "xlsxwriter") {
4076 std::cout << " [FAIL] : engine property incorrect: " << writer.engine() << std::endl;
4077 throw std::runtime_error("engine property incorrect");
4078 }
4079 if (writer.date_format() != "YYYY/MM/DD") {
4080 std::cout << " [FAIL] : date_format property incorrect" << std::endl;
4081 throw std::runtime_error("date_format property incorrect");
4082 }
4083 if (writer.datetime_format() != "YYYY-MM-DD HH:MM:SS.fff") {
4084 std::cout << " [FAIL] : datetime_format property incorrect" << std::endl;
4085 throw std::runtime_error("datetime_format property incorrect");
path (pd_test_2_all.cpp:4071)
4061 std::cout << " -> tests passed" << std::endl;
4062 }
4063
4064 void pd_test_excel_writer_properties() {
4065 std::cout << "========= ExcelWriter properties ===================";
4066
4067 pandas::ExcelWriter writer("temp/test_writer_props.xlsx", "xlsxwriter",
4068 "YYYY/MM/DD", "YYYY-MM-DD HH:MM:SS.fff", "w", std::nullopt, "replace");
4069
4070 if (writer.path() != "temp/test_writer_props.xlsx") {
4071 std::cout << " [FAIL] : path property incorrect" << std::endl;
4072 throw std::runtime_error("path property incorrect");
4073 }
4074 if (writer.engine() != "xlsxwriter") {
4075 std::cout << " [FAIL] : engine property incorrect: " << writer.engine() << std::endl;
4076 throw std::runtime_error("engine property incorrect");
4077 }
4078 if (writer.date_format() != "YYYY/MM/DD") {
4079 std::cout << " [FAIL] : date_format property incorrect" << std::endl;
4080 throw std::runtime_error("date_format property incorrect");
sheet_names (pd_test_2_all.cpp:4049)
4039 pandas::ExcelWriter writer("temp/test_writer_names.xlsx");
4040
4041 std::map<std::string, std::vector<int>> data = {{"A", {1}}};
4042 pandas::DataFrame df(data);
4043
4044 df.to_excel(writer, "First");
4045 df.to_excel(writer, "Second");
4046 df.to_excel(writer, "Third");
4047
4048 auto names = writer.sheet_names();
4049 if (names.size() != 3) {
4050 std::cout << " [FAIL] : sheet_names: expected 3, got " << names.size() << std::endl;
4051 throw std::runtime_error("sheet_names: wrong count");
4052 }
4053 if (names[0] != "First" || names[1] != "Second" || names[2] != "Third") {
4054 std::cout << " [FAIL] : sheet_names: wrong order or names" << std::endl;
4055 throw std::runtime_error("sheet_names: wrong order");
4056 }
4057
4058 writer.close();