Ejemplo n.º 1
0
 internal void SetText(TRichString value)
 {
     if (Dwg == null)
     {
         return;
     }
     else
     {
         TEscherRecord R = Dwg.FindRoot();
         if (R == null)
         {
             return;
         }
         else
         {
             R = R.FindRec <TEscherClientTextBoxRecord>();
             if (R == null)
             {
                 return;
             }
             else
             {
                 ((TEscherClientTextBoxRecord)R).SetValue(value);
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// CreateFromData
        /// </summary>
        internal TNoteRecord(int aRow, int aCol, TRichString aTxt, string aAuthor, TDrawing Drawing, TImageProperties Properties,
                             ExcelFile xls, TSheet sSheet, bool ReadFromXlsx)
            : base((int)xlr.NOTE, aCol)
        {
            if ((aCol < 0) || (aCol > FlxConsts.Max_Columns))
            {
                XlsMessages.ThrowException(XlsErr.ErrXlsIndexOutBounds, aCol, "Column", 0, FlxConsts.Max_Columns);
            }

            Dwg = Drawing.AddNewComment(xls, Properties, sSheet, ReadFromXlsx);
            TEscherImageAnchorRecord Anchor = GetImageRecord();

            if (Anchor != null)
            {
                NoteTextBox = Anchor.SaveCommentCoords(sSheet, aRow, aCol);
            }

            Col         = aCol;
            OptionFlags = 0;   //option flags
            unchecked
            {
                ObjId = (UInt16)Dwg.ObjId;   //object id
            }

            Author = aAuthor;

            SetText(aTxt);
        }
Ejemplo n.º 3
0
        internal void AddNewComment(int Row, int Col, TRichString Txt, string Author, TDrawing Drawing, TImageProperties Properties,
                                    ExcelFile xls, TSheet sSheet, bool ReadFromXlsx)
        {
            TNoteRecord R = new TNoteRecord(Row, Col, Txt, Author, Drawing, Properties, xls, sSheet, ReadFromXlsx); //.CreateFromData

            AddRecord(R, Row);
        }
Ejemplo n.º 4
0
        internal static TRichString GetVisualString(TRichString Text, bool ReverseRightToLeftStrings)
        {
            if (!ReverseRightToLeftStrings || Text == null || Text.Length < 2)
            {
                return(Text);
            }
            BidiReference bref = new BidiReference(Text.Value);

            int[] lines        = { Text.Length };
            int[] ReorderArray = bref.getReordering(lines);

            bool ToLeft = true;

            for (int i = 0; i < ReorderArray.Length; i++)
            {
                if (ReorderArray[i] != i)
                {
                    ToLeft = false;
                    break;
                }
            }

            if (ToLeft)
            {
                return(Text);
            }
            char[] Result = new char[ReorderArray.Length];
            for (int i = 0; i < Result.Length; i++)
            {
                Result[i] = Text[ReorderArray[i]];
            }

            return(new TRichString(new string(Result)));
        }
Ejemplo n.º 5
0
 internal TXRichString(TRichString aString, bool aSplit, real aXExtent, real aYExtent, TAdaptativeFormats aAdaptFormat)
 {
     s           = aString;
     Split       = aSplit;
     XExtent     = aXExtent;
     YExtent     = aYExtent;
     AdaptFormat = aAdaptFormat;
 }
Ejemplo n.º 6
0
 internal TLabelSSTRecord(int aCol, int aXF, TSST aSST, IFlexCelFontList aFontList, TRichString Value)
     : base((int)xlr.LABELSST, aCol, aXF)
 {
     SST          = aSST;
     FontList     = aFontList;
     pSSTEntry    = null;
     AsRichString = Value;
 }
Ejemplo n.º 7
0
 internal TReplace(bool aDates1904, object aSearchItem, object aNewValue, bool aCaseInsensitive, bool aSearchInFormulas, bool aWholeCellContents) : base(aDates1904, aSearchItem, aCaseInsensitive, aSearchInFormulas, aWholeCellContents)
 {
     NewValue = aNewValue as TRichString;
     if (NewValue == null && aNewValue != null)
     {
         NewValue = new TRichString(aNewValue.ToString());
     }
     if (NewValue == null)
     {
         NewValue = new TRichString();
     }
 }
Ejemplo n.º 8
0
        internal static TLabelSSTRecord CreateFromOtherString(int aCol, int aXF, TSST aSST, IFlexCelFontList aFontList, object Value)
        {
            TRichString rs = Value as TRichString;

            if (rs != null && rs.RTFRunCount > 0)
            {
                return(new TLabelSSTRecord(aCol, aXF, aSST, aFontList, rs));
            }
            else
            {
                return(new TLabelSSTRecord(aCol, aXF, aSST, aFontList, FlxConvert.ToStringWithArrays(Value)));
            }
        }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
        internal static TRichString ArabicShape(TRichString Text, bool ReverseRightToLeftStrings)
        {
            if (!ReverseRightToLeftStrings || Text == null || Text.Length < 2)
            {
                return(Text);
            }

            ArabicShaping Ashaping = new ArabicShaping(ArabicShaping.LENGTH_GROW_SHRINK +
                                                       ArabicShaping.TEXT_DIRECTION_LOGICAL + ArabicShaping.LETTERS_SHAPE);
            string SResult = Ashaping.shape(Text.Value);

            if (String.Equals(Text.Value, SResult, StringComparison.InvariantCulture))
            {
                return(Text);
            }
            return(new TRichString(SResult));
        }
Ejemplo n.º 11
0
        private static void WriteJustText(ExcelFile Workbook, IFlxGraphics Canvas, TFontCache FontCache, real Zoom100, bool ReverseRightToLeftStrings, Font AFont, Color AFontColor, real y, real SubOfs, RectangleF CellRect, real Clp, TRichString OutText, real XExtent, real MaxDescent, bool Distributed, TAdaptativeFormats AdaptativeFormats)
        {
            List <TRichString> Words = new List <TRichString>();

            OutText = GetVisualString(OutText, ReverseRightToLeftStrings);
            string s = OutText.Value;
            int    p = 0; int p1 = 0;

            while ((p1 = s.IndexOf(' ', p)) >= 0)
            {
                Words.Add(OutText.Substring(p, p1 - p + 1));
                p = p1 + 1;
            }

            if (p < s.Length)
            {
                Words.Add(OutText.Substring(p));
            }

            real md;
            real wc = XExtent; // CalcTextExtent(AFont, OutText, out md).Width;

            real Spaces = 0;

            if (Words.Count - 1 > 0)
            {
                Spaces = (CellRect.Width - 2 - 2 * Clp - wc) / (Words.Count - 1);
            }

            real x = CellRect.Left + 1 + Clp;

            if (Words.Count == 1 && Distributed)  //Center when it is one word
            {
                x = (CellRect.Left + CellRect.Right - 2 - 2 * Clp - wc) / 2;
            }
            for (int i = 0; i < Words.Count; i++)
            {
                TRichString wo = Words[i];
                WriteText(Workbook, Canvas, FontCache, Zoom100, AFont, AFontColor, x, y, SubOfs, wo, 0, MaxDescent, AdaptativeFormats);
                x += RenderMetrics.CalcTextExtent(Canvas, FontCache, Zoom100, AFont, wo, out md).Width;
                if (Spaces > 0)
                {
                    x += Spaces;
                }
            }
        }
Ejemplo n.º 12
0
        internal static RectangleF CalcTextCoords(out real[] X, out real[] Y, TRichString OutText, TVAlign VAlign,
                                                  ref THAlign HAlign, real Indent, real Alpha, RectangleF CellRect, real Clp, SizeF TextExtent,
                                                  bool FmtGeneral, bool Vertical, real SinAlpha, real CosAlpha, TXRichStringList TextLines, double Linespacing0, TVFlxAlignment VJustify)
        {
            double Linespacing = VJustify == TVFlxAlignment.distributed || VJustify == TVFlxAlignment.justify ? 1.0 : Linespacing0;

            bool TextLeftToRight = IsLeftToRight(OutText.ToString());

            X = new real[TextLines.Count]; Y = new real[TextLines.Count];

            if (Alpha == 0)              //optimize the most common case
            {
                return(CalcTextCoordsAlpha0(X, Y, VAlign, ref HAlign, Indent, ref CellRect, Clp, ref TextExtent, FmtGeneral, Vertical, TextLeftToRight, TextLines, Linespacing));
            }

            else
            {
                // There is rotation. Now values of TextExtent are not ok, since lines will stack.for example ///////  Each line has the same y, and the x is calculated as height/cosAlpha
                return(CalcTextCoordsRotated(X, Y, VAlign, HAlign, Alpha, ref CellRect, Clp, FmtGeneral, SinAlpha, CosAlpha, TextLines, Linespacing));
            }
        }
Ejemplo n.º 13
0
        internal override bool OnFound(ExcelFile xls, object oldval, int row, int col)
        {
            TFormula oldFmla = oldval as TFormula;

            if (!FSearchInFormulas && oldFmla != null)
            {
                return(false);                                                   //do not replace if it is a formula.
            }
            if (oldval == null)
            {
                return(false);
            }

            TRichString OldStr = oldval as TRichString;

            if (OldStr == null)
            {
                OldStr = new TRichString(FlxConvert.ToString(oldval));
            }
            TRichString newStr = OldStr.Replace(SearchToStr, NewValue.ToString(), FCaseInsensitive);

            if (newStr != null && newStr.Value != null && newStr.Length > 0 && newStr.Value.StartsWith(TFormulaMessages.TokenString(TFormulaToken.fmStartFormula)))
            {
                TFormulaSpan Span = oldFmla != null ? oldFmla.Span : new TFormulaSpan();
                xls.SetCellValue(row, col, new TFormula(newStr.Value, null, Span));
            }
            else
            {
                if (oldFmla != null && !oldFmla.Span.IsOneCell)
                {
                    return(false);                                            //can't replace a shared formula with simple text.
                }
                xls.SetCellFromString(row, col, newStr);
            }

            ReplaceCount++;
            return(false);
        }
Ejemplo n.º 14
0
        internal static void CalcTextBox(IFlxGraphics Canvas, TFontCache FontCache, real Zoom100, RectangleF CellRect, real Clp, bool MultiLine, real Alpha, bool Vertical, TRichString OutText, Font AFont, TAdaptativeFormats AdaptativeFormats, out SizeF TextExtent, out TXRichStringList TextLines, out TFloatList MaxDescent)
        {
            TextExtent = new SizeF(0, 0);
            TextLines  = new TXRichStringList();

            MaxDescent = new TFloatList();
            real MaxTextWidth;

            if (MultiLine || Vertical)
            {
                real Md;
                real TextHeight = RenderMetrics.CalcTextExtent(Canvas, FontCache, Zoom100, AFont, new TRichString("M"), out Md).Height; //not perfect since the rich string might have different fonts, but a good approx.
                MaxTextWidth = CalcMaxTextWidth(ref CellRect, Clp, Alpha, TextHeight);

                RenderMetrics.SplitText(Canvas, FontCache, Zoom100, OutText, AFont, MaxTextWidth, TextLines, out TextExtent, Vertical, MaxDescent, AdaptativeFormats);
            }
            else
            {
                TextLines.Add(new TXRichString(OutText, false, 0, 0, AdaptativeFormats));
                real mdx = 0;
                TextExtent           = RenderMetrics.CalcTextExtent(Canvas, FontCache, Zoom100, AFont, OutText, out mdx);
                TextLines[0].XExtent = TextExtent.Width;
                TextLines[0].YExtent = TextExtent.Height;
                MaxTextWidth         = CalcMaxTextWidth(ref CellRect, Clp, Alpha, TextExtent.Height);
                MaxDescent.Add(mdx);
            }

            if (AdaptativeFormats != null && AdaptativeFormats.WildcardPos >= 0)
            {
                MaxTextWidth -= 2 * Clp; //Add some extra clipping so the text doesn't go through the line.
                if (Vertical)
                {
                }
                else
                {
                    AddWildcard(Canvas, FontCache, Zoom100, AFont, MaxTextWidth, TextLines, ref TextExtent);
                }
            }
        }
Ejemplo n.º 15
0
        public static DataSet ToDataSet(byte[] data, bool firstRowIsPropertyName = true)
        {
            bool    formatted = false;
            DataSet dataSet   = new DataSet();

            Stream stream = new MemoryStream(data);

            XlsFile xls = new XlsFile(false);

            xls.Open(stream);

            for (int sheet = 1; sheet <= xls.SheetCount; sheet++)
            {
                xls.ActiveSheet = sheet;

                DataTable Data = dataSet.Tables.Add("Sheet" + sheet.ToString());
                Data.BeginLoadData();

                try
                {
                    int ColCount      = xls.ColCount;
                    int beginIndexRow = 1;

                    if (firstRowIsPropertyName)
                    {
                        beginIndexRow = 2;
                        for (int c = 1; c <= ColCount; c++)
                        {
                            int    r        = 1;
                            int    XF       = 0; // This is the cell format, we will not use it here.
                            object val      = xls.GetCellValueIndexed(r, c, ref XF);
                            string propName = string.Empty;

                            TFormula Fmla = val as TFormula;
                            propName = Convert.ToString(Fmla != null ? Fmla.Result : val);

                            Data.Columns.Add(propName, typeof(String));
                        }
                    }
                    else
                    {
                        beginIndexRow = 1;
                        // Add one column on the dataset for each used column on Excel.
                        for (int c = 1; c <= ColCount; c++)
                        {
                            // Here we will add all strings, since we do not know what we are waiting for.
                            Data.Columns.Add(TCellAddress.EncodeColumn(c), typeof(String));
                        }
                    }

                    string[] dr = new string[ColCount];

                    int rowCount = xls.RowCount;
                    for (int r = beginIndexRow; r <= rowCount; r++)
                    {
                        Array.Clear(dr, 0, dr.Length);
                        //This loop will only loop on used cells. It is more efficient than looping on all the columns.
                        for (int cIndex = xls.ColCountInRow(r); cIndex > 0; cIndex--)  //reverse the loop to avoid calling ColCountInRow more than once.
                        {
                            int Col = xls.ColFromIndex(r, cIndex);

                            if (formatted)
                            {
                                TRichString rs = xls.GetStringFromCell(r, Col);
                                dr[Col - 1] = rs.Value;
                            }
                            else
                            {
                                int    XF  = 0; //This is the cell format, we will not use it here.
                                object val = xls.GetCellValueIndexed(r, cIndex, ref XF);

                                TFormula Fmla = val as TFormula;
                                if (Fmla != null)
                                {
                                    //When we have formulas, we want to write the formula result.
                                    //If we wanted the formula text, we would not need this part.
                                    dr[Col - 1] = Convert.ToString(Fmla.Result);
                                }
                                else
                                {
                                    dr[Col - 1] = Convert.ToString(val);
                                }
                            }
                        }
                        Data.Rows.Add(dr);
                    }
                }
                finally
                {
                    Data.EndLoadData();
                }
            }

            return(dataSet);
        }
Ejemplo n.º 16
0
 ///<inheritdoc />
 public override void SetObjectText(int objectIndex, string objectPath, TRichString text)
 {
     CheckConnected();
     CheckRangeObjPath(objectPath, objectIndex, 1, ObjectCount, FlxParam.ObjectIndex);
     CurrentChart.Drawing.SetObjectText(objectIndex - 1, objectPath, text, Workbook, null);
 }
Ejemplo n.º 17
0
        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));
        }
Ejemplo n.º 18
0
        internal static void FitOneLine(IFlxGraphics Canvas, TFontCache FontCache, real Zoom100, TRichString Text, Font AFont, real w, int idx, ref int fit, ref real StrWidth)
        {
            if (StrWidth > w)
            {
                real md = 0;

                fit = Math.Max((int)Math.Round(fit * w / StrWidth), 1);
                CharUtils.SameOrMore(Text.Value, idx, ref fit);
                StrWidth = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, Text.Substring(idx, fit), out md).Width;

                if (StrWidth > w)
                {
                    while (fit > 1 && StrWidth > w)
                    {
                        fit--;
                        CharUtils.SameOrLess(Text.Value, idx, ref fit);
                        StrWidth = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, Text.Substring(idx, fit), out md).Width;
                    }
                }
                else
                {
                    while (StrWidth < w) //Will not overflow, as wc>w for fit+idx=MaxLength.
                    {
                        int fit1 = fit + 1;
                        CharUtils.SameOrMore(Text.Value, idx, ref fit1);
                        StrWidth = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, Text.Substring(idx, fit1), out md).Width;
                        if (StrWidth < w)
                        {
                            fit = fit1;
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
0
 internal void SetValue(TRichString value)
 {
     ((TTXO)ClientData).SetText(value);
 }
Ejemplo n.º 20
0
 public bool TryGetValue(TRichString key, out TOneCellValue Result)
 {
     Result = (TOneCellValue)this[key];
     return(Result != null);
 }
Ejemplo n.º 21
0
        internal int CalcCellHeight(int Row, int Col, TRichString val, int CellXF, ExcelFile Workbook, real RowMultDisplay, real ColMultDisplay, TMultipleCellAutofitList MultipleRowAutofits)
        {
            if (CellXF < 0)
            {
                return(0xFF);
            }
            if (CellXF >= XFHeight.Length)
            {
                return(0xFF);                                        //Just to make sure. We don't want a wrong file to blow here.
            }
            int Result  = XFHeight[CellXF];
            int Result0 = Result;

            if (val == null)
            {
                return(Result);
            }

            TXFRecord XFRec = Wg.CellXF[CellXF];
            bool      Vertical;
            real      Alpha = FlexCelRender.CalcAngle(XFRec.Rotation, out Vertical);


            if (!XFRec.WrapText && !Vertical && Alpha == 0)
            {
                return(Result);
            }

            Font AFont = gr.FontCache.GetFont(XFFonts[CellXF], 1);

            RectangleF    CellRect = new RectangleF();
            TXlsCellRange rg       = Workbook.CellMergedBounds(Row, Col);

            for (int c = rg.Left; c <= rg.Right; c++)
            {
                CellRect.Width += Workbook.GetColWidth(c, true) / ColMultDisplay;
            }

            SizeF            TextExtent;
            TXRichStringList TextLines  = new TXRichStringList();
            TFloatList       MaxDescent = new TFloatList();

            real Clp = 1 * FlexCelRender.DispMul / 100f;
            real Wr  = 0;

            if (Alpha == 0)
            {
                Wr = CellRect.Right - CellRect.Left - 2 * Clp;
            }
            else
            {
                Wr = 1e6f;                 //When we have an angle, it means "make the row as big as needed to fit". So SplitText needs no limits.
            }


            RenderMetrics.SplitText(gr.Canvas, gr.FontCache, 1, val, AFont, Wr, TextLines, out TextExtent, Vertical, MaxDescent, null);

            if (TextLines.Count <= 0)
            {
                return(Result);
            }

            real H = 0;
            real W = 0;

            for (int i = 0; i < TextLines.Count; i++)
            {
                H += TextLines[i].YExtent;
                if (TextLines[i].XExtent > W)
                {
                    W = TextLines[i].XExtent;
                }
            }

            if (Alpha != 0)
            {
                real SinAlpha = (real)Math.Sin(Alpha * Math.PI / 180); real CosAlpha = (real)Math.Cos(Alpha * Math.PI / 180);
                H = H * CosAlpha + W * Math.Abs(SinAlpha);
            }
            Result = (int)Math.Ceiling(RowMultDisplay * (H + 2 * Clp));

            if (rg.RowCount > 1)
            {
                if (MultipleRowAutofits != null)
                {
                    MultipleRowAutofits.Add(new TMultipleCellAutofit(rg, Result));
                }
                return(Result0);                //We will autofit this later.
            }
            if (Result < 0)
            {
                Result = 0;
            }

            return(Result);
        }
Ejemplo n.º 22
0
        internal static void DrawRichText(ExcelFile Workbook, IFlxGraphics Canvas, TFontCache FontCache, real Zoom100, bool ReverseRightToLeftStrings,
                                          ref RectangleF CellRect, ref RectangleF PaintClipRect, ref RectangleF TextRect, ref RectangleF ContainingRect,
                                          real Clp, THFlxAlignment HJustify, TVFlxAlignment VJustify, real Alpha,
                                          Color DrawFontColor, TSubscriptData SubData, TRichString OutText, SizeF TextExtent,
                                          TXRichStringList TextLines,
                                          Font AFont, TFloatList MaxDescent, real[] X, real[] Y)
        {
            RectangleF FinalRect = CellRect;

            if (ContainingRect.Right > PaintClipRect.Left &&
                ContainingRect.Left < PaintClipRect.Right &&
                Intersect(TextRect, PaintClipRect, out FinalRect))
            {
                real dy             = 0;
                int  TextLinesCount = TextLines.Count;

                if (VJustify == TVFlxAlignment.justify || VJustify == TVFlxAlignment.distributed)
                {
                    if (TextLinesCount > 1)
                    {
                        dy = (CellRect.Height - TextExtent.Height - 2 * Clp) / (TextLinesCount - 1);
                    }
                }

                float eps = 0.0001F; //Tolerance for the comparison, these are floats, not doubles, and we get rounding errors soon.
                if (TextRect.Left - eps <= ContainingRect.Left && TextRect.Right + eps >= ContainingRect.Right && TextRect.Top - eps <= ContainingRect.Top && TextRect.Bottom + eps >= ContainingRect.Bottom)
                {
                    Canvas.SetClipReplace(PaintClipRect);                      //This will improve pdf export a lot, since we can now join all the BT/ET tags inside one, and then we can also join fonts inside the ET/BT tags.
                }
                else
                {
                    if (Alpha == 0 || Alpha == 90)
                    {
                        Canvas.SetClipReplace(FinalRect);
                    }
                    else
                    {
                        Canvas.SetClipReplace(RectangleF.FromLTRB(PaintClipRect.Left, FinalRect.Top, PaintClipRect.Right, FinalRect.Bottom));                         //rotated text can move to other used cells horizontally.
                    }
                }

                real AcumDy = 0;
                for (int i = 0; i < TextLinesCount; i++)
                {
                    TXRichString TextLine = TextLines[i];
                    if ((Alpha == 0) &&
                        (HJustify == THFlxAlignment.justify && TextLine.Split) ||
                        (HJustify == THFlxAlignment.distributed)
                        )
                    {
                        Canvas.SetClipReplace(FinalRect);
                        WriteJustText(Workbook, Canvas, FontCache, Zoom100, ReverseRightToLeftStrings,
                                      AFont, DrawFontColor, Y[i] + AcumDy, SubData.Offset(Canvas, AFont), CellRect, Clp, TextLine.s,
                                      TextLine.XExtent, MaxDescent[i], HJustify == THFlxAlignment.distributed, TextLine.AdaptFormat);
                    }
                    else
                    {
                        WriteText(Workbook, Canvas, FontCache, Zoom100, AFont, DrawFontColor, X[i],
                                  Y[i] + AcumDy, SubData.Offset(Canvas, AFont), GetVisualString(TextLine.s, ReverseRightToLeftStrings),
                                  Alpha, MaxDescent[i], TextLine.AdaptFormat);
                    }
                    AcumDy += dy;
                }
            }
        }
Ejemplo n.º 23
0
        internal static SizeF CalcTextExtent(IFlxGraphics Canvas, TFontCache FontCache, real Zoom100,
                                             Font AFont, TRichString Text, out real MaxDescent)
        {
            MaxDescent = Canvas.FontDescent(AFont);
            if (Text.RTFRunCount == 0)
            {
                return(Canvas.MeasureStringEmptyHasHeight(Text.Value, AFont));
            }

            real  x = 0;
            real  y = 0;
            SizeF Result;

            Result = Canvas.MeasureString(Text.Value.Substring(0, Text.RTFRun(0).FirstChar), AFont, new TPointF(0, 0));
            x      = Result.Width; y = Result.Height;


            for (int i = 0; i < Text.RTFRunCount - 1; i++)
            {
                TFlxFont       Fx     = Text.GetFont(Text.RTFRun(i).FontIndex);
                TSubscriptData Sub    = new TSubscriptData(Fx.Style);
                Font           MyFont = FontCache.GetFont(Fx, Zoom100 * Sub.Factor);
                {
                    int Start = Text.RTFRun(i).FirstChar;
                    if (Start >= Text.Length)
                    {
                        Start = Text.Length;
                    }
                    int Len = Text.RTFRun(i + 1).FirstChar;
                    if (Len >= Text.Length)
                    {
                        Len = Text.Length;
                    }
                    Len -= Start;
                    if (Len < 0)
                    {
                        continue;       //wrong file, (i+1)FirstChar < (i).FirstChar
                    }
                    Result     = Canvas.MeasureString(Text.Value.Substring(Start, Len), MyFont, new TPointF(0, 0));
                    x         += Result.Width; y = Math.Max(y + Sub.Offset(Canvas, MyFont), Result.Height);
                    MaxDescent = Math.Max(MaxDescent, Canvas.FontDescent(MyFont) + Sub.Offset(Canvas, MyFont));
                }
            }


            TFlxFont       Fy      = Text.GetFont(Text.RTFRun(Text.RTFRunCount - 1).FontIndex);
            TSubscriptData Suby    = new TSubscriptData(Fy.Style);
            Font           MyFont2 = FontCache.GetFont(Fy, Zoom100 * Suby.Factor);

            {
                int Start = Text.RTFRun(Text.RTFRunCount - 1).FirstChar;
                if (Start >= Text.Length)
                {
                    Start = Text.Length;
                }
                Result     = Canvas.MeasureStringEmptyHasHeight(Text.Value.Substring(Start), MyFont2);
                x         += Result.Width; y = Math.Max(y + Suby.Offset(Canvas, MyFont2), Result.Height);
                MaxDescent = Math.Max(MaxDescent, Canvas.FontDescent(MyFont2) + Suby.Offset(Canvas, MyFont2));
            }

            return(new SizeF(x, y));
        }
Ejemplo n.º 24
0
        internal static void WriteText(ExcelFile Workbook, IFlxGraphics Canvas, TFontCache FontCache, real Zoom100, Font AFont, Color AFontColor, real x, real y, real SubOfs, TRichString OutText, real Alpha, real MaxDescent, TAdaptativeFormats AdaptativeFormats)
        {
            if (OutText.Length == 0)
            {
                return;
            }

            if (Alpha != 0)
            {
                Canvas.SaveTransform();
            }
            try
            {
                if (Alpha != 0)
                {
                    Canvas.Rotate(x, y, Alpha);
                }

                using (Brush TextBrush = new SolidBrush(AFontColor))
                {
                    if (OutText.RTFRunCount == 0)
                    {
                        if (AdaptativeFormats == null || AdaptativeFormats.Separators == null || AdaptativeFormats.Separators.Length == 0) //formats are only applied to non rich text cells.
                        {
                            Canvas.DrawString(OutText.Value, AFont, TextBrush, x, y + SubOfs);
                        }
                        else
                        {
                            DrawAdaptativeString(Canvas, AdaptativeFormats, OutText.Value, AFont, TextBrush, x, y + SubOfs);
                        }
                    }
                    else
                    {
                        SizeF Result;

                        string s1 = OutText.Value.Substring(0, OutText.RTFRun(0).FirstChar);
                        if (s1.Length > 0)
                        {
                            Result = Canvas.MeasureString(s1, AFont, new TPointF(x, y));
                            Canvas.DrawString(s1, AFont, TextBrush, x, y + SubOfs - (MaxDescent - Canvas.FontDescent(AFont)));
                            x += Result.Width;
                        }

                        for (int i = 0; i < OutText.RTFRunCount - 1; i++)
                        {
                            TFlxFont       Fx     = OutText.GetFont(OutText.RTFRun(i).FontIndex);
                            TSubscriptData Sub    = new TSubscriptData(Fx.Style);
                            Font           MyFont = FontCache.GetFont(Fx, Zoom100 * Sub.Factor);
                            {
                                using (Brush MyBrush = new SolidBrush(GetColor(Workbook, Fx.Color)))
                                {
                                    int Start = OutText.RTFRun(i).FirstChar;
                                    if (Start >= OutText.Length)
                                    {
                                        Start = OutText.Length;
                                    }
                                    int Len = OutText.RTFRun(i + 1).FirstChar;
                                    if (Len >= OutText.Length)
                                    {
                                        Len = OutText.Length;
                                    }
                                    Len -= Start;

                                    string s2 = OutText.Value.Substring(Start, Len);
                                    Result = Canvas.MeasureString(s2, MyFont, new TPointF(x, y));
                                    Canvas.DrawString(s2, MyFont, MyBrush, x, y + Sub.Offset(Canvas, MyFont) - (MaxDescent - Canvas.FontDescent(MyFont)));
                                    x += Result.Width;
                                }
                            }
                        }
                        TFlxFont       Fy      = OutText.GetFont(OutText.RTFRun(OutText.RTFRunCount - 1).FontIndex);
                        TSubscriptData Suby    = new TSubscriptData(Fy.Style);
                        Font           MyFont2 = FontCache.GetFont(Fy, Zoom100 * Suby.Factor);
                        {
                            using (Brush MyBrush = new SolidBrush(GetColor(Workbook, Fy.Color)))
                            {
                                int Start = OutText.RTFRun(OutText.RTFRunCount - 1).FirstChar;
                                if (Start >= OutText.Length)
                                {
                                    Start = OutText.Length;
                                }

                                string s3 = OutText.Value.Substring(Start);
                                Result = Canvas.MeasureString(s3, MyFont2, new TPointF(x, y));
                                Canvas.DrawString(s3, MyFont2, MyBrush, x, y + Suby.Offset(Canvas, MyFont2) - (MaxDescent - Canvas.FontDescent(MyFont2)));
                            }
                        }
                    }
                }
            }
            finally
            {
                if (Alpha != 0)
                {
                    Canvas.ResetTransform();
                }
            }
        }
Ejemplo n.º 25
0
        public bool Upload2(HttpPostedFileBase file)
        {
            bool          formatted  = false;
            List <string> sheetNames = new List <string>();
            DataSet       dataSet    = new DataSet();

            MemoryStream target = new MemoryStream();

            file.InputStream.CopyTo(target);
            byte[]   data     = target.ToArray();
            HttpFile httpFile = new HttpFile(file.FileName, file.ContentType, data);

            Stream stream = new MemoryStream(httpFile.Buffer);

            XlsFile xls = new XlsFile(false);

            xls.Open(stream);

            for (int sheet = 1; sheet <= xls.SheetCount; sheet++)
            {
                xls.ActiveSheet = sheet;

                sheetNames.Add(xls.SheetName);

                DataTable Data = dataSet.Tables.Add("Sheet" + sheet.ToString());
                Data.BeginLoadData();
                try
                {
                    int ColCount = xls.ColCount;
                    //Add one column on the dataset for each used column on Excel.
                    //for (int c = 1; c <= ColCount; c++)
                    //{
                    //    Data.Columns.Add(TCellAddress.EncodeColumn(c), typeof(String));  //Here we will add all strings, since we do not know what we are waiting for.
                    //}

                    for (int c = 1; c <= ColCount; c++)
                    {
                        int    r        = 1;
                        int    XF       = 0; //This is the cell format, we will not use it here.
                        object val      = xls.GetCellValueIndexed(r, c, ref XF);
                        string propName = string.Empty;

                        TFormula Fmla = val as TFormula;
                        propName = Convert.ToString(Fmla != null ? Fmla.Result : val);

                        Data.Columns.Add(propName, typeof(String));
                    }

                    string[] dr = new string[ColCount];

                    int RowCount = xls.RowCount;
                    for (int r = 2; r <= RowCount; r++)
                    {
                        Array.Clear(dr, 0, dr.Length);
                        //This loop will only loop on used cells. It is more efficient than looping on all the columns.
                        for (int cIndex = xls.ColCountInRow(r); cIndex > 0; cIndex--)  //reverse the loop to avoid calling ColCountInRow more than once.
                        {
                            int Col = xls.ColFromIndex(r, cIndex);

                            if (formatted)
                            {
                                TRichString rs = xls.GetStringFromCell(r, Col);
                                dr[Col - 1] = rs.Value;
                            }
                            else
                            {
                                int    XF  = 0; //This is the cell format, we will not use it here.
                                object val = xls.GetCellValueIndexed(r, cIndex, ref XF);

                                TFormula Fmla = val as TFormula;
                                if (Fmla != null)
                                {
                                    //When we have formulas, we want to write the formula result.
                                    //If we wanted the formula text, we would not need this part.
                                    dr[Col - 1] = Convert.ToString(Fmla.Result);
                                }
                                else
                                {
                                    dr[Col - 1] = Convert.ToString(val);
                                }
                            }
                        }
                        Data.Rows.Add(dr);
                    }
                }
                finally
                {
                    Data.EndLoadData();
                }
            }

            DataTable resultDt = dataSet.Tables[0];

            List <Student> Studentlist = new List <Student>();

            Studentlist = Convertor.ConvertToList <Student>(resultDt);

            //AutoMapper.Mapper.Initialize(cfg => cfg.CreateMissingTypeMaps = true);
            //var students = AutoMapper.Mapper.Map<IDataReader, IEnumerable<Student>>(resultDt.CreateDataReader());

            return(true);
        }
Ejemplo n.º 26
0
        private void AnalizeFile(string FileName, int Row, int Col)
        {
            XlsFile xls = new XlsFile();

            xls.Open(FileName);

            int XF = 0;

            MessageBox.Show("Active sheet is \"" + xls.ActiveSheetByName + "\"");
            object v = xls.GetCellValue(Row, Col, ref XF);

            if (v == null)
            {
                MessageBox.Show("Cell A1 is empty");
                return;
            }

            //Here we have all the kind of objects FlexCel can return.
            switch (Type.GetTypeCode(v.GetType()))
            {
            case TypeCode.Boolean:
                MessageBox.Show("Cell A1 is a boolean: " + (bool)v);
                return;

            case TypeCode.Double:      //Remember, dates are doubles with date format.
                TUIColor CellColor = Color.Empty;
                bool     HasDate, HasTime;
                String   CellValue = TFlxNumberFormat.FormatValue(v, xls.GetFormat(XF).Format, ref CellColor, xls, out HasDate, out HasTime).ToString();

                if (HasDate || HasTime)
                {
                    MessageBox.Show("Cell A1 is a DateTime value: " + FlxDateTime.FromOADate((double)v, xls.OptionsDates1904).ToString() + "\n" +
                                    "The value is displayed as: " + CellValue);
                }
                else
                {
                    MessageBox.Show("Cell A1 is a double: " + (double)v + "\n" +
                                    "The value is displayed as: " + CellValue + "\n");
                }
                return;

            case TypeCode.String:
                MessageBox.Show("Cell A1 is a string: " + v.ToString());
                return;
            }

            TFormula Fmla = v as TFormula;

            if (Fmla != null)
            {
                MessageBox.Show("Cell A1 is a formula: " + Fmla.Text + "   Value: " + Convert.ToString(Fmla.Result));
                return;
            }

            TRichString RSt = v as TRichString;

            if (RSt != null)
            {
                MessageBox.Show("Cell A1 is a formatted string: " + RSt.Value);
                return;
            }

            if (v is TFlxFormulaErrorValue)
            {
                MessageBox.Show("Cell A1 is an error: " + TFormulaMessages.ErrString((TFlxFormulaErrorValue)v));
                return;
            }

            throw new Exception("Unexpected value on cell");
        }
Ejemplo n.º 27
0
        internal static void SplitText(IFlxGraphics Canvas, TFontCache FontCache, real Zoom100,
                                       TRichString Text, Font AFont, real w, TXRichStringList TextLines, out SizeF TextExtent, bool Vertical, TFloatList MaxDescent, TAdaptativeFormats AdaptFormat)
        {
            TextLines.Clear();
            MaxDescent.Clear();

            int idx = 0;
            int fit = 0;


            TextExtent = new SizeF(0, 0);
            if (w <= 0 || Text.Value.Length <= 0)
            {
                return;
            }

            while (idx < Text.Value.Length)
            {
                int Enter     = Text.Value.IndexOf((char)0x0A, idx);
                int MaxLength = Text.Value.Length - idx;
                if (Enter >= 0)
                {
                    MaxLength = Enter - idx;
                }

                if (Vertical)
                {
                    fit = 1;
                    CharUtils.SameOrMore(Text.Value, idx, ref fit);
                }
                else
                {
                    //Not a really efficient way, but...
                    //First Guess. whole string.
                    fit = MaxLength;

                    real md;
                    real wc = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, Text.Substring(idx, fit), out md).Width;
                    FitOneLine(Canvas, FontCache, Zoom100, Text, AFont, w, idx, ref fit, ref wc);

                    if (fit <= 0)
                    {
                        fit = 1;                               //avoid infinite loop
                    }
                    CharUtils.SameOrMore(Text.Value, idx, ref fit);


                    if (Text.Value.IndexOf(' ', idx, fit) >= 0)
                    {
                        int minfit = 1;
                        CharUtils.SameOrMore(Text.Value, idx, ref minfit);
                        while (fit > minfit && fit < MaxLength && Text.Value[idx + fit] != ' ')
                        {
                            fit--;
                        }
                    }
                    while (fit < MaxLength && Text.Value[idx + fit] == ' ')
                    {
                        fit++;
                    }
                    //No need to adjust fit for surrogates. it will always be at the start of one.
                }

                //int Enter=Text.Value.IndexOf((char)0x0A, idx, fit);
                //if (Enter>0) fit=Enter-idx;
                int TextLen = Math.Min(MaxLength, fit);
                TextLines.Add(new TXRichString(Text.Substring(idx, TextLen), true, 0, 0, TAdaptativeFormats.CopyTo(AdaptFormat, idx, TextLen)));

                if (fit + idx < Text.Value.Length && Text.Value[idx + fit] == (char)0x0A)
                {
                    TextLines[TextLines.Count - 1].Split = false;
                    if (idx + fit < Text.Value.Length - 1)                  //An Enter at the end behaves different, it means we have a new empty line.
                    {
                        idx++;
                    }
                }
                if (fit + idx >= Text.Value.Length)
                {
                    TextLines[TextLines.Count - 1].Split = false;
                }

                idx += fit;

                //Recalculate dx
                real        mdx   = 0;
                TRichString sx    = TextLines[TextLines.Count - 1].s;
                SizeF       bSize = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, sx, out mdx);
                if (bSize.Height == 0)
                {
                    real  mdx3;
                    SizeF bSize3 = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, new TRichString("M"), out mdx3);
                    bSize.Height = bSize3.Height;
                }

                SizeF bSize2 = bSize;
                if (sx != null && sx.Length > 0 && sx.ToString()[sx.Length - 1] == ' ')             //This is to right align line with spaces at the end.
                {
                    real mdx2;
                    bSize2 = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, sx.RightTrim(), out mdx2);
                }
                TextLines[TextLines.Count - 1].XExtent = bSize2.Width;
                TextLines[TextLines.Count - 1].YExtent = bSize.Height;                 // not bSize2.Height; This might be even 0.

                MaxDescent.Add(mdx);
                if (TextExtent.Width < bSize.Width)
                {
                    TextExtent.Width = bSize.Width;
                }
                TextExtent.Height += bSize.Height;
            }             //while
        }
