コード例 #1
0
        void createHeader(GenerateExcelData d, string b, bool font, int size, string fcolor)
        {
            xlWorkSheet.Cells[1, 1] = d.excelHeader;
            int  unicode   = 65 + d.worksheetData.Columns.Count - 1;
            char character = (char)unicode;

            chartRange = xlWorkSheet.get_Range("A1", character.ToString() + "1");
            chartRange.Merge(d.worksheetData.Columns.Count - 1);
            switch (b)
            {
            case "YELLOW":
                chartRange.Interior.Color = System.Drawing.Color.Yellow.ToArgb();
                break;

            case "GRAY":
                chartRange.Interior.Color = System.Drawing.Color.Gray.ToArgb();
                break;

            case "GAINSBORO":
                chartRange.Interior.Color =
                    System.Drawing.Color.Gainsboro.ToArgb();
                break;

            case "Turquoise":
                chartRange.Interior.Color =
                    System.Drawing.Color.Turquoise.ToArgb();
                break;

            case "PeachPuff":
                chartRange.Interior.Color =
                    System.Drawing.Color.PeachPuff.ToArgb();
                break;

            default:
                //  workSheet_range.Interior.Color = System.Drawing.Color..ToArgb();
                break;
            }

            chartRange.Borders.Color = System.Drawing.Color.Black.ToArgb();
            chartRange.Font.Bold     = font;
            chartRange.ColumnWidth   = size;
            if (fcolor.Equals(""))
            {
                chartRange.Font.Color = System.Drawing.Color.White.ToArgb();
            }
            else
            {
                chartRange.Font.Color = System.Drawing.Color.Black.ToArgb();
            }
        }
コード例 #2
0
        void mapData(GenerateExcelData d)
        {
            int  j         = 2;
            int  k         = 1;
            int  colCount  = d.worksheetData.Columns.Count;
            int  unicode   = 65 + colCount - 1;
            char character = (char)unicode;


            if (String.IsNullOrEmpty(d.excelHeader))
            {
                j = 1;
            }
            foreach (DataColumn col in d.worksheetData.Columns)
            {
                object cell = col.ToString();
                xlWorkSheet.Cells[j, k++] = cell;
            }
            chartRange = xlWorkSheet.get_Range("A" + j.ToString(), character.ToString() + j.ToString());

            //var columnHeadingsRange = xlWorkSheet.Range[xlWorkSheet.Cells[j], xlWorkSheet.Cells[colCount]];
            chartRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightPink);
            chartRange.Font.Color     = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            chartRange.Font.Bold      = true;

            //j = startPoint;
            foreach (DataRow row in d.worksheetData.Rows)
            {
                ++j;
                for (int i = 0; i < colCount; i++)
                {
                    object cell = row[i];
                    xlWorkSheet.Cells[j, i + 1] = cell;
                }
            }
        }