@@ -169,249 +169,5 @@ public static function delete_column($dataDir)
169169
170170 }
171171
172- public static function hide_rows_columns ($ dataDir )
173- {
174-
175- # Instantiating a Workbook object by excel file path
176- $ workbook = new Workbook ($ dataDir . 'Book1.xls ' );
177-
178- # Accessing the first worksheet in the Excel file
179- $ worksheet = $ workbook ->getWorksheets ()->get (0 );
180- $ cells = $ worksheet ->getCells ();;
181-
182- # Hiding the 3rd row of the worksheet
183- $ cells ->hideRow (2 );
184-
185- # Hiding the 2nd column of the worksheet
186- $ cells ->hideColumn (1 );
187-
188- # Saving the modified Excel file in default (that is Excel 2003) format
189- $ workbook ->save ($ dataDir . "Hide Rows And Columns.xls " );
190-
191- print "Hide Rows And Columns Successfully. " . PHP_EOL ;
192-
193- }
194-
195- public static function unhide_rows_columns ($ dataDir )
196- {
197-
198- # Instantiating a Workbook object by excel file path
199- $ workbook = new Workbook ($ dataDir . 'Book1.xls ' );
200-
201- # Accessing the first worksheet in the Excel file
202- $ worksheet = $ workbook ->getWorksheets ()->get (0 );
203- $ cells = $ worksheet ->getCells ();;
204-
205- # Unhiding the 3rd row and setting its height to 13.5
206- $ cells ->unhideRow (2 ,13.5 );
207-
208- # Unhiding the 2nd column and setting its width to 8.5
209- $ cells ->unhideColumn (1 ,8.5 );
210-
211- # Saving the modified Excel file in default (that is Excel 2003) format
212- $ workbook ->save ($ dataDir . "Unhide Rows And Columns.xls " );
213-
214- print "Unhide Rows And Columns Successfully. " . PHP_EOL ;
215-
216- }
217-
218- public static function group_rows_columns ($ dataDir )
219- {
220-
221- # Instantiating a Workbook object by excel file path
222- $ workbook = new Workbook ($ dataDir . 'Book1.xls ' );
223-
224- # Accessing the first worksheet in the Excel file
225- $ worksheet = $ workbook ->getWorksheets ()->get (0 );
226- $ cells = $ worksheet ->getCells ();;
227-
228- # Grouping first six rows (from 0 to 5) and making them hidden by passing true
229- $ cells ->groupRows (0 ,5 ,true );
230-
231- # Grouping first three columns (from 0 to 2) and making them hidden by passing true
232- $ cells ->groupColumns (0 ,2 ,true );
233-
234- # Saving the modified Excel file in default (that is Excel 2003) format
235- $ workbook ->save ($ dataDir . "Group Rows And Columns.xls " );
236-
237- print "Group Rows And Columns Successfully. " . PHP_EOL ;
238-
239- }
240-
241- public static function ungroup_rows_columns ($ dataDir )
242- {
243-
244- # Instantiating a Workbook object by excel file path
245- $ workbook = new Workbook ($ dataDir . 'Group Rows And Columns.xls ' );
246-
247- # Accessing the first worksheet in the Excel file
248- $ worksheet = $ workbook ->getWorksheets ()->get (0 );
249- $ cells = $ worksheet ->getCells ();;
250-
251- # Ungrouping first six rows (from 0 to 5)
252- $ cells ->ungroupRows (0 ,5 );
253-
254- # Ungrouping first three columns (from 0 to 2)
255- $ cells ->ungroupColumns (0 ,2 );
256-
257- # Saving the modified Excel file in default (that is Excel 2003) format
258- $ workbook ->save ($ dataDir . "Ungroup Rows And Columns.xls " );
259-
260- print "Ungroup Rows And Columns Successfully. " . PHP_EOL ;
261-
262- }
263-
264- public static function set_row_height ($ dataDir )
265- {
266-
267- # Instantiating a Workbook object by excel file path
268- $ workbook = new Workbook ($ dataDir . 'Book1.xls ' );
269-
270- # Accessing the first worksheet in the Excel file
271- $ worksheet = $ workbook ->getWorksheets ()->get (0 );
272- $ cells = $ worksheet ->getCells ();
273-
274- # Setting the height of the second row to 13
275- $ cells ->setRowHeight (1 , 13 );
276-
277- # Saving the modified Excel file in default (that is Excel 2003) format
278- $ workbook ->save ($ dataDir . "Set Row Height.xls " );
279-
280- print "Set Row Height Successfully. " . PHP_EOL ;
281-
282- }
283-
284- public static function set_column_width ($ dataDir )
285- {
286-
287- # Instantiating a Workbook object by excel file path
288- $ workbook = new Workbook ($ dataDir . 'Book1.xls ' );
289-
290- # Accessing the first worksheet in the Excel file
291- $ worksheet = $ workbook ->getWorksheets ()->get (0 );
292- $ cells = $ worksheet ->getCells ();
293-
294- # Setting the width of the second column to 17.5
295- $ cells ->setColumnWidth (1 , 17.5 );
296-
297- # Saving the modified Excel file in default (that is Excel 2003) format
298- $ workbook ->save ($ dataDir . "Set Column Width.xls " );
299-
300- print "Set Column Width Successfully. " . PHP_EOL ;
301-
302- }
303-
304- public static function autofit_row ($ dataDir )
305- {
306-
307- # Instantiating a Workbook object by excel file path
308- $ workbook = new Workbook ($ dataDir . 'Book1.xls ' );
309-
310- # Accessing the first worksheet in the Excel file
311- $ worksheet = $ workbook ->getWorksheets ()->get (0 );
312-
313- # Auto-fitting the 3rd row of the worksheet
314- $ worksheet ->autoFitRow (2 );
315-
316- # Auto-fitting the 3rd row of the worksheet based on the contents in a range of
317- # cells (from 1st to 9th column) within the row
318- #$worksheet->autoFitRow(2,0,8) # Uncomment this line if you to do AutoFit Row in a Range of Cells. Also, comment line 288.
319-
320- # Saving the modified Excel file in default (that is Excel 2003) format
321- $ workbook ->save ($ dataDir . "Autofit Row.xls " );
322-
323- print "Autofit Row Successfully. " . PHP_EOL ;
324-
325- }
326-
327- public static function autofit_column ($ dataDir )
328- {
329-
330- # Instantiating a Workbook object by excel file path
331- $ workbook = new Workbook ($ dataDir . 'Book1.xls ' );
332-
333- # Accessing the first worksheet in the Excel file
334- $ worksheet = $ workbook ->getWorksheets ()->get (0 );
335-
336- # Auto-fitting the 4th column of the worksheet
337- $ worksheet ->autoFitColumn (3 );
338-
339- # Auto-fitting the 4th column of the worksheet based on the contents in a range of
340- # cells (from 1st to 9th row) within the column
341- #$worksheet->autoFitColumn(3,0,8) #Uncomment this line if you to do AutoFit Column in a Range of Cells. Also, comment line 310.
342-
343- # Saving the modified Excel file in default (that is Excel 2003) format
344- $ workbook ->save ($ dataDir . "Autofit Column.xls " );
345-
346- print "Autofit Column Successfully. " . PHP_EOL ;
347-
348- }
349-
350- public static function copy_rows ($ dataDir )
351- {
352-
353- # Instantiating a Workbook object by excel file path
354- $ workbook = new Workbook ($ dataDir . 'Book1.xls ' );
355-
356- # Accessing the first worksheet in the Excel file
357- $ worksheet = $ workbook ->getWorksheets ()->get (0 );
358-
359- # Copy the second row with data, formattings, images and drawing objects
360- # to the 12th row in the $worksheet->
361- $ worksheet ->getCells ()->copyRow ($ worksheet ->getCells (),1 ,11 );
362-
363- # Saving the modified Excel file in default (that is Excel 2003) format
364- $ workbook ->save ($ dataDir . "Copy Rows.xls " );
365-
366- print "Copy Rows Successfully. " . PHP_EOL ;
367-
368- }
369-
370- public static function copy_columns ($ dataDir )
371- {
372-
373- # Instantiating a Workbook object by excel file path
374- $ workbook = new Workbook ();
375-
376- # Accessing the first worksheet in the Excel file
377- $ worksheet = $ workbook ->getWorksheets ()->get (0 );
378-
379- # Put some data into header rows (A1:A4)
380- $ i = 0 ;
381- while ($ i < 5 )
382- {
383- $ worksheet ->getCells ()->get ($ i , 0 )->setValue ("Header Row # $ i " );
384- $ i ++;
385-
386- }
387-
388-
389- # Put some detail data (A5:A999)
390- $ i = 5 ;
391- while ($ i < 1000 ) {
392-
393- $ worksheet ->getCells ()->get ($ i , 0 )->setValue ("Detail Row # $ i " );
394- $ i ++;
395- }
396-
397- # Create another Workbook.
398- $ workbook1 = new Workbook ();
399-
400- # Get the first worksheet in the book.
401- $ worksheet1 = $ workbook1 ->getWorksheets ()->get (0 );
402-
403- # Copy the first column from the first worksheet of the first workbook into
404- # the first worksheet of the second workbook.
405- $ worksheet1 ->getCells ()->copyColumn ($ worksheet ->getCells (),0 ,2 );
406-
407- # Autofit the column.
408- $ worksheet1 ->autoFitColumn (2 );
409-
410- # Saving the modified Excel file in default (that is Excel 2003) format
411- $ workbook ->save ($ dataDir . "Copy Columns.xls " );
412-
413- print "Copy Columns Successfully. " . PHP_EOL ;
414-
415- }
416172
417173}
0 commit comments