Phpexcel Common Properties Use
Prospect:
Several variables need to be instantiated first:
$this->objexcel = new Phpexcel (); Instantiate a Phpexcel variable
$this->objexcel->setactivesheetindex (0); Set the sheet page to manipulate
$this->objactsheet = $this->objexcel->getactivesheet (); Gets the sheet page that is currently being manipulated
$objStyle = $this->objactsheet->getstyle (' A1 '); Gets the style of the cell to be set, and the contents of the parentheses are: (' a1:e1 ')
$objAlign = $objStyle->getalignment (); A variable used to set the Alignment property and wrap text within a cell
$objFont = $objStyle->getfont (); Get font properties
Common Properties:
1. Set sheet name:
Sets the name of the currently active sheet
$this->objactsheet->settitle ($title);
2. Set alignment and cell wrap
2.1. Horizontal alignment
Set cell content Horizontal alignment
$objAlign->sethorizontal (Phpexcel_style_alignment::horizontal_left);
Description
Horizontal-aligned variables are: Phpexcel_style_alignment::horizontal_left, Phpexcel_style_alignment::horizontal_center, PHPExcel_Style_ Alignment::horizontal_right;
The specific meanings are: Left, center, right.
2.2. Vertical alignment
$objAlign->setvertical (phpexcel_style_alignment::vertical_top);
Description
The vertically aligned variables are: Phpexcel_style_alignment::vertical_top, Phpexcel_style_alignment::vertical_center, PHPExcel_St Yle_alignment::vertical_bottom
The specific meanings are: top alignment, vertical center alignment, bottom alignment
2.3. Line wrapping in cell
$objAlign->setwraptext (TRUE);
Description
1, this is to achieve the cell can be manually specified in the position of the line break. As long as the specified text itself is wrapped, or a newline character (' \ n ') is inserted.
2, the text to be wrapped, the outside must be double quotation marks
For example:
The text is set to: $arr [' header '] = "haha \nhelloworld";
The effect shown is:
Ha ha
HelloWorld
3, set the font, color, etc.
3.1. Set the font
$objFont->setname (' Microsoft Jas Black '); Set the font you want to use
3.2. Set the font size
$objFont->setsize (11);
3.3. Set Bold
$objFont->setbold (FALSE);
3.4. Set Word color
$objFont->getcolor ()->setargb (phpexcel_style_color::color_white);
Description
1, its color composition: Alpha (transparency) channel +RGB color mode
2, ARGB---alpha,red,green,blu
3, generally I use the value of "FF" +rgb color value, such as: "FFCC15DD"
4. Cell Settings:
4.1. Setting the background color
$objStyle->getfill ()->setfilltype (phpexcel_style_fill::fill_solid);
$objStyle->getfill ()->getstartcolor ()->setargb (' FF595959 ');
4.2. Set width
$this->objactsheet->getcolumndimension ($WIDTHSTR)->setwidth (' 27.45 ');
4.3, set the height
$this->objactsheet->getrowdimension ($HEIGHTSTR)->setrowheight (' 27.45 ');
4.4. Cell Merging
$this->objactsheet->mergecells (' a1:i1 ');
Inside specifies the range of cells to merge
5. Other Settings:
5.1. Set Automatic filtering
$this->objactsheet->setautofilter ("a2:b2");
Description
At present, the author is more stupid, can not be arbitrarily specified to set the automatic filtering method.
5.2, cell formatting prevent scientific counting method
Format cells (prevent science and technology law)
$numberFormat = $objStyle->getnumberformat ();
$numberFormat->setformatcode (Phpexcel_style_numberformat::format_number);
Description
Read the time must be used: GetFormattedValue (), so that can be reduced to a certain extent the number of scientific counting method. Although PHP has methods to convert scientific notation, it suffers from the loss of precision.
I am now the most headache of a problem is the scientific counting method, there is no very good solution, now can solve the method is not thorough. I will continue to explore!
Phpexcel Common Properties Use