Пример #1
0
 public static function run($dataDir = null)
 {
     $fileFormatType = new FileFormatType();
     //Creating an Workbook object with an Excel file path
     $workbook = new Workbook($dataDir . "book.xls");
     //Save in default (Excel2003) format
     $workbook->save($dataDir . "book.default.out.xls");
     //Save in Excel2003 format
     $workbook->save($dataDir . "book.out.xls", $fileFormatType->EXCEL_97_TO_2003);
     //Save in Excel2007 xlsx format
     $workbook->save($dataDir . "book.out.xlsx", $fileFormatType->XLSX);
     //Save in SpreadsheetML format
     $workbook->save($dataDir . "book.out.xml", $fileFormatType->EXCEL_2003_XML);
     //Print Message
     print "<BR>";
     print "Worksheets are saved successfully.";
 }
 public static function run($dataDir = null)
 {
     $saveFormat = new SaveFormat();
     $workbook = new Workbook($dataDir . "Book1.xls");
     //Save the document in PDF format
     $workbook->save($dataDir . "OutBook1.html", $saveFormat->HTML);
     // Print message
     echo "\n Excel to HTML conversion performed successfully.";
 }
Пример #3
0
 public static function run($dataDir = null)
 {
     //Instantiating a Workbook object by excel file path
     $workbook = new Workbook($dataDir . "book1.xls");
     //Hiding the tabs of the Excel file
     $workbook->getSettings()->setShowTabs(false);
     //Saving the modified Excel file in default (that is Excel 2003) format
     $workbook->save($dataDir + "output.xls");
     // Print message
     print "Tabs are now hidden, please check the output file." . PHP_EOL;
 }
 public static function run($dataDir = null)
 {
     //Instantiate a Workbook object by excel file path
     $workbook = new Workbook($dataDir . "Book1.xls");
     //Retrieve a list of all custom document properties of the Excel file
     $customProperties = $workbook->getWorksheets()->getCustomDocumentProperties();
     //Accessing a custom document property by using the property index
     $customProperty1 = $customProperties->get(3);
     //Accessing a custom document property by using the property name
     $customProperty2 = $customProperties->get("Owner");
     //Adding a custom document property to the Excel file
     $publisher = $customProperties->add("Publisher", "Aspose");
     //Save the file
     $workbook->save($dataDir . "Test_Workbook.xls");
     //Removing a custom document property
     $customProperties->remove("Publisher");
     //Save the file
     $workbook->save($dataDir . "Test_Workbook_RemovedProperty.xls");
     // Print message
     print "Excel file's custom properties accessed successfully." . PHP_EOL;
 }
 public static function run($dataDir = null)
 {
     //Instantiating a Excel object by excel file path
     $workbook = new Workbook($dataDir . "book1.xls");
     //Hiding the vertical scroll bar of the Excel file
     $workbook->getSettings()->setVScrollBarVisible(false);
     //Hiding the horizontal scroll bar of the Excel file
     $workbook->getSettings()->setHScrollBarVisible(false);
     //Saving the modified Excel file in default (that is Excel 2003) format
     $workbook->save($dataDir . "output.xls");
     // Print message
     print "Scroll bars are now hidden, please check the output document.";
 }
Пример #6
0
 public static function run($dataDir = null)
 {
     //Instantiating a Excel object by excel file path
     $workbook = new Workbook($dataDir . "book.xls");
     //Accessing the first worksheet in the Excel file
     $worksheets = $workbook->getWorksheets();
     $worksheet = $worksheets->get(0);
     //Applying freeze panes settings
     $worksheet->freezePanes(3, 2, 3, 2);
     //Saving the modified Excel file in default format
     $workbook->save($dataDir . "book.out.xls");
     //Print Message
     print "Panes freeze successfull." . PHP_EOL;
 }
