zhao
2021-07-09 0821715ebc11d3934d0594a1cc2c39686d808906
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//============================================================================
//Gios Pdf.NET - A library for exporting Pdf Documents in C#
//Copyright (C) 2005  Paolo Gios - www.paologios.com
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public
//License along with this library; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//=============================================================================
using System;
using System.Drawing;
using System.Collections;
 
namespace HH.WMS.Utils.Gios.Pdf
{
    /// <summary>
    /// This class represent a range of Cell. Each method called will be applied to each Cell.
    /// </summary>
    public class PdfCellRange
    {
        internal int startRow,endRow,startColumn,endColumn;
        internal PdfTable owner;
        internal PdfCellRange(){}
        internal PdfCellRange(PdfTable owner,int startRow,int startColumn,int endRow,int endColumn)
        {
            object o=owner.Cell(startRow,startColumn);
            o=owner.Cell(endRow,endColumn);
            this.owner=owner;
            this.startColumn=startColumn;
            this.startRow=startRow;
            this.endColumn=endColumn;
            this.endRow=endRow;
        }
        internal PdfArea Area
        {
            get
            {
                return this.owner.Cell(startRow,startColumn).Area
                    .Merge(this.owner.Cell(endRow,endColumn).Area);
            }
        }
        /// <summary>
        /// The entire collection of Cells.
        /// </summary>
        public ArrayList Cells
        {
            get
            {
                ArrayList al=new ArrayList();
                for (int r=startRow;r<=endRow;r++)
                    for (int c=startColumn;c<=endColumn;c++)
                        al.Add(this.owner.cells[r+","+c] as PdfCell);
                return al;
            }
        }
        /// <summary>
        /// Sets this Content Format to each Cell of the CellRange.
        /// </summary>
        /// <param name="Format"></param>
        public void SetContentFormat(string Format)
        {
            foreach (PdfCell pc in this.Cells) pc.SetContentFormat(Format);
        }
        /// <summary>
        /// sets this Content to each Cell of the CellRange.
        /// </summary>
        public void SetContent(object Content)
        {
            foreach (PdfCell pc in this.Cells) pc.SetContent(Content);
        }
        /// <summary>
        /// sets this Color as background to each Cell of the CellRange
        /// </summary>
        /// <param name="BackgroundColor"></param>
        public void SetBackgroundColor(Color BackgroundColor)
        {
            foreach (PdfCell rc in this.Cells)    rc.SetBackgroundColor(BackgroundColor);
        }
        /// <summary>
        /// sets those two colors as alternating backgrounds to each Row of the CellRange
        /// </summary>
        /// <param name="BackgroundColor"></param>
        /// <param name="AlternateBackgroundColor"></param>
        public void SetBackgroundColor(Color BackgroundColor,Color AlternateBackgroundColor)
        {
            this.SetBackgroundColor(AlternateBackgroundColor);
            for (int r=this.startRow;r<=this.endRow;r+=2)
                for (int c=this.startColumn;c<=this.endColumn;c++)
                    this.owner.Cell(r,c).SetBackgroundColor(BackgroundColor);
        }
        /// <summary>
        /// sets this Color as Foreground Color to each Cell of the CellRange.
        /// </summary>
        /// <param name="Color"></param>
        public void SetForegroundColor(Color Color)
        {
            foreach (PdfCell rc in this.Cells)    rc.SetForegroundColor(Color);
        }
        /// <summary>
        /// sets Foreground and Background Colors of each Cell of the CellRange.
        /// </summary>
        /// <param name="ForegroundColor"></param>
        /// <param name="BackgroundColor"></param>
        /// <param name="AlternateBackgroundColor"></param>
        public void SetColors(Color ForegroundColor,Color BackgroundColor,Color AlternateBackgroundColor)
        {
            foreach (PdfCell rc in this.Cells)    rc.SetForegroundColor(ForegroundColor);
            this.SetBackgroundColor(AlternateBackgroundColor);
            for (int r=this.startRow;r<=this.endRow;r+=2)
                for (int c=this.startColumn;c<=this.endColumn;c++)
                    this.owner.Cell(r,c).SetBackgroundColor(BackgroundColor);
        }
        /// <summary>
        /// sets this Foreground and Background Colors to each Cell of the CellRange.
        /// </summary>
        /// <param name="ForegroundColor"></param>
        /// <param name="BackgroundColor"></param>
        public void SetColors(Color ForegroundColor,Color BackgroundColor)
        {
            foreach (PdfCell rc in this.Cells)    rc.SetForegroundColor(ForegroundColor);
            foreach (PdfCell rc in this.Cells)    rc.SetBackgroundColor(BackgroundColor);
        }
        /// <summary>
        /// sets this content alignment to each Cell of the CellRange.
        /// </summary>
        /// <param name="ContentAlignment"></param>
        public void SetContentAlignment(ContentAlignment ContentAlignment)
        {
            foreach (PdfCell rc in this.Cells)    rc.ContentAlignment=ContentAlignment;
        }
        /// <summary>
        /// sets this font to each Cell of the CellRange.
        /// </summary>
        /// <param name="Font"></param>
        public void SetFont(Font Font)
        {
                foreach (PdfCell rc in this.Cells) rc.Font=Font;
        }
        /// <summary>
        /// sets transparent each Cell of the CellRange.
        /// </summary>
        public void SetTransparent()
        {
            foreach (PdfCell rc in this.Cells) rc.transparent=true;
        }
        /// <summary>
        /// sets this CellPadding to each Cell of the CellRange.
        /// </summary>
        /// <param name="CellPadding"></param>
        public void SetCellPadding(double CellPadding)
        {
            foreach (PdfCell pc in this.Cells) pc.SetCellPadding(CellPadding);
        }
        /// <summary>
        /// The CellRange will be collapsed into a single Cell (with the lowest row and column index)
        /// This method will automatically sets the colspan and rowspan of the first Cell of the Range.
        /// </summary>
        public void MergeCells()
        {
            try
            {
                PdfCell pc=this.owner.Rows[startRow][startColumn];
                pc.RowSpan=endRow-startRow+1;
                pc.ColSpan=endColumn-startColumn+1;
            }
            catch {throw new Exception("Impossible to merge the CellAreas");}
        }
    }
}