使用此代码,我可以在excel文件中创建注释.
$comment = $data_sheet->getCommentByColumnAndRow($col, 1);
$comment->setAuthor($table_name . '.' . $field_name);
$comment->setWidth('200px');
$comment->setHeight('24px');
$comment->setVisible(false); # ActiveCell.Comment.Visible = True
$objCommentRichText = $comment->getText()->createTextRun($table_name . '.' . $field_name);
保存时,文件中包含注释,可以对其进行编辑,但是在重新打开该文件时,注释对象处于默认状态.
$comment = $data_sheet->getComment('A1');
结果是:-
$comment = PHPExcel_Comment Object (
[_author:private] => Author
[_text:private] => PHPExcel_RichText Object ( [_richTextElements:private] => Array ( ) )
[_width:private] => 96pt
[_marginLeft:private] => 59.25pt
[_marginTop:private] => 1.5pt
[_visible:private] =>
[_height:private] => 55.5pt
[_fillColor:private] => PHPExcel_Style_Color Object (
[_argb:private] => FFFFFFE1
[_isSupervisor:private] =>
[_parent:private] =>
[_parentPropertyName:private] =>
)
)
编辑:
products.products_idproducts.part_codeproducts.products_nameproducts.products_quantityproducts.products_statusproducts.costproducts.cost_modifierproducts.delivery_costproducts.shipping_strategyproducts.products_weightproducts.shipping_amountproducts.products_priceproducts.rrpproducts.tradeproducts_feed.amazon_priceproducts_feed.ebay_price
products.products_id
products.part_code
products.products_name
products.products_quantity
products.products_status
products.cost
products.cost_modifier
products.delivery_cost
products.shipping_strategy
products.products_weight
products.shipping_amount
products.products_price
products.rrp
products.trade
products_feed.amazon_price
products_feed.ebay_price
因此,注释存在于.xlsx文件中.
这些都还没有收到评论.
$comment = $data_sheet->getCommentByColumnAndRow($col, 1);
$comment = $data_sheet->getComment('A'. $row);
$comments = $data_sheet->getComments();
– 编辑
问题,注释是否正确以“ Excel2007”格式加载?
解决方法:
这是我使用PHPExcel从单元格中提取注释的代码片段
$objPHPExcel = PHPExcel_IOFactory::load("MyExcelFile.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();
// loop through each row in excel file
foreach ($objWorksheet->getRowIterator() as $row) {
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
// loop through each column in row
foreach ($cellIterator as $cell) {
// get the value of the cell
$value = $cell->getValue();
// get the comment in the cell (if a comment exists)
$comment = $objWorksheet->getComment($cell->getCoordinate())->getText();
}
}
标签:phpexcel,php
来源: https://codeday.me/bug/20191023/1915627.html