简体   繁体   English

使用PHPEXCEL在工作表中添加评论

[英]Add a comment in a sheet with PHPEXCEL

I'm trying with this code to add a comment in a Excel cell : 我正在尝试使用此代码在Excel单元格中添加注释:

$objPHPExcel->getActiveSheet()->getComment(($arr_periodes[2]+1),17+($arr_periodes[1]))->setAuthor($user->prenom.' '.$user->nom);
                           $objCommentRichText = $objPHPExcel->getActiveSheet()->getComment(($arr_periodes[2]+1),17+($arr_periodes[1]))->getText()->createTextRun($res->commentaire);
                           $objCommentRichText->getFont()->setBold(true);
                           $objPHPExcel->getActiveSheet()->getComment(($arr_periodes[2]+1),17+($arr_periodes[1]))->getText()->createTextRun("\r\n");
                           $objPHPExcel->getActiveSheet()->getComment(($arr_periodes[2]+1),17+($arr_periodes[1]))->getText()->createTextRun($res->commentaire);

It opens file, but I need to repair it and comments doesn't show. 它会打开文件,但是我需要修复它并且注释不会显示。

This is my writer : 这是我的作家:

$writer = new PHPExcel_Writer_Excel2007($objPHPExcel);

EDIT 编辑

This code works : 此代码有效:

$objPHPExcel->getActiveSheet()
                            ->getComment('E11')
                            ->getText()->createTextRun($user->commentaire);

Is it possible to put a variable in place of E11 ? 是否可以将变量替换为E11?

I have to use setCellValueByColumnAndRow, thus 5,11 ie 我必须使用setCellValueByColumnAndRow,因此5,11即

EDIT 编辑

My problem persists : 我的问题仍然存在:

I tried with this : 我尝试了这个:

objPHPExcel->getActiveSheet()
                            ->getComment(($arr_periodes[2]+1),(17+$arr_periodes[1]))
                            ->getText()->createTextRun($user->commentaire);

($arr_periodes[2]+1) contains in exemple 4 AND (17+$arr_periodes[1]) contains in exemple 20 ($ arr_periodes [2] +1)包含在示例4中,而(17 + $ arr_periodes [1])包含在示例20中

The refernece is 4,17 裁判是4,17

The problem is that the first parameter has to be a letter ! 问题是第一个参数必须是字母!

The file is only 17K and I have to repair it when I open it. 该文件只有17K,打开时必须修复。

Any Idea ? 任何想法 ?

OK, I found a solution : 好的,我找到了解决方案:

I created an array : 我创建了一个数组:

$arr_lettres = array(2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K',11=>'L',12=>'M',13=>'N',14=>'O',15=>'P',16=>'Q',17=>'R',18=>'S',19=>'T',20=>'U',21=>'V',22=>'W',23=>'X',24=>'Y',25=>'Z',26=>'AA',27=>'AB',28=>'AC',29=>'AD',30=>'AE',31=>'AF',32=>'AG');

And then : 接着 :

$objPHPExcel->getActiveSheet()
                        ->getComment($arr_lettres[($arr_periodes[2]+1)].(17+$arr_periodes[1]))
                        ->getText()->createTextRun($periodes->commentaire);

All is working now, I have my comments and text. 现在一切正常,我有意见和文字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM