[Spreadsheet] Fix CSV import by insert
This commit is contained in:
committed by
Yorik van Havre
parent
f167e0e8ac
commit
e6a9c2e8c1
@@ -60,6 +60,7 @@ public:
|
||||
: Py::ExtensionModule<Module>("SpreadsheetGui")
|
||||
{
|
||||
add_varargs_method("open", &Module::open);
|
||||
add_varargs_method("insert", &Module::insert);
|
||||
initialize("This module is the SpreadsheetGui module."); // register with Python
|
||||
}
|
||||
|
||||
@@ -90,6 +91,32 @@ private:
|
||||
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
Py::Object insert(const Py::Tuple& args)
|
||||
{
|
||||
char* Name;
|
||||
const char* DocName = nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "et|s", "utf-8", &Name, &DocName)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
|
||||
try {
|
||||
Base::FileInfo file(EncodedName);
|
||||
App::Document* pcDoc = Gui::Application::Instance->activeDocument()->getDocument();
|
||||
Spreadsheet::Sheet* pcSheet = static_cast<Spreadsheet::Sheet*>(
|
||||
pcDoc->addObject("Spreadsheet::Sheet", file.fileNamePure().c_str()));
|
||||
|
||||
pcSheet->importFromFile(EncodedName, '\t', '"', '\\');
|
||||
pcSheet->execute();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
throw Py::RuntimeError(e.what());
|
||||
}
|
||||
|
||||
return Py::None();
|
||||
}
|
||||
};
|
||||
|
||||
PyObject* initModule()
|
||||
|
||||
Reference in New Issue
Block a user