static void example4(const char* path) { BasicExcel xls; xls.New(1); BasicExcelWorksheet* sheet = xls.GetWorksheet(0); XLSFormatManager fmt_mgr(xls); char buffer[100]; int i = 0; for(int row=0; row<8; ++row) { int color = i++; int height = 100 * i; sprintf(buffer, "Times New Roman %d", height/20); ExcelFont font; font.set_color_index(color); font.set_height(height); font.set_font_name(L"Times New Roman"); CellFormat fmt(fmt_mgr, font); fmt.set_background(MAKE_COLOR2(EGA_MAGENTA,0)); // solid magenta background BasicExcelCell* cell = sheet->Cell(row, 0); cell->Set(buffer); cell->SetFormat(fmt); } xls.SaveAs(path); }
static void example1(const char* path) { BasicExcel xls; // create sheet 1 and get the associated BasicExcelWorksheet pointer xls.New(1); BasicExcelWorksheet* sheet = xls.GetWorksheet(0); XLSFormatManager fmt_mgr(xls); // Create a table containing an header row in bold and four rows below. ExcelFont font_bold; font_bold._weight = FW_BOLD; // 700 CellFormat fmt_bold(fmt_mgr); fmt_bold.set_font(font_bold); int col, row = 0; for(col=0; col<10; ++col) { BasicExcelCell* cell = sheet->Cell(row, col); cell->Set("TITLE"); cell->SetFormat(fmt_bold); } while(++row < 4) { for(int col=0; col<10; ++col) sheet->Cell(row, col)->Set("text"); } ++row; ExcelFont font_red_bold; font_red_bold._weight = FW_BOLD; font_red_bold._color_index = EGA_RED; CellFormat fmt_red_bold(fmt_mgr, font_red_bold); fmt_red_bold.set_color1(COLOR1_PAT_SOLID); // solid background fmt_red_bold.set_color2(MAKE_COLOR2(EGA_BLUE,0)); // blue background CellFormat fmt_green(fmt_mgr, ExcelFont().set_color_index(EGA_GREEN)); for(col=0; col<10; ++col) { BasicExcelCell* cell = sheet->Cell(row, col); cell->Set("xxx"); cell->SetFormat(fmt_red_bold); cell = sheet->Cell(row, ++col); cell->Set("yyy"); cell->SetFormat(fmt_green); } xls.SaveAs(path); }
int main() { BasicExcel xls; // create sheet 1 and get the associated BasicExcelWorksheet pointer xls.New(1); xls.workbook_.definedName_.setName("shit"); BasicExcelWorksheet* sheet = xls.GetWorksheet(0); XLSFormatManager fmt_mgr(xls); ExcelFont font_header; font_header.set_weight(FW_BOLD); font_header.set_underline_type(EXCEL_UNDERLINE_SINGLE); font_header.set_font_name(L"Times New Roman"); font_header.set_color_index(EGA_BLUE); font_header._options = EXCEL_FONT_STRUCK_OUT; CellFormat fmt_header(fmt_mgr, font_header); fmt_header.set_rotation(30); // rotate the header cell text 30?to the left int row = 0; for(int col=0; col<10; ++col) { BasicExcelCell* cell = sheet->Cell(row, col); cell->Set("TITLE"); cell->SetFormat(fmt_header); } char buffer[100]; while(++row < 10) { for(int col=0; col<10; ++col) { sprintf(buffer, "text %d/%d", row, col); sheet->Cell(row, col)->Set(buffer); } } xls.SaveAs("fasdf.xls"); xls.Close(); }
static void example_read_write(const char* from, const char* to) { cout << "read " << from << endl; BasicExcel xls(from); XLSFormatManager fmt_mgr(xls); BasicExcelWorksheet* sheet = xls.GetWorksheet(0); CellFormat fmt_general(fmt_mgr); fmt_general.set_format_string("0.000"); for(int y=0; y<2; ++y) { for(int x=0; x<2; ++x) { cout << y << "/" << x; BasicExcelCell* cell = sheet->Cell(y, x); CellFormat fmt(fmt_mgr, cell); // cout << " - xf_idx=" << cell->GetXFormatIdx(); const Workbook::Font& font = fmt_mgr.get_font(fmt); string font_name = stringFromSmallString(font.name_); cout << " font name: " << font_name; const wstring& fmt_string = fmt.get_format_string(); cout << " format: " << narrow_string(fmt_string); cell->SetFormat(fmt_general); cout << endl; } } cout << "write: " << from << endl; xls.SaveAs(to); }
static void write_big_sheet(const char* path, const int row_max, const int col_max) { BasicExcel xls; char buffer[16]; // create sheet 1 and get the associated BasicExcelWorksheet pointer xls.New(1); BasicExcelWorksheet* sheet = xls.GetWorksheet(0); XLSFormatManager fmt_mgr(xls); // Create a table containing header row and column in bold. ExcelFont font_bold; font_bold._weight = FW_BOLD; // 700 CellFormat fmt_bold(fmt_mgr); fmt_bold.set_font(font_bold); int col, row; BasicExcelCell* cell = sheet->Cell(0, 0); cell->Set("Row / Column"); cell->SetFormat(fmt_bold); for(col=1; col<=col_max; ++col) { cell = sheet->Cell(0, col); sprintf(buffer, "Column %d", col); cell->Set(buffer); cell->SetFormat(fmt_bold); } for(row=1; row<=row_max; ++row) { cell = sheet->Cell(row, 0); sprintf(buffer, "Row %d", row); cell->Set(buffer); cell->SetFormat(fmt_bold); } for(row=1; row<=row_max; ++row) { for(int col=1; col<=col_max; ++col) { sprintf(buffer, "%d / %d", row, col); sheet->Cell(row, col)->Set(buffer); } } xls.SaveAs(path); }
int main(int argc, char* argv[]) { BasicExcel e; // Load a workbook with one sheet, display its contents and save into another file. e.Load("example1.xls"); BasicExcelWorksheet* sheet1 = e.GetWorksheet("Sheet1"); if (sheet1) { size_t maxRows = sheet1->GetTotalRows(); size_t maxCols = sheet1->GetTotalCols(); cout << "Dimension of " << sheet1->GetAnsiSheetName() << " (" << maxRows << ", " << maxCols << ")" << endl; printf(" "); for (size_t c=0; c<maxCols; ++c) printf("%10d", c+1); cout << endl; for (size_t r=0; r<maxRows; ++r) { printf("%10d", r+1); for (size_t c=0; c<maxCols; ++c) { BasicExcelCell* cell = sheet1->Cell(r,c); switch (cell->Type()) { case BasicExcelCell::UNDEFINED: printf(" "); break; case BasicExcelCell::INT: printf("%10d", cell->GetInteger()); break; case BasicExcelCell::DOUBLE: printf("%10.6lf", cell->GetDouble()); break; case BasicExcelCell::STRING: printf("%10s", cell->GetString()); break; case BasicExcelCell::WSTRING: wprintf(L"%10s", cell->GetWString()); break; } } cout << endl; } } cout << endl; e.SaveAs("example2.xls"); // Create a new workbook with 2 worksheets and write some contents. e.New(2); e.RenameWorksheet("Sheet1", "Test1"); BasicExcelWorksheet* sheet = e.GetWorksheet("Test1"); BasicExcelCell* cell; if (sheet) { for (size_t c=0; c<4; ++c) { cell = sheet->Cell(0,c); cell->Set((int)c); } cell = sheet->Cell(1,3); cell->SetDouble(3.141592654); sheet->Cell(1,4)->SetString("Test str1"); sheet->Cell(2,0)->SetString("Test str2"); sheet->Cell(2,5)->SetString("Test str1"); sheet->Cell(4,0)->SetDouble(1.1); sheet->Cell(4,1)->SetDouble(2.2); sheet->Cell(4,2)->SetDouble(3.3); sheet->Cell(4,3)->SetDouble(4.4); sheet->Cell(4,4)->SetDouble(5.5); sheet->Cell(4,4)->EraseContents(); } sheet = e.AddWorksheet("Test2", 1); sheet = e.GetWorksheet(1); if (sheet) { sheet->Cell(1,1)->SetDouble(1.1); sheet->Cell(2,2)->SetDouble(2.2); sheet->Cell(3,3)->SetDouble(3.3); sheet->Cell(4,4)->SetDouble(4.4); sheet->Cell(70,2)->SetDouble(5.5); } e.SaveAs("example3.xls"); // Load the newly created sheet and display its contents e.Load("example3.xls"); size_t maxSheets = e.GetTotalWorkSheets(); cout << "Total number of worksheets: " << e.GetTotalWorkSheets() << endl; for (size_t i=0; i<maxSheets; ++i) { BasicExcelWorksheet* sheet = e.GetWorksheet(i); if (sheet) { size_t maxRows = sheet->GetTotalRows(); size_t maxCols = sheet->GetTotalCols(); cout << "Dimension of " << sheet->GetAnsiSheetName() << " (" << maxRows << ", " << maxCols << ")" << endl; if (maxRows>0) { printf(" "); for (size_t c=0; c<maxCols; ++c) printf("%10d", c+1); cout << endl; } for (size_t r=0; r<maxRows; ++r) { printf("%10d", r+1); for (size_t c=0; c<maxCols; ++c) { cout << setw(10) << *(sheet->Cell(r,c)); // Another way of printing a cell content. } cout << endl; } if (i==0) { ofstream f("example4.csv"); sheet->Print(f, ',', '\"'); // Save the first sheet as a CSV file. f.close(); } } cout << endl; } return 0; }
static void example3(const char* path) { BasicExcel xls; // create sheet 1 and get the associated BasicExcelWorksheet pointer xls.New(1); BasicExcelWorksheet* sheet = xls.GetWorksheet(0); XLSFormatManager fmt_mgr(xls); CellFormat fmt(fmt_mgr); BasicExcelCell* cell; // row 1 fmt.set_format_string(XLS_FORMAT_INTEGER); cell = sheet->Cell(0, 0); cell->Set(1.); cell->SetFormat(fmt); fmt.set_format_string(XLS_FORMAT_DECIMAL); cell = sheet->Cell(0, 1); cell->Set(2.); cell->SetFormat(fmt); fmt.set_format_string(XLS_FORMAT_DATE); fmt.set_font(ExcelFont().set_weight(FW_BOLD)); cell = sheet->Cell(0, 2); cell->Set("03.03.2000"); cell->SetFormat(fmt); // row 2 fmt.set_font(ExcelFont().set_weight(FW_NORMAL)); fmt.set_format_string(XLS_FORMAT_GENERAL); cell = sheet->Cell(1, 0); cell->Set("normal"); cell->SetFormat(fmt); fmt.set_format_string(XLS_FORMAT_TEXT); cell = sheet->Cell(1, 1); cell->Set("Text"); cell->SetFormat(fmt); fmt.set_format_string(XLS_FORMAT_GENERAL); fmt.set_font(ExcelFont().set_weight(FW_BOLD)); cell = sheet->Cell(1, 2); cell->Set("bold"); cell->SetFormat(fmt); xls.SaveAs(path); }
std::string VLDDexporter::CommandProcessor::RunCommands(InputProcessor& data){ // let's run filters on the input data // _FilterInputData(data); // run the routine with the loaded parameters // // output spreadsheet // BasicExcel xls; // workbook sheets: // hot files, hot functions, summary, leaked blocks xls.New(4); // create hot files sheet // BasicExcelWorksheet* hotfilessheet = xls.GetWorksheet(0); hotfilessheet->Rename("Hot files"); // hot functions sheet // BasicExcelWorksheet* hotfunctions = xls.GetWorksheet(1); hotfunctions->Rename("Hot functions"); // summary sheet // //BasicExcelWorksheet* summarysheet = xls.GetWorksheet(2); //summarysheet->Rename("Summary"); // leaked blocks // //BasicExcelWorksheet* leakedblocks = xls.GetWorksheet(3); //leakedblocks->Rename("Leaked blocks"); XLSFormatManager fmt_mgr(xls); // create required fonts // ExcelFont fontheader; fontheader._weight = FW_BOLD; //fontheader._color_index = ExcelFont fontdata; fontheader._weight = FW_NORMAL; CellFormat fmtheader(fmt_mgr); fmtheader.set_font(fontheader); CellFormat fmtdata(fmt_mgr); fmtdata.set_font(fontdata); int Row = 0; int Col = 0; // hot files // for(Col = 0; Col < 4; Col++){ // get current cell // BasicExcelCell* cell = hotfilessheet->Cell(Row, Col); switch(Col){ case 0: { cell->Set("File"); } break; case 1: { cell->Set("Blame count"); } break; case 2: { cell->Set("Lines"); } break; case 3: { cell->Set("Blame gathering function"); } break; } cell->SetFormat(fmtheader); } // set proper widths // hotfilessheet->SetColWidth(0, 24000); hotfilessheet->SetColWidth(1, 5000); hotfilessheet->SetColWidth(2, 6000); hotfilessheet->SetColWidth(3, 10000); // output data // for(size_t i = 0; i < data.LeakingFiles.size(); i++){ // increase row // Row++; CallstackFileEntry* file = data.LeakingFiles[i].get(); for(Col = 0; Col < 4; Col++){ // get current cell // BasicExcelCell* cell = hotfilessheet->Cell(Row, Col); switch(Col){ case 0: { cell->Set(file->PathOrName.c_str()); } break; case 1: { cell->SetInteger(file->BlameCount); } break; case 2: { string lines; for(size_t a = 0; a < file->LeakLines.size(); a++){ if(a != 0) lines += ", "; stringstream converter; converter << file->LeakLines[a]; string tmpstr = ""; converter >> tmpstr; lines += tmpstr; } cell->Set(lines.c_str()); } break; case 3: { cell->Set(file->FunctionsInfile[0]->Name.c_str()); } break; } cell->SetFormat(fmtdata); } } Row = 0; Col = 0; // output hot functions // for(Col = 0; Col < 4; Col++){ // get current cell // BasicExcelCell* cell = hotfunctions->Cell(Row, Col); switch(Col){ case 0: { cell->Set("Function"); } break; case 1: { cell->Set("Blame count"); } break; case 2: { cell->Set("File"); } break; case 3: { cell->Set("Line"); } break; } cell->SetFormat(fmtheader); } // set proper widths // hotfunctions->SetColWidth(0, 32000); hotfunctions->SetColWidth(1, 5000); hotfunctions->SetColWidth(2, 24000); // output data // for(size_t i = 0; i < data.LeakingFunctions.size(); i++){ // increase row // Row++; CallstackFunction* func = data.LeakingFunctions[i].get(); for(Col = 0; Col < 4; Col++){ // get current cell // BasicExcelCell* cell = hotfunctions->Cell(Row, Col); switch(Col){ case 0: { cell->Set(func->Name.c_str()); } break; case 1: { cell->SetInteger(func->BlameCount); } break; case 2: { cell->Set(func->ContainedInFile->PathOrName.c_str()); } break; case 3: { cell->SetInteger(func->Line); } break; } cell->SetFormat(fmtdata); } } string finaloutput = OutputFilePath+OutputFile; // delete old first // wstringstream sstream; sstream << finaloutput.c_str(); wstring path; sstream >> path; DeleteFile((L"\\\\?\\"+path).c_str()); // save file // xls.SaveAs(finaloutput.c_str()); // return the created output // return OutputFilePath+OutputFile; }
void network_generator::write_output(){ for(int k=0;k<channel_layer;k++){ BasicExcel xls; // create sheet 1 and get the associated BasicExcelWorksheet pointer xls.New(1); BasicExcelWorksheet* sheet = xls.GetWorksheet(0); XLSFormatManager fmt_mgr(xls); // Create a table containing an header row in bold and four rows below. ExcelFont font_bold; font_bold._weight = FW_BOLD; // 700 CellFormat fmt_bold(fmt_mgr); fmt_bold.set_font(font_bold); ExcelFont font_red_bold; font_red_bold._weight = FW_BOLD; font_red_bold._color_index = EGA_BLACK; CellFormat color_1(fmt_mgr, font_red_bold); color_1.set_color1(COLOR1_PAT_SOLID); color_1.set_color2(MAKE_COLOR2(29,0)); CellFormat color_2(fmt_mgr, font_red_bold); color_2.set_color1(COLOR1_PAT_SOLID); color_2.set_color2(MAKE_COLOR2(16,0)); for (int i=0;i<101;i++){ for(int j=0;j<101;j++){ BasicExcelCell* cell = sheet->Cell(i, j); if(i%2 == 0 && j%2 == 0){ cell->SetFormat(color_2); sheet->Cell(i, j)->Set(-1); } else{ cell->SetFormat(color_1); sheet->Cell(i, j)->Set(liquid_network[k][i][j]); } } } for (int i=0;i<101;i++){ sheet->SetColWidth(i,950); } char layernum = k+48; string test_case_num = "0"; test_case_num += char(chip.case_num+48); string output_name=""; output_name += "cada030_problemA_testcase"; output_name += test_case_num; if(channel_layer > 1){ output_name += "_channellayer"; output_name += layernum; } output_name += ".xls"; xls.SaveAs(&output_name[0]); } }