Ejemplo n.º 28
0
        private void ImportFile(string FileName, bool Formatted)
        {
            try
            {
                //Open the Excel file.
                XlsFile  xls       = new XlsFile(false);
                DateTime StartOpen = DateTime.Now;
                xls.Open(FileName);
                DateTime EndOpen = DateTime.Now;

                //Set up the Grid
                DisplayGrid.DataBindings.Clear();
                DisplayGrid.DataSource = null;
                DisplayGrid.DataMember = null;
                DataSet dataSet1 = new DataSet();
                sheetCombo.Items.Clear();

                //We will create a DataTable "SheetN" for each sheet on the Excel sheet.
                for (int sheet = 1; sheet <= xls.SheetCount; sheet++)
                {
                    xls.ActiveSheet = sheet;

                    sheetCombo.Items.Add(xls.SheetName);

                    DataTable Data = dataSet1.Tables.Add("Sheet" + sheet.ToString());
                    Data.BeginLoadData();
                    try
                    {
                        int ColCount = xls.ColCount;
                        //Add one column on the dataset for each used column on Excel.
                        for (int c = 1; c <= ColCount; c++)
                        {
                            Data.Columns.Add(TCellAddress.EncodeColumn(c), typeof(String));  //Here we will add all strings, since we do not know what we are waiting for.
                        }

                        string[] dr = new string[ColCount];

                        int RowCount = xls.RowCount;
                        for (int r = 1; r <= RowCount; r++)
                        {
                            Array.Clear(dr, 0, dr.Length);
                            //This loop will only loop on used cells. It is more efficient than looping on all the columns.
                            for (int cIndex = xls.ColCountInRow(r); cIndex > 0; cIndex--)  //reverse the loop to avoid calling ColCountInRow more than once.
                            {
                                int Col = xls.ColFromIndex(r, cIndex);

                                if (Formatted)
                                {
                                    TRichString rs = xls.GetStringFromCell(r, Col);
                                    dr[Col - 1] = rs.Value;
                                }
                                else
                                {
                                    int    XF  = 0; //This is the cell format, we will not use it here.
                                    object val = xls.GetCellValueIndexed(r, cIndex, ref XF);

                                    TFormula Fmla = val as TFormula;
                                    if (Fmla != null)
                                    {
                                        //When we have formulas, we want to write the formula result.
                                        //If we wanted the formula text, we would not need this part.
                                        dr[Col - 1] = Convert.ToString(Fmla.Result);
                                    }
                                    else
                                    {
                                        dr[Col - 1] = Convert.ToString(val);
                                    }
                                }
                            }
                            Data.Rows.Add(dr);
                        }
                    }
                    finally
                    {
                        Data.EndLoadData();
                    }

                    DateTime EndFill = DateTime.Now;
                    statusBar.Text = String.Format("Time to load file: {0}    Time to fill dataset: {1}     Total time: {2}", (EndOpen - StartOpen).ToString(), (EndFill - EndOpen).ToString(), (EndFill - StartOpen).ToString());
                }

                //Set up grid.
                DisplayGrid.DataSource   = dataSet1;
                DisplayGrid.DataMember   = "Sheet1";
                sheetCombo.SelectedIndex = 0;
                DisplayGrid.CaptionText  = FileName;
            }
            catch
            {
                DisplayGrid.CaptionText = "Error Loading File";
                DisplayGrid.DataSource  = null;
                DisplayGrid.DataMember  = "";
                sheetCombo.Items.Clear();
                throw;
            }
        }
