本帖最后由 pengwei0417 于 2014-08-31 15:02:38 编辑

解决方案 »

  1.   

    hw是什么,完全没看出跟AllResult有任何关系
      

  2.   

    还有,既然报AN5有问题,看看AN5到底怎么了
    是否在同一单元格建立了2个批注?
      

  3.   

    哦,少写了一句: HSSFWorkbook hw = new HSSFWorkbook(fs)你说的对,是在同一个单元格建立了2个批注,问题已经解决,解决方法如下:
    此处代码:
     for (int k = 0; k < AllResult[i].errorinfo[j].columnindex.Count; k++) //按单个错误所涉及的单元格数循环,设置错误包含单元格的格式
                        {
                            //建立批注
                            comment1 = patr.CreateCellComment(anchor) as HSSFComment;
                            comment1.String = new HSSFRichTextString(AllResult[i].errorinfo[j].errorInfo);
                            comment1.Author = "XXXX设计";
                            //错误所在的列号
                            int coli = (int)AllResult[i].errorinfo[j].columnindex[k];
                            HSSFCell cell = (HSSFCell)row.GetCell(coli);//包含错误的单元格
                            cell.CellComment = comment1;
                            cell.CellStyle = hfctyle;
                        }改为:
      for (int k = 0; k < AllResult[i].errorinfo[j].columnindex.Count; k++) //按单个错误所涉及的单元格数循环,设置错误包含单元格的格式
                        {
                            //错误所在的列号
                            int coli = (int)AllResult[i].errorinfo[j].columnindex[k];
                            HSSFCell cell = (HSSFCell)row.GetCell(coli);//包含错误的单元格
                            if (cell.CellComment == null)
                            {
                                //建立批注
                                comment1 = patr.CreateCellComment(anchor) as HSSFComment;
                                comment1.String = new HSSFRichTextString(AllResult[i].errorinfo[j].errorInfo);
                                comment1.Author = "数据比对助手";
                                cell.CellComment = comment1;
                            }
                            else
                            {
                                //原批注文本
                                string commentstr = cell.CellComment.String.String;
                                cell.CellComment.String = new HSSFRichTextString(commentstr + "\r\n" + AllResult[i].errorinfo[j].errorInfo);
                            }