MCPcopy Create free account
hub / github.com/NatLabRockies/SAM / SendToExcel

Method SendToExcel

src/parametric.cpp:1506–1576  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1504}
1505
1506void ParametricViewer::SendToExcel()
1507{
1508 wxBusyInfo busy("Processing data table... please wait");
1509
1510#ifdef __WXMSW__
1511 wxExcelAutomation xl;
1512 if (!xl.StartExcel())
1513 {
1514 wxMessageBox("Could not start Excel.");
1515 return;
1516 }
1517
1518 xl.Show(true);
1519
1520 if (!xl.NewWorkbook())
1521 {
1522 wxMessageBox("Could not create a new Excel worksheet.");
1523 return;
1524 }
1525
1526 for (int col = m_grid_data->GetNumberCols()-1; col >= 0; col--) { // reorder to match list of Excel sheets with parametric table
1527 if (VarValue* vv = m_grid_data->GetVarValue(0, col)) {
1528 wxString sheetName = m_grid_data->GetColLabelValue(col).ToAscii(' ');
1529 // valid sheet names - no \ / ? * [ ] and 31 characters max
1530 sheetName.Replace("\\", "_");
1531 sheetName.Replace("/", "_");
1532 sheetName.Replace("?", "_");
1533 sheetName.Replace("*", "_");
1534 sheetName.Replace("[", "_");
1535 sheetName.Replace("]", "_");
1536 if (m_grid_data->IsInput(col)) sheetName = "IN_" + sheetName;
1537 sheetName = sheetName.Left(31);
1538
1539 if (vv->Type() == VV_STRING) {
1540 wxString header = "Index\t";
1541 wxString dat = "0\t";
1542 for (int row = 0; row < m_grid_data->GetNumberRows(); row++) {
1543 header += wxString::Format("Run %d", row + 1);
1544 dat += m_grid_data->GetValue(row, col);
1545 if (row < m_grid_data->GetNumberRows() - 1) {
1546 header += '\t';
1547 dat += '\t';
1548 }
1549 else {
1550 header += '\n';
1551 dat += '\n';
1552 }
1553 }
1554 dat = header + dat;
1555 dat.Replace(",", "");
1556 xl.PasteNewWorksheet(sheetName, dat);
1557 }
1558 else {
1559 std::vector<std::vector<double> > values_vec;
1560 wxArrayString labels;
1561 for (int row = 0; row < m_grid_data->GetNumberRows(); row++)
1562 {
1563 std::vector<double> vec = m_grid_data->GetArray(row, col);

Callers

nothing calls this directly

Calls 12

IsInputMethod · 0.80
TypeMethod · 0.80
sizeMethod · 0.80
SendToExcelSheetMethod · 0.80
ShowMethod · 0.45
GetNumberColsMethod · 0.45
GetVarValueMethod · 0.45
GetColLabelValueMethod · 0.45
GetNumberRowsMethod · 0.45
GetValueMethod · 0.45
GetArrayMethod · 0.45
GetDoubleMethod · 0.45

Tested by

no test coverage detected