示例#1
0
        static void RichTextFormatting(Stream stream, XlDocumentFormat documentFormat)
        {
            // Create an exporter instance.
            IXlExporter exporter = XlExport.CreateExporter(documentFormat);

            // Create a new document.
            using (IXlDocument document = exporter.CreateDocument(stream))
            {
                document.Options.Culture = CultureInfo.CurrentCulture;
                #region #RichTextFormatting
                // Create a new worksheet.
                using (IXlSheet sheet = document.CreateSheet())
                {
                    // Create the first column and set its width.
                    using (IXlColumn column = sheet.CreateColumn())
                    {
                        column.WidthInPixels = 180;
                    }
                    // Create the first row.
                    using (IXlRow row = sheet.CreateRow())
                    {
                        // Create the cell A1.
                        using (IXlCell cell = row.CreateCell())
                        {
                            // Create an XlRichTextString instance.
                            XlRichTextString richText = new XlRichTextString();
                            // Add three text runs to the collection.
                            richText.Runs.Add(new XlRichTextRun("Formatted ", XlFont.CustomFont("Arial", 14.0, XlColor.FromArgb(0x53, 0xbb, 0xf4))));
                            richText.Runs.Add(new XlRichTextRun("cell ", XlFont.CustomFont("Century Gothic", 14.0, XlColor.FromArgb(0xf1, 0x77, 0x00))));
                            richText.Runs.Add(new XlRichTextRun("text", XlFont.CustomFont("Consolas", 14.0, XlColor.FromArgb(0xe3, 0x2c, 0x2e))));
                            // Add the rich formatted text to the cell.
                            cell.SetRichText(richText);
                        }
                    }
                }
                #endregion #RichTextFormatting
            }
        }