示例#1
0
        public void TestWrite()
        {
            string file = Path.GetTempFileName() + ".xls";

            using (ExcelDocument doc = ExcelDocument.CreateDocument())
            {
                ExcelWorksheet worksheet = doc.CreateWorksheet("Test");

                ExcelCell cell = worksheet.GetCellAt(new ExcelCellName(new ColumnLetter(Letter.A), 1));
                cell.Text = "Hello World";

                ExcelFormatter formatter = worksheet.GetFormatterAt(
                    new ExcelCellName(new ColumnLetter(Letter.A), 1),
                    new ExcelCellName(new ColumnLetter(Letter.C), 3));
                formatter.Background  = Color.Red;
                formatter.Foreground  = Color.Yellow;
                formatter.BorderColor = Color.Blue;
                formatter.Font        = new Font("Courier New", 12, FontStyle.Underline | FontStyle.Bold);
                formatter.Merge();
                formatter.ColumnWidth = 100;
                formatter.RowHeight   = 100;

                Assert.AreEqual(Color.FromArgb(0, 255, 0, 0), formatter.Background);
                Assert.AreEqual(Color.FromArgb(0, 255, 255, 0), formatter.Foreground);
                //Assert.AreEqual(Color.FromArgb(0, 0, 0, 255), formatter.BorderColor); TODO

                doc.Save(file);
            }
        }