2018-08-25
01:09 AM
- last edited on
2022-11-30
10:45 AM
by
Daniel Kassai
static void Do_ExportWallsToExcel (void)
{
DBPrintf ("Exporting walls to Excel document...\n");
libxl::Book* book = xlCreateXMLBook ();
libxl::Sheet* sheet = book->addSheet (UNISTR_TO_LIBXLSTR (GS::UniString("Walls exported from Archicad")));
libxl::Font* guidFormatFont = book->addFont ();
guidFormatFont->setSize (6);
guidFormatFont->setColor (libxl::COLOR_GRAY50);
libxl::Format* guidFormat = book->addFormat ();
guidFormat->setFont (guidFormatFont);
GS::Array<GS::UniString> titles;
titles.Push ("GUID");
titles.Push ("Height");
titles.Push ("BeginCoordX");
titles.Push ("BeginCoordY");
titles.Push ("EndCoordX");
titles.Push ("EndCoordY");
for (UIndex i = 0; i < titles.GetSize (); ++i) {
sheet->writeStr (0, i, UNISTR_TO_LIBXLSTR (titles));
}
GS::Array<API_Guid> apiguids;
ACAPI_Element_GetElemList (API_WallID, &apiguids);
for (UIndex i = 0; i < apiguids.GetSize (); ++i) {
GS::Guid gsguid = APIGuid2GSGuid (apiguids);
API_Element element = {};
element.header.guid = apiguids;
GSErrCode err = ACAPI_Element_Get (&element);
if (err != NoError) {
DBPrintf ("ACAPI_Element_Get returned error (%d) for GUID '%s'\n", err,
gsguid.ToUniString ().ToCStr ().Get ());
continue;
}
API_WallType& wall = element.wall;
//DBPrintf ("GUID '%s'\n", gsguid.ToUniString ().ToCStr ().Get ());
sheet->writeStr (i + 1, 0, UNISTR_TO_LIBXLSTR (gsguid.ToUniString ()), guidFormat);
sheet->writeNum (i + 1, 1, wall.height);
sheet->writeNum (i + 1, 2, wall.begC.x);
sheet->writeNum (i + 1, 3, wall.begC.y);
sheet->writeNum (i + 1, 4, wall.endC.x);
sheet->writeNum (i + 1, 5, wall.endC.y);
}
IO::Location location;
IO::fileSystem.GetSpecialLocation (IO::FileSystem::UserDocuments, &location);
location.AppendToLocal (IO::Name ("export.xlsx"));
GS::UniString filepath;
location.ToPath (&filepath);
DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath)));
book->release ();
DBPrintf ("Export operation finished\n");
}
Solved! Go to Solution.
2018-08-27 10:56 AM
IO::Location location;
IO::fileSystem.GetSpecialLocation (IO::FileSystem::UserDocuments, &location);
location.AppendToLocal (IO::Name ("export.xlsx"));
Don't you find the "export.xlsx" file in you documentation folder after executing this operation?
2018-08-27 10:56 AM
IO::Location location;
IO::fileSystem.GetSpecialLocation (IO::FileSystem::UserDocuments, &location);
location.AppendToLocal (IO::Name ("export.xlsx"));
Don't you find the "export.xlsx" file in you documentation folder after executing this operation?
2018-08-28 09:15 AM
2018-08-28 09:42 AM
park wrote:I'm glad that you solved the issue and you can continue the AddOn development!
DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath)));
2018-08-28 07:31 PM
Tibor wrote:This is an excellent reason for anyone posting here in the Developer Forum to make clear if they are experimenting with the API using ARCHICAD in Demo mode - or if they have an API license key and are testing in a production license.
Yes, you're absolutely right. The code inside DBASSERT runs only if you built your AddOn using Debug configuration.park wrote:I'm glad that you solved the issue and you can continue the AddOn development!
DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath)));
2018-09-11 12:13 PM
2018-12-01 07:01 AM
park wrote:I get the following errors when the change mentioned is made, any suggestions why?
before
DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath)));
book->release ();
after
bool aaaa= book->save (UNISTR_TO_LIBXLSTR(filepath))
book->release();
After making the above changes, an Excel file was created in the Documents folder.