Пример #7
0
 public static function run($dataDir = null)
 {
     //Instantiating a Excel object by excel file path
     $workbook = new Workbook($dataDir . "book1.xls");
     //Accessing the first worksheet in the Excel file
     $worksheets = $workbook->getWorksheets();
     $worksheet = $worksheets->get(0);
     //Setting the zoom factor of the worksheet to 75
     $worksheet->setZoom(75);
     //Saving the modified Excel file in default format
     $workbook->save($dataDir . "output.xls");
     // Print message
     print "Zoom factor set to 75% for sheet 1, please check the output document.";
 }
 public static function run($dataDir = null)
 {
     //Instantiating a Excel object by excel file path
     $workbook = new Workbook($dataDir . "book1.xls");
     //Adding a new worksheet to the Workbook object
     $worksheets = $workbook->getWorksheets();
     $worksheet = $worksheets->get(0);
     //Displaying the worksheet in page break preview
     $worksheet->setPageBreakPreview(true);
     //Saving the modified Excel file in default format
     $workbook->save($dataDir . "output.xls");
     // Print message
     print "Page break preview is enabled for sheet 1, please check the output document." . PHP_EOL;
 }
 public static function run($dataDir = null)
 {
     //Instantiating a Workbook object by excel file path
     $workbook = new Workbook($dataDir . "book1.xls");
     //Accessing the first worksheet in the Excel file
     $worksheets = $workbook->getWorksheets();
     $worksheet = $worksheets->get(0);
     //Hiding the first worksheet of the Excel file
     $worksheet->setVisible(false);
     //Saving the modified Excel file in default (that is Excel 2003) format
     $workbook->save($dataDir . "output.xls");
     // Print message
     print "Worksheet 1 is now hidden, please check the output document." . PHP_EOL;
 }
Пример #10
0
 public static function run($dataDir = null)
 {
     $saveFormat = new SaveFormat();
     //Instantiate a new workbook
     //Open a template file
     $book = new Workbook($dataDir . "book.xls");
     //Set the active cell
     $book->getWorksheets()->get(0)->setActiveCell("A20");
     //Split the worksheet window
     $book->getWorksheets()->get(0)->split();
     //Save the excel file
     $book->save($dataDir . "book.out.xls", $saveFormat->EXCEL_97_TO_2003);
     //Print Message
     print "Panes split successfully." . PHP_EOL;
 }
 public static function run($dataDir = null)
 {
     //Creating a file stream containing the Excel file to be opened
     $fstream = new FileInputStream($dataDir . "book.xls");
     //Instantiating a Workbook object with the stream
     $workbook = new Workbook($fstream);
     //Removing a worksheet using its sheet name
     $workbook->getWorksheets()->removeAt("Sheet1");
     //Saving the Excel file
     $workbook->save($dataDir . "book.out.xls");
     //Closing the file stream to free all resources
     $fstream->close();
     //Print Message
     print "Sheet removed successfully.";
 }
 public static function run($dataDir = null)
 {
     $filesFormatType = new FileFormatType();
     //Instantiating a Workbook object
     $workbook = new Workbook($dataDir . "book1.xls");
     $worksheets = $workbook->getWorksheets();
     $worksheet = $worksheets->get(0);
     $protection = $worksheet->getProtection();
     //Unprotecting the worksheet with a password
     $worksheet->unprotect("aspose");
     // Save the excel file.
     $workbook->save($dataDir . "output.xls", $filesFormatType->EXCEL_97_TO_2003);
     //Print Message
     print "Worksheet unprotected successfully.";
 }
 public static function scaling($dataDir = null)
 {
     # Instantiating a Workbook object by excel file path
     $workbook = new Workbook($dataDir . 'Book1.xls');
     # Accessing the first worksheet in the Excel file
     $worksheets = $workbook->getWorksheets();
     $sheet_index = $worksheets->add();
     $sheet = $worksheets->get($sheet_index);
     # Setting the scaling factor to 100
     $page_setup = $sheet->getPageSetup();
     $page_setup->setZoom(100);
     # Saving the modified Excel file in default (that is Excel 2003) format
     $workbook->save($dataDir . "Scaling.xls");
     print "Set scaling, please check the output file." . PHP_EOL;
 }
 public static function run($dataDir = null)
 {
     //Instantiating a Workbook object
     $workbook = new Workbook();
     //Adding a new worksheet to the Workbook object
     $worksheets = $workbook->getWorksheets();
     $sheetIndex = $worksheets->add();
     $worksheet = $worksheets->get($sheetIndex);
     //Setting the name of the newly added worksheet
     $worksheet->setName("My Worksheet");
     //Saving the Excel file
     $workbook->save($dataDir . "book.out.xls");
     //Print Message
     print "Sheet added successfully.";
 }
 public static function run($dataDir = null)
 {
     $sveFormat = new SaveFormat();
     //Specify the file path
     $filePath = $dataDir . "Book1.xlsx";
     //Specify the HTML saving options
     $sv = new HtmlSaveOptions($sveFormat->M_HTML);
     //Instantiate a workbook and open the template XLSX file
     $wb = new Workbook($filePath);
     //Save the MHT file
     $wb->save($filePath . ".out.mht", $sv);
     // Print message
     print "<br>";
     print "<br>";
     print "Excel to MHTML conversion performed successfully.";
 }
