Knowledgebase (2311)
Children categories
Spire.XLS has powerful functions to export Excel worksheets into different image file formats. In the previous articles, we have already shown you how to convert Excel worksheets into BMP, PNG, GIF, JPG, JPEG, TIFF. Now Spire.XLS newly starts to support exporting Excel worksheet into EMF image. With the help of Spire.XLS, you only need three lines of codes to finish the conversion function.
Make sure Spire.XLS (Version 7.6.43 or above) has been installed correctly and then add Spire.xls.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Xls\Bin\NET4.0\ Spire. Xls.dll". Here comes to the details of how to convert excel worksheet to EMF image.
Step 1: Create an excel document and load the document from file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("XLS2.xlsx");
Step 2: Get the first worksheet in excel workbook.
Worksheet sheet = workbook.Worksheets[0];
Step 3: Save excel worksheet into EMF image.
sheet.SaveToEMFImage("result.emf", 1, 1, 19, 6, system.Drawing.Imaging.EmfType.EmfPlusDual);
Effective screenshot:

Full codes:
using Spire.Xls;
namespace XLStoEMF
{
class Program
{
static void Main(string[] args)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("XLS2.xlsx");
Worksheet sheet = workbook.Worksheets[0];
sheet.SaveToEMFImage("result.emf", 1, 1, 19,6, System.Drawing.Imaging.EmfType.EmfPlusDual);
}
}
}
Set the offset of image when the fill way of chart is picture fill
2015-04-17 07:39:10 Written by KoohjiSet offset of the filled image could make your chart background pictures zoom and show proportional as you wish. This article shows how to set the offset of image via Spire.XLS.
Here are the steps:
Step 1: Create an instance of Spire.XLS.Workbook.
Workbook book = new Workbook();
Step 2: Load data and create a contrast sheet.
workbook.LoadFromFile("test.xlsx",ExcelVersion.Version2013);
Worksheet sheet = workbook.Worksheets[0];
Worksheet sheet1 = workbook.Worksheets.Add("Contrast");
Step 3: Add chart1 and background image to sheet1 as comparision.
Chart chart1 = sheet1.Charts.Add(ExcelChartType.ColumnClustered);
chart1.DataRange = sheet.Range["D1:E9"];
chart1.SeriesDataFromRange = false;
chart1.LeftColumn = 1;
chart1.TopRow = 11;
chart1.RightColumn = 8;
chart1.BottomRow = 33;
chart1.ChartArea.Fill.CustomPicture(Image.FromFile("2.jpg"), "None");
Step 4: Add same chart and background image then set offset of image by transforming image in sheet[0] as form of XlsShapeFill. Then set the property of PicStretch of each direction with percentage and Tile property.
Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered);
chart.DataRange = sheet.Range["D1:E9"];
chart.SeriesDataFromRange = false;
chart.LeftColumn = 1;
chart.TopRow = 11;
chart.RightColumn = 8;
chart.BottomRow = 33;
chart.ChartArea.Fill.CustomPicture(Image.FromFile("2.jpg"), "None");
IChart ichart = sheet.Charts[0];
(ichart.ChartArea.Fill as XlsShapeFill).Tile = false;
(ichart.ChartArea.Fill as XlsShapeFill).PicStretch.Left = 10;
(ichart.ChartArea.Fill as XlsShapeFill).PicStretch.Top = 20;
(ichart.ChartArea.Fill as XlsShapeFill).PicStretch.Right = 10;
(ichart.ChartArea.Fill as XlsShapeFill).PicStretch.Bottom = 5;
Step 5: Save and review.
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2013);
System.Diagnostics.Process.Start("result.xlsx");
Screenshot:


Full code:
using Spire.Xls;
using Spire.Xls.Core;
using Spire.Xls.Core.Spreadsheet.Shapes;
using System.Drawing;
namespace SetOffsetofImage
{
class Program
{
static void Main(string[] args)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("test.xlsx", ExcelVersion.Version2013);
Worksheet sheet = workbook.Worksheets[0];
Worksheet sheet1 = workbook.Worksheets.Add("Contrast");
//add contrast
Chart chart1 = sheet1.Charts.Add(ExcelChartType.ColumnClustered);
chart1.DataRange = sheet.Range["D1:E9"];
chart1.SeriesDataFromRange = false;
//Chart Position
chart1.LeftColumn = 1;
chart1.TopRow = 11;
chart1.RightColumn = 8;
chart1.BottomRow = 33;
chart1.ChartArea.Fill.CustomPicture(Image.FromFile("2.jpg"), "None");
//add original
Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered);
chart.DataRange = sheet.Range["D1:E9"];
chart.SeriesDataFromRange = false;
//Chart Position
chart.LeftColumn = 1;
chart.TopRow = 11;
chart.RightColumn = 8;
chart.BottomRow = 33;
chart.ChartArea.Fill.CustomPicture(Image.FromFile("2.jpg"), "None");
IChart ichart = sheet.Charts[0];
(ichart.ChartArea.Fill as XlsShapeFill).Tile = false;
(ichart.ChartArea.Fill as XlsShapeFill).PicStretch.Left = 10;
(ichart.ChartArea.Fill as XlsShapeFill).PicStretch.Top = 20;
(ichart.ChartArea.Fill as XlsShapeFill).PicStretch.Right = 10;
(ichart.ChartArea.Fill as XlsShapeFill).PicStretch.Bottom = 5;
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2013);
System.Diagnostics.Process.Start("result.xlsx");
}
}
}
Automatically Display Bookmarks or Thumbnails When PDF is Opened in C#/VB.NET
2015-04-16 02:14:27 Written by KoohjiWhen a user opens a PDF document they see the initial view of the PDF. By default, the Bookmarks Panel or Thumbnails Panel is not shown when the PDF is opened. In this article, we're going to demonstrate how to set document properties so that the Bookmarks Panel or Thumbnails Panel will be open every time the file is launched.
Check the test file below, only the page content is showing when the document is opened.

Code Snippet and Effect:
Step 1: Create a new PDF document and load the test file.
PdfDocument Pdf = new PdfDocument();
Pdf.LoadFromFile("Test.pdf");
Step 2: In the class of ViewerPreferences, there is a PageMode property that specifies how the document should be displayed when opened. Set PageMode as UseOutlines, save the changes to a new PDF file named "ShowBookmarks".
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseOutlines;
Pdf.SaveToFile("ShowBookmarks.pdf");
Open the newly-generated file, Bookmarks Panel will be automatically displayed as below:

Step 3: If we set PageMode as UseThumbs, and save the changes to another PDF file named "ShowThumbnails", then we will get following effect if we open this file.
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseThumbs;
Pdf.SaveToFile("ShowThumbnails.pdf");

Full Code:
using Spire.Pdf;
namespace Bookmarks
{
class Program
{
static void Main(string[] args)
{
PdfDocument Pdf = new PdfDocument();
Pdf.LoadFromFile("Test.pdf");
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseOutlines;
Pdf.SaveToFile("ShowBookmarks.pdf");
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseThumbs;
Pdf.SaveToFile("ShowThumbnails.pdf");
}
}
}
Imports Spire.Pdf
Namespace Bookmarks
Class Program
Private Shared Sub Main(args As String())
Dim Pdf As New PdfDocument()
Pdf.LoadFromFile("Test.pdf")
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseOutlines
Pdf.SaveToFile("ShowBookmarks.pdf")
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseThumbs
Pdf.SaveToFile("ShowThumbnails.pdf")
End Sub
End Class
End Namespace