Beispiel #1
0
 public void RightAlignNumbers()
 {
     for (int i = this.numOfHeaderRows; i < this.tableData.Count; i++)
     {
         List <AbstractCell> list = this.tableData[i];
         foreach (object current in list)
         {
             if (current is Cell)
             {
                 Cell cell = (Cell)current;
                 if (cell.GetText() != null)
                 {
                     string text   = cell.text;
                     int    length = text.Length;
                     bool   flag   = true;
                     int    j      = 0;
                     while (j < length)
                     {
                         char c = text[j++];
                         if (!char.IsNumber(c) && c != '(' && c != ')' && c != '-' && c != '.' && c != ',' && c != '\'')
                         {
                             flag = false;
                         }
                     }
                     if (flag)
                     {
                         cell.SetTextAlignment(2097152);
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
        /**
         *  Wraps around the text in all cells so it fits the column width.
         *  This method should be called after all calls to SetColumnWidth and AutoAdjustColumnWidths.
         *
         */
        public void WrapAroundCellText()
        {
            List <List <Cell> > tableData2 = new List <List <Cell> >();

            for (int i = 0; i < tableData.Count; i++)
            {
                List <Cell> row            = tableData[i];
                int         maxNumVerCells = 1;
                for (int j = 0; j < row.Count; j++)
                {
                    Cell cell    = row[j];
                    int  colspan = cell.GetColSpan();
                    for (int n = 1; n < colspan; n++)
                    {
                        Cell next = row[j + n];
                        cell.SetWidth(cell.GetWidth() + next.GetWidth());
                        next.SetWidth(0f);
                    }
                    int numVerCells = cell.GetNumVerCells();
                    if (numVerCells > maxNumVerCells)
                    {
                        maxNumVerCells = numVerCells;
                    }
                }

                for (int j = 0; j < maxNumVerCells; j++)
                {
                    List <Cell> row2 = new List <Cell>();
                    for (int k = 0; k < row.Count; k++)
                    {
                        Cell cell = row[k];

                        Cell cell2 = new Cell(cell.GetFont(), "");
                        cell2.SetFallbackFont(cell.GetFallbackFont());
                        cell2.SetPoint(cell.GetPoint());
                        cell2.SetWidth(cell.GetWidth());
                        if (j == 0)
                        {
                            cell2.SetTopPadding(cell.top_padding);
                        }
                        if (j == (maxNumVerCells - 1))
                        {
                            cell2.SetBottomPadding(cell.bottom_padding);
                        }
                        cell2.SetLeftPadding(cell.left_padding);
                        cell2.SetRightPadding(cell.right_padding);
                        cell2.SetLineWidth(cell.GetLineWidth());
                        cell2.SetBgColor(cell.GetBgColor());
                        cell2.SetPenColor(cell.GetPenColor());
                        cell2.SetBrushColor(cell.GetBrushColor());
                        cell2.SetProperties(cell.GetProperties());
                        cell2.SetVerTextAlignment(cell.GetVerTextAlignment());
                        cell2.SetIgnoreImageHeight(cell.GetIgnoreImageHeight());

                        if (j == 0)
                        {
                            cell2.SetImage(cell.GetImage());
                            if (cell.GetCompositeTextLine() != null)
                            {
                                cell2.SetCompositeTextLine(cell.GetCompositeTextLine());
                            }
                            else
                            {
                                cell2.SetText(cell.GetText());
                            }
                            if (maxNumVerCells > 1)
                            {
                                cell2.SetBorder(Border.BOTTOM, false);
                            }
                        }
                        else
                        {
                            cell2.SetBorder(Border.TOP, false);
                            if (j < (maxNumVerCells - 1))
                            {
                                cell2.SetBorder(Border.BOTTOM, false);
                            }
                        }
                        row2.Add(cell2);
                    }
                    tableData2.Add(row2);
                }
            }

            for (int i = 0; i < tableData2.Count; i++)
            {
                List <Cell> row = tableData2[i];
                for (int j = 0; j < row.Count; j++)
                {
                    Cell cell = row[j];
                    if (cell.text != null)
                    {
                        int      n         = 0;
                        String[] textLines = cell.GetText().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                        foreach (String textLine in textLines)
                        {
                            StringBuilder sb     = new StringBuilder();
                            String[]      tokens = Regex.Split(textLine, @"\s+");
                            if (tokens.Length == 1)
                            {
                                sb.Append(tokens[0]);
                            }
                            else
                            {
                                for (int k = 0; k < tokens.Length; k++)
                                {
                                    String token = tokens[k];
                                    if (cell.font.StringWidth(cell.fallbackFont, sb.ToString() + " " + token) >
                                        (cell.GetWidth() - (cell.left_padding + cell.right_padding)))
                                    {
                                        tableData2[i + n][j].SetText(sb.ToString());
                                        sb = new StringBuilder(token);
                                        n++;
                                    }
                                    else
                                    {
                                        if (k > 0)
                                        {
                                            sb.Append(" ");
                                        }
                                        sb.Append(token);
                                    }
                                }
                            }
                            tableData2[i + n][j].SetText(sb.ToString());
                            n++;
                        }
                    }
                    else
                    {
                        tableData2[i][j].SetCompositeTextLine(cell.GetCompositeTextLine());
                    }
                }
            }

            tableData = tableData2;
        }
Beispiel #3
0
        public void WrapAroundCellText()
        {
            List <List <Cell> > list = new List <List <Cell> >();

            for (int i = 0; i < this.tableData.Count; i++)
            {
                List <Cell> list2 = this.tableData[i];
                int         num   = 1;
                for (int j = 0; j < list2.Count; j++)
                {
                    Cell cell    = list2[j];
                    int  colSpan = cell.GetColSpan();
                    for (int k = 1; k < colSpan; k++)
                    {
                        Cell cell2 = list2[j + k];
                        cell.SetWidth((double)(cell.GetWidth() + cell2.GetWidth()));
                        cell2.SetWidth(0.0);
                    }
                    int numVerCells = cell.GetNumVerCells(this.padding);
                    if (numVerCells > num)
                    {
                        num = numVerCells;
                    }
                }
                for (int l = 0; l < num; l++)
                {
                    List <Cell> list3 = new List <Cell>();
                    for (int m = 0; m < list2.Count; m++)
                    {
                        Cell cell3 = list2[m];
                        Cell cell4 = new Cell(cell3.GetFont(), "");
                        cell4.SetPoint(cell3.GetPoint());
                        cell4.SetCompositeTextLine(cell3.GetCompositeTextLine());
                        cell4.SetWidth((double)cell3.GetWidth());
                        if (l == 0)
                        {
                            cell4.SetTopPadding(cell3.top_padding);
                        }
                        if (l == num - 1)
                        {
                            cell4.SetBottomPadding(cell3.bottom_padding);
                        }
                        cell4.SetLeftPadding(cell3.left_padding);
                        cell4.SetRightPadding(cell3.right_padding);
                        cell4.SetLineWidth(cell3.GetLineWidth());
                        cell4.SetBgColor(cell3.GetBgColor());
                        cell4.SetPenColor(cell3.GetPenColor());
                        cell4.SetBrushColor(cell3.GetBrushColor());
                        cell4.SetProperties(cell3.GetProperties());
                        if (l == 0)
                        {
                            cell4.SetText(cell3.GetText());
                        }
                        else
                        {
                            if (l > 0)
                            {
                                cell4.SetBorder(65536, false);
                                if (l < num - 1)
                                {
                                    cell4.SetBorder(131072, false);
                                }
                            }
                        }
                        list3.Add(cell4);
                    }
                    list.Add(list3);
                }
            }
            for (int n = 0; n < list.Count; n++)
            {
                List <Cell> list4 = list[n];
                for (int num2 = 0; num2 < list4.Count; num2++)
                {
                    Cell cell5 = list4[num2];
                    if (cell5.text != null)
                    {
                        int           num3          = 0;
                        string[]      array         = Regex.Split(cell5.GetText(), "\\s+");
                        StringBuilder stringBuilder = new StringBuilder();
                        if (array.Length == 1)
                        {
                            stringBuilder.Append(array[0]);
                        }
                        else
                        {
                            for (int num4 = 0; num4 < array.Length; num4++)
                            {
                                string text = array[num4];
                                if (cell5.font.StringWidth(stringBuilder.ToString() + " " + text) > cell5.GetWidth() - (cell5.left_padding + cell5.right_padding + 2f * this.padding))
                                {
                                    list[n + num3][num2].SetText(stringBuilder.ToString());
                                    stringBuilder = new StringBuilder(text);
                                    num3++;
                                }
                                else
                                {
                                    if (num4 > 0)
                                    {
                                        stringBuilder.Append(" ");
                                    }
                                    stringBuilder.Append(text);
                                }
                            }
                        }
                        list[n + num3][num2].SetText(stringBuilder.ToString());
                    }
                }
            }
            this.tableData = list;
        }