From 1a44a04171734084761c61ff6c933f0bd62f26cf Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Fri, 7 Nov 2014 12:35:29 +0800 Subject: [PATCH] Refactoring worksheetoperations examples. --- examples/xlsx/worksheetoperations/main.cpp | 45 ++++++++++++++++------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/examples/xlsx/worksheetoperations/main.cpp b/examples/xlsx/worksheetoperations/main.cpp index fc86bb3..d0c23a2 100644 --- a/examples/xlsx/worksheetoperations/main.cpp +++ b/examples/xlsx/worksheetoperations/main.cpp @@ -1,32 +1,53 @@ #include #include "xlsxdocument.h" +#include "xlsxabstractsheet.h" + +QTXLSX_USE_NAMESPACE int main() { - QXlsx::Document xlsx; + //![Create a xlsx file] + Document xlsx; for (int i=1; i<20; ++i) { for (int j=1; j<15; ++j) xlsx.write(i, j, QString("R %1 C %2").arg(i).arg(j)); } - xlsx.renameSheet("Sheet1", "TheFirstSheet"); - - xlsx.addSheet("TheSecondSheet"); + xlsx.addSheet(); xlsx.write(2, 2, "Hello Qt Xlsx"); + xlsx.addSheet(); + xlsx.write(3, 3, "This will be deleted..."); - xlsx.copySheet("TheFirstSheet", "CopyOfTheFirst"); + xlsx.addSheet("HiddenSheet"); + xlsx.currentSheet()->setHidden(true); + xlsx.write("A1", "This sheet is hidden."); - xlsx.addSheet("TheForthSheet"); - xlsx.write(3, 3, "This will be deleted..."); + xlsx.addSheet("VeryHiddenSheet"); + xlsx.sheet("VeryHiddenSheet")->setSheetState(AbstractSheet::SS_VeryHidden); + xlsx.write("A1", "This sheet is very hidden."); + + xlsx.save();//Default name is "Book1.xlsx" + //![Create a xlsx file] + + Document xlsx2("Book1.xlsx"); + //![add_copy_move_delete] + xlsx2.renameSheet("Sheet1", "TheFirstSheet"); + + xlsx2.copySheet("TheFirstSheet", "CopyOfTheFirst"); - xlsx.selectSheet("CopyOfTheFirst"); - xlsx.write(25, 2, "On the Copy Sheet"); + xlsx2.selectSheet("CopyOfTheFirst"); + xlsx2.write(25, 2, "On the Copy Sheet"); - xlsx.deleteSheet("TheForthSheet"); + xlsx2.deleteSheet("Sheet3"); - xlsx.moveSheet("TheSecondSheet", 0); + xlsx2.moveSheet("Sheet2", 0); + //![add_copy_move_delete] - xlsx.save(); + //![show_hidden_sheets] + xlsx2.sheet("HiddenSheet")->setVisible(true); + xlsx2.sheet("VeryHiddenSheet")->setVisible(true); + //![show_hidden_sheets] + xlsx2.saveAs("Book2.xlsx"); return 0; }