Ejemplo n.º 29
0
        internal int CalcCellWidth(int Row, int Col, TRichString val, int CellXF, ExcelFile Workbook, real RowMultDisplay, real ColMultDisplay, TMultipleCellAutofitList MultipleColAutofits)
        {
            if (val == null || val.Value == null || val.Value.Length == 0)
            {
                return(0);
            }

            TXFRecord XFRec = Wg.CellXF[CellXF];
            bool      Vertical;
            real      Alpha = FlexCelRender.CalcAngle(XFRec.Rotation, out Vertical);

            Font AFont = gr.FontCache.GetFont(XFFonts[CellXF], 1);             //dont dispose

            TXlsCellRange rg = Workbook.CellMergedBounds(Row, Col);

            SizeF            TextExtent;
            TXRichStringList TextLines  = new TXRichStringList();
            TFloatList       MaxDescent = new TFloatList();

            real Clp = 1 * FlexCelRender.DispMul / 100f;
            real Wr  = 0;

            if (Alpha != 90 && Alpha != -90)
            {
                Wr = 1e6f;                                          //this means "make the column as big as needed to fit". So SplitText needs no limits.
            }
            else
            {
                RectangleF CellRect = new RectangleF();
                for (int r = rg.Top; r <= rg.Bottom; r++)
                {
                    CellRect.Height += Workbook.GetRowHeight(r, true) / RowMultDisplay;
                }
                Wr = CellRect.Height - 2 * Clp;
            }


            RenderMetrics.SplitText(gr.Canvas, gr.FontCache, 1, val, AFont, Wr, TextLines, out TextExtent, Vertical, MaxDescent, null);

            if (TextLines.Count <= 0)
            {
                return(0);
            }

            real Rr = 0;
            real Ww = 0;

            for (int i = 0; i < TextLines.Count; i++)
            {
                Rr += TextLines[i].YExtent;
                if (TextLines[i].XExtent > Ww)
                {
                    Ww = TextLines[i].XExtent;
                }
            }
            if (Alpha != 0)
            {
                real SinAlpha = (real)Math.Sin(Alpha * Math.PI / 180); real CosAlpha = (real)Math.Cos(Alpha * Math.PI / 180);
                Ww = Ww * CosAlpha + Rr * Math.Abs(SinAlpha);
            }
            int Result = (int)Math.Ceiling(ColMultDisplay * (Ww + 4 * Clp));

            if (rg.ColCount > 1)
            {
                if (MultipleColAutofits != null)
                {
                    MultipleColAutofits.Add(new TMultipleCellAutofit(rg, Result));
                }
                return(0);                //We will autofit this later.
            }

            if (Result < 0)
            {
                Result = 0;
            }
            return(Result);
        }