/
Puzzman
/
setPointMap
Обзор
Документация
Войти
/
Puzzman
/
setPointMap
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
scripts/libs/classes/class_ExportToXML.ctl
218 строк
10 KB
Sergey
refactor
12 май 2025, 16:11
12 май 2025, 16:11
8c27993
Код
Авторство
О чём код?
#uses "scadMsg_Messages" #uses "CtrlXml" #uses "classes/Structures.ctl" class ExportToXML { defaultParametrsForsetPointMap paramSetPointMap; private string PATH = paramSetPointMap.pathToSave; private shared_ptr<StateTab> tab_ = nullptr; private dyn_anytype Tab_; private int doc_num_, worksheet_; private string mame_file_; private int node_main_; public ExportToXML(dyn_anytype Tab, string mame_file) { Tab_ = Tab; mame_file_ = mame_file; doc_num_ = xmlNewDocument(); CreateXMLDocument(); } private CreateXMLDocument() { CreateHeader(); for (int i = 1; i <= dynlen(Tab_); ++i) { CreateTable(Tab_[i]); CreateFooter(); // break; } SaveToFile(); } private CreateHeader() { xmlAppendChild(doc_num_, -1, XML_PROCESSING_INSTRUCTION_NODE, "xml version=\"1.0\""); xmlAppendChild(doc_num_, -1, XML_PROCESSING_INSTRUCTION_NODE, "mso-application progid=\"Excel.Sheet\""); node_main_ = xmlAppendChild(doc_num_, -1, XML_ELEMENT_NODE, "Workbook"); xmlSetElementAttribute(doc_num_, node_main_, "xmlns", "urn:schemas-microsoft-com:office:spreadsheet"); xmlSetElementAttribute(doc_num_, node_main_, "xmlns:o", "urn:schemas-microsoft-com:office:office"); xmlSetElementAttribute(doc_num_, node_main_, "xmlns:x", "urn:schemas-microsoft-com:office:excel"); xmlSetElementAttribute(doc_num_, node_main_, "xmlns:ss", "urn:schemas-microsoft-com:office:spreadsheet"); xmlSetElementAttribute(doc_num_, node_main_, "xmlns:html", "http://www.w3.org/TR/REC-html40"); int node = xmlAppendChild(doc_num_, node_main_, XML_ELEMENT_NODE, "OfficeDocumentSettings"); xmlSetElementAttribute(doc_num_, node, "xmlns", "urn:schemas-microsoft-com:office:office"); xmlAppendChild(doc_num_, node, XML_ELEMENT_NODE, "AllowPNG"); node = xmlAppendChild(doc_num_, node_main_, XML_ELEMENT_NODE, "Styles"); int node2 = xmlAppendChild(doc_num_, node, XML_ELEMENT_NODE, "Style"); xmlSetElementAttribute(doc_num_, node2, "ss:ID", "Default"); xmlSetElementAttribute(doc_num_, node2, "ss:Name", "Normal"); int node3 = xmlAppendChild(doc_num_, node2, XML_ELEMENT_NODE, "Alignment"); xmlSetElementAttribute(doc_num_, node3, "ss:Vertical", "Bottom"); node3 = xmlAppendChild(doc_num_, node2, XML_ELEMENT_NODE, "Borders"); node3 = xmlAppendChild(doc_num_, node2, XML_ELEMENT_NODE, "Font"); xmlSetElementAttribute(doc_num_, node3, "ss:FontName", "Calibri"); xmlSetElementAttribute(doc_num_, node3, "x:CharSet", "204"); xmlSetElementAttribute(doc_num_, node3, "x:Family", "Swiss"); xmlSetElementAttribute(doc_num_, node3, "ss:Size", "11"); xmlAppendChild(doc_num_, node2, XML_ELEMENT_NODE, "NumberFormat"); xmlAppendChild(doc_num_, node2, XML_ELEMENT_NODE, "Protection"); node3 = xmlAppendChild(doc_num_, node, XML_ELEMENT_NODE, "Style"); xmlSetElementAttribute(doc_num_, node3, "ss:ID", "s102"); int node4 = xmlAppendChild(doc_num_, node3, XML_ELEMENT_NODE, "Alignment"); xmlSetElementAttribute(doc_num_, node4, "ss:Horizontal", "Center"); xmlSetElementAttribute(doc_num_, node4, "ss:Vertical", "Bottom"); node3 = xmlAppendChild(doc_num_, node, XML_ELEMENT_NODE, "Style"); xmlSetElementAttribute(doc_num_, node3, "ss:ID", "s103"); int node4 = xmlAppendChild(doc_num_, node3, XML_ELEMENT_NODE, "Alignment"); xmlSetElementAttribute(doc_num_, node4, "ss:Horizontal", "Left"); xmlSetElementAttribute(doc_num_, node4, "ss:Vertical", "Bottom"); node3 = xmlAppendChild(doc_num_, node, XML_ELEMENT_NODE, "Style"); xmlSetElementAttribute(doc_num_, node3, "ss:ID", "s104"); int node4 = xmlAppendChild(doc_num_, node3, XML_ELEMENT_NODE, "Interior"); xmlSetElementAttribute(doc_num_, node4, "ss:Color", "#F2F2F2"); xmlSetElementAttribute(doc_num_, node4, "ss:Pattern", "Solid"); node4 = xmlAppendChild(doc_num_, node3, XML_ELEMENT_NODE, "Alignment"); xmlSetElementAttribute(doc_num_, node4, "ss:Horizontal", "Center"); xmlSetElementAttribute(doc_num_, node4, "ss:Vertical", "Bottom"); node3 = xmlAppendChild(doc_num_, node, XML_ELEMENT_NODE, "Style"); xmlSetElementAttribute(doc_num_, node3, "ss:ID", "s105"); int node4 = xmlAppendChild(doc_num_, node3, XML_ELEMENT_NODE, "Interior"); xmlSetElementAttribute(doc_num_, node4, "ss:Color", "#F2F2F2"); xmlSetElementAttribute(doc_num_, node4, "ss:Pattern", "Solid"); node4 = xmlAppendChild(doc_num_, node3, XML_ELEMENT_NODE, "Alignment"); xmlSetElementAttribute(doc_num_, node4, "ss:Horizontal", "Left"); xmlSetElementAttribute(doc_num_, node4, "ss:Vertical", "Bottom"); } private CreateFooter() { int node = xmlAppendChild(doc_num_, worksheet_, XML_ELEMENT_NODE, "WorksheetOptions"); xmlSetElementAttribute(doc_num_, node, "xmlns", "urn:schemas-microsoft-com:office:excel"); int node1 = xmlAppendChild(doc_num_, node, XML_ELEMENT_NODE, "PageSetup"); int node2 = xmlAppendChild(doc_num_, node1, XML_ELEMENT_NODE, "Header"); xmlSetElementAttribute(doc_num_, node2, "x:Margin", "0.3"); node2 = xmlAppendChild(doc_num_, node1, XML_ELEMENT_NODE, "Footer"); xmlSetElementAttribute(doc_num_, node2, "x:Margin", "0.3"); node2 = xmlAppendChild(doc_num_, node1, XML_ELEMENT_NODE, "PageMargins"); xmlSetElementAttribute(doc_num_, node2, "x:Bottom", "0.75"); xmlSetElementAttribute(doc_num_, node2, "x:Left", "0.7"); xmlSetElementAttribute(doc_num_, node2, "x:Right", "0.7"); xmlSetElementAttribute(doc_num_, node2, "x:Top", "0.75"); xmlAppendChild(doc_num_, node2, XML_ELEMENT_NODE, "Selected"); node2 = xmlAppendChild(doc_num_, node, XML_ELEMENT_NODE, "ProtectObjects"); xmlAppendChild(doc_num_, node2, XML_TEXT_NODE, "False"); node2 = xmlAppendChild(doc_num_, node, XML_ELEMENT_NODE, "ProtectScenarios"); xmlAppendChild(doc_num_, node2, XML_TEXT_NODE, "False"); } private CreateTable(shared_ptr<StateTab> tab_) { shape t = tab_.classTable.get_table(); int column = t.columnCount(); int row = t.lineCount(); worksheet_ = xmlAppendChild(doc_num_, node_main_, XML_ELEMENT_NODE, "Worksheet"); xmlSetElementAttribute(doc_num_, worksheet_, "ss:Name", tab_.title); int node1 = xmlAppendChild(doc_num_, worksheet_, XML_ELEMENT_NODE, "Table"); xmlSetElementAttribute(doc_num_, node1, "ss:ExpandedColumnCount", column - 1); xmlSetElementAttribute(doc_num_, node1, "ss:ExpandedRowCount", row+1); xmlSetElementAttribute(doc_num_, node1, "x:FullColumns", "1"); xmlSetElementAttribute(doc_num_, node1, "x:FullRows", "1"); xmlSetElementAttribute(doc_num_, node1, "ss:DefaultRowHeight", "15"); int width; getValue (t.name, "columnWidth",0, width); int node2 = xmlAppendChild(doc_num_, node1, XML_ELEMENT_NODE, "Column"); xmlSetElementAttribute(doc_num_, node2, "ss:StyleID", "s102"); xmlSetElementAttribute(doc_num_, node2, "ss:Width", width); getValue (t.name, "columnWidth",1, width); node2 = xmlAppendChild(doc_num_, node1, XML_ELEMENT_NODE, "Column"); xmlSetElementAttribute(doc_num_, node2, "ss:StyleID", "s103"); xmlSetElementAttribute(doc_num_, node2, "ss:Width", (float)width*1.1); getValue (t.name, "columnWidth",2, width); node2 = xmlAppendChild(doc_num_, node1, XML_ELEMENT_NODE, "Column"); xmlSetElementAttribute(doc_num_, node2, "ss:StyleID", "s102"); xmlSetElementAttribute(doc_num_, node2, "ss:Width", width); getValue (t.name, "columnWidth",3, width); node2 = xmlAppendChild(doc_num_, node1, XML_ELEMENT_NODE, "Column"); xmlSetElementAttribute(doc_num_, node2, "ss:StyleID", "s102"); xmlSetElementAttribute(doc_num_, node2, "ss:Width", width); int node2 = xmlAppendChild(doc_num_, node1, XML_ELEMENT_NODE, "Column"); xmlSetElementAttribute(doc_num_, node2, "ss:StyleID", "s102"); xmlSetElementAttribute(doc_num_, node2, "ss:Width", 100); xmlSetElementAttribute(doc_num_, node2, "ss:Span", column - 6); insertColumnName(row, column, t, node1); for (int j = 0; j < row; ++j) { int node2 = xmlAppendChild(doc_num_, node1, XML_ELEMENT_NODE, "Row"); for (int k = 0; k < column - 1; ++k) { int node3 = xmlAppendChild(doc_num_, node2, XML_ELEMENT_NODE, "Cell"); if (j % 2 == 0) { if (k == 1) {xmlSetElementAttribute(doc_num_, node3, "ss:StyleID", "s105");} else {xmlSetElementAttribute(doc_num_, node3, "ss:StyleID", "s104");} } int node4 = xmlAppendChild(doc_num_, node3, XML_ELEMENT_NODE, "Data"); xmlSetElementAttribute(doc_num_, node4, "ss:Type", "String"); string data = ""; getValue (t.name, "cellValueRC", j, t.columnToName(k), data); xmlAppendChild(doc_num_, node4, XML_TEXT_NODE, data); } } } private insertColumnName(int row, int column, shape &t, int node1) { int node2 = xmlAppendChild(doc_num_, node1, XML_ELEMENT_NODE, "Row"); for (int k = 0; k < column - 1; ++k) { int node3 = xmlAppendChild(doc_num_, node2, XML_ELEMENT_NODE, "Cell"); int node4 = xmlAppendChild(doc_num_, node3, XML_ELEMENT_NODE, "Data"); xmlSetElementAttribute(doc_num_, node4, "ss:Type", "String"); string data; getValue (t.name, "columnHeader", k, data); DebugN(data); xmlAppendChild(doc_num_, node4, XML_TEXT_NODE, data); } } private SaveToFile() { file f; string file_name = PATH + mame_file_ + " (" + formatTime("%Y.%m.%d_%H-%M-%S", getCurrentTime()) + ").xml"; //bool result = mkdir(dir, "777"); //создаем директорию f = fopen(file_name, "w"); fclose(f); xmlDocumentToFile(doc_num_, file_name); //int err = zipFiles(makeDynString(file_name), PATH + "Export.zip"); string msg = mame_file_ +" успешно экспортирована в директорию " + PATH; openInformationPanel(makeDynString("$sInformation:" + msg + "", "$iTimer:0", "$bCritical:false"), "-1", "-1"); CreateMultiInstanceMessage("Произведен экспорт карты уставок пользователем " + getUserName() + " в директорию " + PATH, "", "armMessages_10", "armMessages_10", getHostname()); } ~ExportToXML() { DebugN("close Document"); xmlCloseDocument(doc_num_); } };