Knowledgebase (2328)
Children categories
How to Open and View Excel in Windows Form using Spire.Speadsheet
2016-04-19 03:20:45 Written by KoohjiSpire.Spreadsheet is a .NET Excel viewer control that allows programmers to load Excel spreadsheet in Windows form, manipulate the data in it and save to file. This guide will introduce how to add Spire.Spreadsheet controls to Toolbox and how to create a Windows Form Application to display Excel spreadsheet.
Add Spire.Spreadsheet Controls to Toolbox
Right-click on the white space of the Toolbox – "Add Tab" - name the new Tab "Spire.Spreadsheet Controls":

Right-click on the blank part below "Spire.Spreadsheet Controls" - "Choose Items" - ".NET Framework Components" - "Browse" to the "Bin" folder - find the file "Spire.Spreadsheet.dll" - "Open".

Click "OK". Then you have added controls to Toolbox successfully.

Create a Windows Form Application to Display Spreadsheet
Create a Windows Form Application, drag Spreadsheet control to form1 and add an openToolStrip in menuStrip to open an Excel file.

Double click openToolStrip to write code. The spreadsheet1 that represents Spreadsheet control can easily load an Excel file by LoadFromFile() method.
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofDialog = new OpenFileDialog();
ofDialog.Filter = "All files|*.*|Microsoft Excel Files(*.xls;*.xlsx;*.ods;*.xlsb)|*.xls;*.xlsx;*.xlsb;*.ods";
if (ofDialog.ShowDialog() == DialogResult.OK)
spreadsheet1.LoadFromFile(ofDialog.FileName);
}
Run the program and open an existing Excel file, you’ll get following output:

It seems very easy to rotate the PDF page. However, we often find that the rotation is applied to the whole PDF document when we try to rotate a particular page. Is there an easy and fast way to rotate a certain PDF page within the DPF document?
In the following sections, I will demonstrate how to rotate a certain PDF page within PDF document in WPF with several lines of codes.
The code snippets are as followed:
Step 1: Initialize a new instance of PdfDocument class and load the PDF document from the file.
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("LeavesOfGrass.pdf");
Step 2: For rotation, Spire.PDF enables you to define 0, 90, 180 and 270 degrees. In this example, my PDF file has five pages. I want to rotate the fifth page by 270 degrees and make other pages remain the same.
PdfPageBase page = doc.Pages[4]; page.Rotation = PdfPageRotateAngle.RotateAngle270;
Step 3: Save the PDF document and launch the file.
doc.SaveToFile("RotatedLeavesOfGrass.pdf");
System.Diagnostics.Process.Start("RotatedLeavesOfGrass.pdf");
Effective screenshot:


Full Codes:
using System.Windows;
using Spire.Pdf;
namespace Rotate_PDF_page
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("LeavesOfGrass.pdf");
PdfPageBase page = doc.Pages[4];
page.Rotation = PdfPageRotateAngle.RotateAngle270;
doc.SaveToFile("RotatedLeavesOfGrass.pdf");
System.Diagnostics.Process.Start("RotatedLeavesOfGrass.pdf");
}
}
}
Imports System.Windows
Imports Spire.Pdf
Namespace Rotate_PDF_page
'''
''' Interaction logic for MainWindow.xaml
'''
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
Dim doc As New PdfDocument()
doc.LoadFromFile("LeavesOfGrass.pdf")
Dim page As PdfPageBase = doc.Pages(4)
page.Rotation = PdfPageRotateAngle.RotateAngle270
doc.SaveToFile("RotatedLeavesOfGrass.pdf")
System.Diagnostics.Process.Start("RotatedLeavesOfGrass.pdf")
End Sub
End Class
End Namespace
With the help of Spire.XLS, developers can easily set the font for the text for Excel chart. We have already demonstrate how to set the font for TextBox in Excel Chart, this article will focus on demonstrating how to set the font for legend and datalable in Excel chart by using the SetFont() method to change the font for the legend and datalable easily in C#.
Firstly, please view the Excel worksheet with chart which the font will be changed later:

Note: Before Start, please download the latest version of Spire.XLS and add Spire.Xls.dll in the bin folder as the reference of Visual Studio.
Step 1: Create a new Excel workbook and load from file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Step 2: Get the first worksheet from workbook.
Worksheet ws = workbook.Worksheets[0]; Spire.Xls.Chart chart = ws.Charts[0];
Step 3: Create a font with specified size and color.
ExcelFont font = workbook.CreateFont(); font.Size =12.0; font.Color = Color.Red;
Step 4: Apply the font to chart Legend.
chart.Legend.TextArea.SetFont(font);
Step 5: Apply the font to chart DataLabel.
foreach (ChartSerie cs in chart.Series)
{
cs.DataPoints.DefaultDataPoint.DataLabels.TextArea.SetFont(font);
}
Step 6: Save the document to file.
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010);
Effective screenshot after changing the text font.

Full codes:
using Spire.Xls;
using Spire.Xls.Charts;
using System.Drawing;
namespace SetFont
{
class Program
{
static void Main(string[] args)
{
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet ws = workbook.Worksheets[0];
Spire.Xls.Chart chart = ws.Charts[0];
ExcelFont font = workbook.CreateFont();
font.Size = 12.0;
font.Color = Color.Red;
chart.Legend.TextArea.SetFont(font);
foreach (ChartSerie cs in chart.Series)
{
cs.DataPoints.DefaultDataPoint.DataLabels.TextArea.SetFont(font);
}
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010);
}
}
}
}