internal TExcelString(TStrLenLength aStrLenLength, string s, TRTFRun[] RTFRuns, bool ForceWide) { StrLenLength = aStrLenLength; if (StrLenLength == TStrLenLength.is8bits) { if (s.Length > 0xFF) { XlsMessages.ThrowException(XlsErr.ErrInvalidStringRecord); } } OptionFlags = 0; if (ForceWide || StrOps.IsWide(s)) { OptionFlags = 1; } if ((RTFRuns != null) && (RTFRuns.Length > 0)) { OptionFlags = (byte)(OptionFlags | 8); RichTextFormats = TRTFRun.ToByteArray(RTFRuns); } else { RichTextFormats = null; } FarEastData = null; Data = s; //We have to include all data on the hash. Hash = GetHashString().GetHashCode(); }
internal TRTFRun[] AdaptFontList(TRichString Source) { if (Source == null || Source.RTFRunCount == 0) { return(new TRTFRun[0]); } TRTFRun[] Result = new TRTFRun[Source.RTFRunCount]; for (int i = 0; i < Source.RTFRunCount; i++) { Result[i].FirstChar = Source.RTFRun(i).FirstChar; Result[i].FontIndex = FontList.AddFont(Source.GetFont(Source.RTFRun(i).FontIndex)); } return(Result); }
internal override object GetValue(ICellList Cells) { TxBaseRecord MySelf = new TxBaseRecord(Id, Data); int MyOfs = 6; TExcelString XS = new TExcelString(TStrLenLength.is16bits, ref MySelf, ref MyOfs); byte[] b = new byte[2]; BitOps.ReadMem(ref MySelf, ref MyOfs, b); TRTFRun[] RTFRuns = new TRTFRun[BitOps.GetWord(b, 0)]; for (int i = 0; i < RTFRuns.Length; i++) { BitOps.ReadMem(ref MySelf, ref MyOfs, b); RTFRuns[i].FirstChar = BitOps.GetWord(b, 0); BitOps.ReadMem(ref MySelf, ref MyOfs, b); RTFRuns[i].FontIndex = BitOps.GetWord(b, 0); } return(new TRichString(XS.Data, RTFRuns, Cells.Workbook)); }
/// <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)); }
private void AddChart(ExcelFile xls) { //This code is adapted from APIMate. //Objects TShapeProperties ChartOptions1 = new TShapeProperties(); ChartOptions1.Anchor = new TClientAnchor(TFlxAnchorType.MoveAndResize, 1, 215, 1, 608, 30, 228, 17, 736); ChartOptions1.ShapeName = "Lines of code"; ChartOptions1.Print = true; ChartOptions1.Visible = true; ChartOptions1.ShapeOptions.SetValue(TShapeOption.fLockText, true); ChartOptions1.ShapeOptions.SetValue(TShapeOption.LockRotation, true); ChartOptions1.ShapeOptions.SetValue(TShapeOption.fAutoTextMargin, true); ChartOptions1.ShapeOptions.SetValue(TShapeOption.fillColor, 134217806); ChartOptions1.ShapeOptions.SetValue(TShapeOption.wzName, "Lines of code"); ExcelChart Chart1 = xls.AddChart(ChartOptions1, TChartType.Area, new ChartStyle(102), false); TDataLabel Title = new TDataLabel(); Title.PositionZeroBased = null; ChartFillOptions TextFillOptions = new ChartFillOptions(new TShapeFill(new TSolidFill(TDrawingColor.FromRgb(0x80, 0x80, 0x80)), true, TFormattingType.Subtle, TDrawingColor.FromRgb(0x00, 0x00, 0x00, new TColorTransform(TColorTransformType.Alpha, 0)), false)); TChartTextOptions LabelTextOptions = new TChartTextOptions(new TFlxChartFont("Calibri Light", 320, TExcelColor.FromArgb(0x80, 0x80, 0x80), TFlxFontStyles.Bold, TFlxUnderline.None, TFontScheme.Major), THFlxAlignment.center, TVFlxAlignment.center, TBackgroundMode.Transparent, TextFillOptions); Title.TextOptions = LabelTextOptions; TDataLabelOptions LabelOptions = new TDataLabelOptions(); Title.LabelOptions = LabelOptions; ChartLineOptions ChartLineOptions = new ChartLineOptions(new TShapeLine(true, new TLineStyle(new TNoFill(), null), null, TFormattingType.Subtle)); ChartFillOptions ChartFillOptions = new ChartFillOptions(new TShapeFill(new TNoFill(), false, TFormattingType.Subtle, null, false)); Title.Frame = new TChartFrameOptions(ChartLineOptions, ChartFillOptions, false); TRTFRun[] Runs; Runs = new TRTFRun[1]; Runs[0].FirstChar = 0; TFlxFont fnt; fnt = xls.GetDefaultFont; fnt.Name = "Calibri Light"; fnt.Size20 = 320; fnt.Color = TExcelColor.FromArgb(0x80, 0x80, 0x80); fnt.Style = TFlxFontStyles.Bold; fnt.Family = 0; fnt.CharSet = 1; fnt.Scheme = TFontScheme.Major; Runs[0].FontIndex = xls.AddFont(fnt); TRichString LabelValue1 = new TRichString("FlexCel: Lines of code over time", Runs, xls); Title.LabelValues = new Object[] { LabelValue1 }; Chart1.SetTitle(Title); Chart1.Background = new TChartFrameOptions(TDrawingColor.FromTheme(TThemeColor.Dark1, new TColorTransform(TColorTransformType.LumMod, 0.15), new TColorTransform(TColorTransformType.LumOff, 0.85)), 9525, TDrawingColor.FromTheme(TThemeColor.Light1), false); TChartFrameOptions PlotAreaFrame; ChartLineOptions = new ChartLineOptions(new TShapeLine(true, new TLineStyle(new TNoFill(), null), null, TFormattingType.Subtle)); ChartFillOptions = new ChartFillOptions(new TShapeFill(new TPatternFill(TDrawingColor.FromTheme(TThemeColor.Dark1, new TColorTransform(TColorTransformType.LumMod, 0.15), new TColorTransform(TColorTransformType.LumOff, 0.85)), TDrawingColor.FromTheme(TThemeColor.Light1), TDrawingPattern.ltDnDiag), true, TFormattingType.Subtle, null, false)); PlotAreaFrame = new TChartFrameOptions(ChartLineOptions, ChartFillOptions, false); TChartPlotAreaPosition PlotAreaPos = new TChartPlotAreaPosition(true, TChartRelativeRectangle.Automatic, TChartLayoutTarget.Inner, true); Chart1.PlotArea = new TChartPlotArea(PlotAreaFrame, PlotAreaPos, false); Chart1.SetChartOptions(1, new TAreaChartOptions(false, TStackedMode.Stacked, null)); int LastYear = 0; double shade = 1; for (int i = 2; i < 190; i++) { ChartSeries Series = new ChartSeries( "=" + new TCellAddress("Data", 1, i, true, true).CellRef, "=" + new TCellAddress("Data", 2, i, true, true).CellRef + ":" + new TCellAddress("Data", 189, i, true, true).CellRef, "=Data!$A$2:$A$189"); //We will display every year in a single color. Each month gets its own shade. int xf = -1; int Year = FlxDateTime.FromOADate(((double)xls.GetCellValue(2, 1, i, ref xf)), false).Year; if (LastYear != Year) { shade = 1; } else if (shade > 0.3) { shade -= 0.05; } LastYear = Year; TDrawingColor SeriesColor = TDrawingColor.FromTheme(TThemeColor.Accent1 + Year % 6, new TColorTransform(TColorTransformType.Shade, shade)); ChartSeriesFillOptions SeriesFill = new ChartSeriesFillOptions(new TShapeFill(new TSolidFill(SeriesColor), true, TFormattingType.Subtle, null, false), null, false, false); ChartSeriesLineOptions SeriesLine = new ChartSeriesLineOptions(new TShapeLine(true, new TLineStyle(new TNoFill(), null), null, TFormattingType.Subtle), false); Series.Options.Add(new ChartSeriesOptions(-1, SeriesFill, SeriesLine, null, null, null, true)); Chart1.AddSeries(Series); } Chart1.PlotEmptyCells = TPlotEmptyCells.Zero; Chart1.ShowDataInHiddenRowsAndCols = false; TFlxChartFont AxisFont = new TFlxChartFont("Calibri", 180, TExcelColor.FromArgb(0x59, 0x59, 0x59), TFlxFontStyles.None, TFlxUnderline.None, TFontScheme.Minor); TAxisLineOptions AxisLine = new TAxisLineOptions(); AxisLine.MainAxis = new ChartLineOptions(new TShapeLine(true, new TLineStyle(new TSolidFill(TDrawingColor.FromTheme(TThemeColor.Dark1, new TColorTransform(TColorTransformType.LumMod, 0.15), new TColorTransform(TColorTransformType.LumOff, 0.85))), 9525, TPenAlignment.Center, TLineCap.Flat, TCompoundLineType.Single, null, TLineJoin.Round, null, null, null), null, TFormattingType.Subtle)); AxisLine.DoNotDrawLabelsIfNotDrawingAxis = false; TAxisTickOptions AxisTicks = new TAxisTickOptions(TTickType.Outside, TTickType.None, TAxisLabelPosition.NextToAxis, TBackgroundMode.Transparent, TDrawingColor.FromRgb(0x59, 0x59, 0x59), 0); TAxisRangeOptions AxisRangeOptions = new TAxisRangeOptions(12, 1, false, false, false); TBaseAxis CatAxis = new TCategoryAxis(0, 0, 12, TDateUnits.Days, 12, TDateUnits.Days, TDateUnits.Months, 0, TCategoryAxisOptions.AutoMin | TCategoryAxisOptions.AutoMax | TCategoryAxisOptions.DateAxis | TCategoryAxisOptions.AutoCrossDate | TCategoryAxisOptions.AutoDate, AxisFont, "yyyy\\-mm\\-dd;@", true, AxisLine, AxisTicks, AxisRangeOptions, null, TChartAxisPos.Bottom, 1); AxisFont = new TFlxChartFont("Calibri", 180, TExcelColor.FromArgb(0x59, 0x59, 0x59), TFlxFontStyles.None, TFlxUnderline.None, TFontScheme.Minor); AxisLine = new TAxisLineOptions(); AxisLine.MainAxis = new ChartLineOptions(new TShapeLine(true, new TLineStyle(new TSolidFill(TDrawingColor.FromTheme(TThemeColor.Dark1, new TColorTransform(TColorTransformType.LumMod, 0.15), new TColorTransform(TColorTransformType.LumOff, 0.85))), 9525, TPenAlignment.Center, TLineCap.Flat, TCompoundLineType.Single, null, TLineJoin.Round, null, null, null), null, TFormattingType.Subtle)); AxisLine.MajorGridLines = new ChartLineOptions(new TShapeLine(true, new TLineStyle(new TSolidFill(TDrawingColor.FromTheme(TThemeColor.Dark1, new TColorTransform(TColorTransformType.LumMod, 0.15), new TColorTransform(TColorTransformType.LumOff, 0.85))), 9525, TPenAlignment.Center, TLineCap.Flat, TCompoundLineType.Single, null, TLineJoin.Round, null, null, null), null, TFormattingType.Subtle)); AxisLine.DoNotDrawLabelsIfNotDrawingAxis = false; AxisTicks = new TAxisTickOptions(TTickType.None, TTickType.None, TAxisLabelPosition.NextToAxis, TBackgroundMode.Transparent, TDrawingColor.FromRgb(0x59, 0x59, 0x59), 0); CatAxis.NumberFormat = "yyyy-mm"; CatAxis.NumberFormatLinkedToSource = false; TBaseAxis ValAxis = new TValueAxis(0, 0, 0, 0, 0, TValueAxisOptions.AutoMin | TValueAxisOptions.AutoMax | TValueAxisOptions.AutoMajor | TValueAxisOptions.AutoMinor | TValueAxisOptions.AutoCross, AxisFont, "General", true, AxisLine, AxisTicks, null, TChartAxisPos.Left); Chart1.SetChartAxis(new TChartAxis(0, CatAxis, ValAxis)); }