Пример #16
0
 public static function run($dataDir = null)
 {
     // Instantiating a Workbook object that represents a Microsoft Excel file.
     $workbook = new Workbook();
     // Note when you create a new workbook, a default worksheet,
     // "Sheet1", is by default added to the workbook.
     // Accessing the first worksheet in the book ("Sheet1").
     $sheet = $workbook->getWorksheets()->get(0);
     # Access cell "A1" in the sheet.
     $cell = $sheet->getCells()->get("A1");
     # Input the "Hello World!" text into the "A1" cell
     $cell->setValue("Hello World!");
     # Saving the modified Excel file in default (that is Excel 2003) format
     $file_format_type = new FileFormatType();
     $workbook->save($dataDir . "HelloWorld.xls", $file_format_type->EXCEL_97_TO_2003);
     print "Document has been saved, please check the output file.";
 }
Пример #17
0
 public static function run($dataDir = null)
 {
     $saveFormat = new SaveFormat();
     $workbook = new Workbook($dataDir . "Book1.xls");
     //Get the first worksheet.
     $sheet = $workbook->getWorksheets()->get(0);
     //Apply different Image and Print options
     $options = new ImageOrPrintOptions();
     //Set the Format
     $options->setSaveFormat($saveFormat->XPS);
     // Render the sheet with respect to specified printing options
     $sr = new SheetRender($sheet, $options);
     $sr->toImage(0, $dataDir . "out_printingxps.xps");
     //Save the complete Workbook in XPS format
     $workbook->save($dataDir . "out_whole_printingxps", $saveFormat->XPS);
     // Print message
     print "Excel to XPS conversion performed successfully.";
 }
 public static function run($dataDir = null)
 {
     $filesFormatType = new FileFormatType();
     //Instantiating a Workbook object
     $workbook = new Workbook($dataDir . "book1.xls");
     $worksheets = $workbook->getWorksheets();
     $worksheet = $worksheets->get(0);
     $protection = $worksheet->getProtection();
     //The following 3 methods are only for Excel 2000 and earlier formats
     $protection->setAllowEditingContent(false);
     $protection->setAllowEditingObject(false);
     $protection->setAllowEditingScenario(false);
     //Unprotecting the worksheet
     $worksheet->unprotect();
     // Save the excel file.
     $workbook->save($dataDir . "output.xls", $filesFormatType->EXCEL_97_TO_2003);
     //Print Message
     print "Worksheet unprotected successfully." . PHP_EOL;
 }
 public static function run($dataDir = null)
 {
     //Instantiating a Excel object by excel file path
     $excel = new Workbook($dataDir . "book1.xls");
     //Accessing the first worksheet in the Excel file
     $worksheets = $excel->getWorksheets();
     $worksheet = $worksheets->get(0);
     $protection = $worksheet->getProtection();
     //The following 3 methods are only for Excel 2000 and earlier formats
     $protection->setAllowEditingContent(false);
     $protection->setAllowEditingObject(false);
     $protection->setAllowEditingScenario(false);
     //Protects the first worksheet with a password "1234"
     $protection->setPassword("1234");
     //Saving the modified Excel file in default format
     $excel->save($dataDir . "output.xls");
     //Print Message
     print "Sheet protected successfully." . PHP_EOL;
 }
Пример #20
0
 public static function copy_columns($dataDir)
 {
     # Instantiating a Workbook object by excel file path
     $workbook = new Workbook();
     # Accessing the first worksheet in the Excel file
     $worksheet = $workbook->getWorksheets()->get(0);
     # Put some data into header rows (A1:A4)
     $i = 0;
     while ($i < 5) {
         $worksheet->getCells()->get($i, 0)->setValue("Header Row #{$i}");
         $i++;
     }
     # Put some detail data (A5:A999)
     $i = 5;
     while ($i < 1000) {
         $worksheet->getCells()->get($i, 0)->setValue("Detail Row #{$i}");
         $i++;
     }
     # Create another Workbook.
     $workbook1 = new Workbook();
     # Get the first worksheet in the book.
     $worksheet1 = $workbook1->getWorksheets()->get(0);
     # Copy the first column from the first worksheet of the first workbook into
     # the first worksheet of the second workbook.
     $worksheet1->getCells()->copyColumn($worksheet->getCells(), 0, 2);
     # Autofit the column.
     $worksheet1->autoFitColumn(2);
     # Saving the modified Excel file in default (that is Excel 2003) format
     $workbook->save($dataDir . "Copy Columns.xls");
     print "Copy Columns Successfully." . PHP_EOL;
 }