kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

PHPExcel 页面边距设置

phpexcel 官网上找到了以下设置边距的代码,且测试成功.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$excel = new PHPExcel(); 
$sheet = $excel->getActiveSheet(); 
$pageMargins = $sheet->getPageMargins(); 

// 设置边距为0.5厘米

(1英寸 = 2.54厘米)

$margin = 0.5 / 2.54; //phpexcel 中是按英寸来计算的,所以这里换算了一下 

$pageMargins->setTop($margin);       //上边距 
$pageMargins->setBottom($margin);    //下 
$pageMargins->setLeft($margin);      //左 
$pageMargins->setRight($margin);     //右 

$sheet->getPageSetup()->setFitToWidth('1');//自动填充到页面的宽度 
//$sheet->getPageSetup()->setFitToHeight('1');//自动填充到页面的高度 

$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5'); //生成一个新的xls文件 
$writer->save('test.xls'); 

phpExcel使单元格部分文字加粗、放大、添加颜色

可以使用phpExcel的富文本进行操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$objPHPExcel = new \PHPExcel();

//创建一个富文本对象 
$objRichText = new \PHPExcel_RichText(); 
$objRichText->createText('啊啊啊啊'); 

//需要改变大小或颜色的文字内容 
$objPayable = $objRichText->createTextRun('不不不'); 

//设置加粗
$objPayable->getFont()->setBold(true);
//设置斜体
$objPayable->getFont()->setItalic(true);
//设置文字大小
$objPayable->getFont()->setSize(15);
//设置颜色
$objPayable->getFont()->setColor( new \PHPExcel_Style_Color(\PHPExcel_Style_Color::COLOR_DARKGREEN) );

$objRichText->createText('超超超超');

$objPHPExcel->getActiveSheet()->getCell('A1')->setValue($objRichText);

$PHPWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
$PHPWriter->save('a.xlsx'); 

PHPExcel设置打印区域

https://www.cnblogs.com/keketoloveme/p/16723337.html

方向和纸张尺寸:

1
2
3
4
5
6
$objPHPExcel->getActiveSheet()
    ->getPageSetup()
    ->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$objPHPExcel->getActiveSheet()
    ->getPageSetup()
    ->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);

页边距:

1
2
3
4
5
6
7
8
$objPHPExcel->getActiveSheet()
    ->getPageMargins()->setTop(1);
$objPHPExcel->getActiveSheet()
    ->getPageMargins()->setRight(0.75);
$objPHPExcel->getActiveSheet()
    ->getPageMargins()->setLeft(0.75);
$objPHPExcel->getActiveSheet()
    ->getPageMargins()->setBottom(1);

页眉和页脚:

1
2
3
4
5
6
$objPHPExcel->getActiveSheet()
    ->getHeaderFooter()
    ->setOddHeader('&C&HPlease treat this document as confidential!');
$objPHPExcel->getActiveSheet()
    ->getHeaderFooter()
    ->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() .

打印机分页符:

1
2
$objPHPExcel->getActiveSheet()
    ->setBreak( 'A10' , PHPExcel_Worksheet::BREAK_ROW );

显示网格线:

1
2
$objPHPExcel->getActiveSheet()
    ->setShowGridlines(true);

将行/列设置为在每页的顶部/左侧重复

1
2
3
$objPHPExcel->getActiveSheet()
    ->getPageSetup()
    ->setRowsToRepeatAtTopByStartAndEnd(1, 5);

设置打印区域:

1
2
3
$objPHPExcel->getActiveSheet()
    ->getPageSetup()
    ->setPrintArea('A1:E5,G4:M20');