static void PictureHyperlinkClick(Stream stream, XlDocumentFormat documentFormat) { #region #HyperlinkClick // Create an exporter instance. IXlExporter exporter = XlExport.CreateExporter(documentFormat); // Create a new document. using (IXlDocument document = exporter.CreateDocument(stream)) { document.Options.Culture = CultureInfo.CurrentCulture; // Create a worksheet. using (IXlSheet sheet = document.CreateSheet()) { // Load a picture from a file and add a hyperlink to it. using (IXlPicture picture = sheet.CreatePicture()) { picture.Image = Image.FromFile(Path.Combine(imagesPath, "DevExpress.png")); picture.HyperlinkClick.TargetUri = "http://www.devexpress.com"; picture.HyperlinkClick.Tooltip = "Developer Express Inc."; picture.SetTwoCellAnchor(new XlAnchorPoint(1, 1, 0, 0), new XlAnchorPoint(10, 5, 2, 15), XlAnchorType.TwoCell); } } } #endregion #HyperlinkClick }
void GenerateTitle(IXlSheet sheet) { // Specify formatting settings for the document title. XlCellFormatting formatting = new XlCellFormatting(); formatting.Font = new XlFont(); formatting.Font.Name = "Calibri Light"; formatting.Font.SchemeStyle = XlFontSchemeStyles.None; formatting.Font.Size = 24; formatting.Font.Color = XlColor.FromTheme(XlThemeColor.Dark1, 0.5); formatting.Border = new XlBorder(); formatting.Border.BottomColor = XlColor.FromTheme(XlThemeColor.Dark1, 0.5); formatting.Border.BottomLineStyle = XlBorderLineStyle.Medium; // Add the document title. using (IXlRow row = sheet.CreateRow()) { // Skip the cell "A1". row.SkipCells(1); // Create the cell "B1" containing the document title. using (IXlCell cell = row.CreateCell()) { cell.Value = "SALES ANALYSIS 2014"; cell.Formatting = formatting; } // Create five empty cells with the title formatting. row.BlankCells(5, formatting); } // Skip one row before starting to generate data rows. sheet.SkipRows(1); // Insert a picture from a file and anchor it to the cell "G1". string startupPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); using (IXlPicture picture = sheet.CreatePicture()) { picture.Image = Image.FromFile(Path.Combine(startupPath, "Logo.png")); picture.SetOneCellAnchor(new XlAnchorPoint(6, 0, 8, 4), 105, 30); } }
static void FitPicture(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; // Create a worksheet. using (IXlSheet sheet = document.CreateSheet()) { sheet.SkipColumns(1); // Create the column "B" and set its width. using (IXlColumn column = sheet.CreateColumn()) { column.WidthInPixels = 300; } sheet.SkipRows(1); // Create the second row and set its height. using (IXlRow row = sheet.CreateRow()) { row.HeightInPixels = 154; } #region #FitPicture // Insert a picture from a file to fit in the cell B2. using (IXlPicture picture = sheet.CreatePicture()) { picture.Image = Image.FromFile(Path.Combine(imagesPath, "image1.jpg")); picture.FitToCell(new XlCellPosition(1, 1), 300, 154, true); } } #endregion #FitPicture } }
static void InsertPicture(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 #InsertPicture // Create a worksheet. using (IXlSheet sheet = document.CreateSheet()) { // Insert a picture from a file and anchor it to cells. using (IXlPicture picture = sheet.CreatePicture()) { picture.Image = Image.FromFile(Path.Combine(imagesPath, "image1.jpg")); picture.SetTwoCellAnchor(new XlAnchorPoint(1, 1, 0, 0), new XlAnchorPoint(6, 11, 2, 15), XlAnchorType.TwoCell); } } #endregion #InsertPicture } }