/// <summary> /// 给单元格添加标注 /// </summary> /// <param name="row">单元格所在行</param> /// <param name="col">单元格所在列</param> /// <param name="comment">标注</param> public void AddCommentToCell(int row, int col, string commentTitle, string commentDetail) { string comment = string.Format("{0}\n{1}\n", commentTitle, commentDetail); // 设置单元格背景色 TFlxFormat fmt = xls.GetCellVisibleFormatDef(row, col); fmt.FillPattern.Pattern = TFlxPatternStyle.Solid; fmt.FillPattern.FgColor = Color.FromArgb(0xFF9999); xls.SetCellFormat(row, col, xls.AddFormat(fmt)); // 设置批注 TRTFRun[] Runs = new TRTFRun[3]; Runs[0].FirstChar = 0; TFlxFont fnt = xls.GetDefaultFont; fnt.Size20 = 180; fnt.Color = TExcelColor.Automatic; fnt.Style = TFlxFontStyles.Bold; fnt.Family = 3; fnt.CharSet = 134; fnt.Scheme = TFontScheme.None; Runs[0].FontIndex = xls.AddFont(fnt); Runs[1].FirstChar = 7; fnt = xls.GetDefaultFont; fnt.Size20 = 180; fnt.Color = TExcelColor.Automatic; fnt.Family = 3; fnt.CharSet = 134; fnt.Scheme = TFontScheme.None; Runs[1].FontIndex = xls.AddFont(fnt); Runs[2].FirstChar = 13; fnt = xls.GetDefaultFont; Runs[2].FontIndex = xls.AddFont(fnt); xls.SetComment(row, col, new TRichString(comment, Runs, xls)); }