[C#]
//Creating a file stream containing the Excel file to be opened
//Instantiating a Workbook object
Workbook workbook = new Workbook("template.xlsx");
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
//Creating AutoFilter by giving the cells range of the heading row
worksheet.AutoFilter.Range = "A1:B1";
//Filtering columns with specified values
worksheet.AutoFilter.Filter(1, "Bananas");
//Saving the modified Excel file.
workbook.Save("output.xls");
[Visual Basic]
'Creating a file stream containing the Excel file to be opened
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook("template.xlsx")
'Accessing the first worksheet in the Excel file
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Creating AutoFilter by giving the cells range of the heading row
worksheet.AutoFilter.Range = "A1:B1"
'Filtering columns with specified values
Worksheet.AutoFilter.Filter(1, "Bananas")
'Saving the modified Excel file
workbook.Save("output.xls")
[C#]
Workbook excel = new Workbook();
Cells cells = excel.Worksheets[0].Cells;
//Put a string into a cell
Cell cell = cells[0, 0];
cell.PutValue("Hello");
string first = cell.StringValue;
//Put an integer into a cell
cell = cells["B1"];
cell.PutValue(12);
int second = cell.IntValue;
//Put a double into a cell
cell = cells[0, 2];
cell.PutValue(-1.234);
double third = cell.DoubleValue;
//Put a formula into a cell
cell = cells["D1"];
cell.Formula = "=B1 + C1";
//Put a combined formula: "sum(average(b1,c1), b1)" to cell at b2
cell = cells["b2"];
cell.Formula = "=sum(average(b1,c1), b1)";
//Set style of a cell
Style style = cell.GetStyle();
//Set background color
style.BackgroundColor = Color.Yellow;
//Set format of a cell
style.Font.Name = "Courier New";
style.VerticalAlignment = TextAlignmentType.Top;
cell.SetStyle(style);
[Visual Basic]
Dim excel as Workbook = new Workbook()
Dim cells as Cells = exce.Worksheets(0).Cells
'Put a string into a cell
Dim cell as Cell = cells(0, 0)
cell.PutValue("Hello")
Dim first as String = cell.StringValue
//Put an integer into a cell
cell = cells("B1")
cell.PutValue(12)
Dim second as Integer = cell.IntValue
//Put a double into a cell
cell = cells(0, 2)
cell.PutValue(-1.234)
Dim third as Double = cell.DoubleValue
//Put a formula into a cell
cell = cells("D1")
cell.Formula = "=B1 + C1"
//Put a combined formula: "sum(average(b1,c1), b1)" to cell at b2
cell = cells("b2")
cell.Formula = "=sum(average(b1,c1), b1)"
//Set style of a cell
Dim style as Style = cell.GetStyle()
//Set background color
style.BackgroundColor = Color.Yellow
//Set font of a cell
style.Font.Name = "Courier New"
style.VerticalAlignment = TextAlignmentType.Top
cell.SetStyle(style)
[C#]
Workbook excel = new Workbook();
Cells cells = excel.Worksheets[0].Cells;
//Put date time into a cell
Cell cell = cells[0, 0];
cell.PutValue(new DateTime(2023, 5, 15));
Style style = cell.GetStyle(false);
style.Number = 14;
cell.SetStyle(style);
[C#]
Workbook excel = new Workbook();
Cells cells = excel.Worksheets[0].Cells;
cells["B6"].Formula = "=SUM(B2:B5, E1) + sheet1!A1";
[Visual Basic]
Dim excel As Workbook = New Workbook()
Dim cells As Cells = excel.Worksheets(0).Cells
cells("B6").Formula = "=SUM(B2:B5, E1) + sheet1!A1"
[C#]
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
cells["A1"].Formula = "=B1+SUM(B1:B10)+[Book1.xls]Sheet1!A1";
ReferredAreaCollection areas = cells["A1"].GetPrecedents();
for (int i = 0; i < areas.Count; i++)
{
ReferredArea area = areas[i];
StringBuilder stringBuilder = new StringBuilder();
if (area.IsExternalLink)
{
stringBuilder.Append("[");
stringBuilder.Append(area.ExternalFileName);
stringBuilder.Append("]");
}
stringBuilder.Append(area.SheetName);
stringBuilder.Append("!");
stringBuilder.Append(CellsHelper.CellIndexToName(area.StartRow, area.StartColumn));
if (area.IsArea)
{
stringBuilder.Append(":");
stringBuilder.Append(CellsHelper.CellIndexToName(area.EndRow, area.EndColumn));
}
Console.WriteLine(stringBuilder.ToString());
}
[Visual Basic]
Dim workbook As Workbook = New Workbook()
Dim cells As Cells = workbook.Worksheets(0).Cells
cells("A1").Formula = "= B1 + SUM(B1:B10) + [Book1.xls]Sheet1!A1"
Dim areas As ReferredAreaCollection = cells("A1").GetPrecedents()
For i As Integer = 0 To areas.Count - 1
Dim area As ReferredArea = areas(i)
Dim stringBuilder As StringBuilder = New StringBuilder()
If (area.IsExternalLink) Then
stringBuilder.Append("[")
stringBuilder.Append(area.ExternalFileName)
stringBuilder.Append("]")
End If
stringBuilder.Append(area.SheetName)
stringBuilder.Append("!")
stringBuilder.Append(CellsHelper.CellIndexToName(area.StartRow, area.StartColumn))
If (area.IsArea) Then
stringBuilder.Append(":")
stringBuilder.Append(CellsHelper.CellIndexToName(area.EndRow, area.EndColumn))
End If
Console.WriteLine(stringBuilder.ToString())
Next
[C#]
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
cells["A1"].Formula = "=B1+SUM(B1:B10)+[Book1.xls]Sheet1!B2";
cells["A2"].Formula = "=IF(TRUE,B2,B1)";
Cell[] dependents = cells["B1"].GetDependents(true);
for (int i = 0; i < dependents.Length; i++)
{
Console.WriteLine(dependents[i].Name);
}
[C#]
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
cells["A2"].Formula = "=IF(TRUE,B2,B1)";
workbook.Settings.FormulaSettings.EnableCalculationChain = true;
workbook.CalculateFormula();
IEnumerator en = cells["A2"].GetPrecedentsInCalculation();
Console.WriteLine("A2's calculation precedents:");
while(en.MoveNext())
{
ReferredArea r = (ReferredArea)en.Current;
Console.WriteLine(r);
}
[C#]
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
cells["A1"].Formula = "=B1+SUM(B1:B10)+[Book1.xls]Sheet1!B2";
cells["A2"].Formula = "=IF(TRUE,B2,B1)";
workbook.Settings.FormulaSettings.EnableCalculationChain = true;
workbook.CalculateFormula();
IEnumerator en = cells["B1"].GetDependentsInCalculation(false);
Console.WriteLine("B1's calculation dependents:");
while(en.MoveNext())
{
Cell c = (Cell)en.Current;
Console.WriteLine(c.Name);
}
en = cells["B2"].GetDependentsInCalculation(false);
Console.WriteLine("B2's calculation dependents:");
while(en.MoveNext())
{
Cell c = (Cell)en.Current;
Console.WriteLine(c.Name);
}
null,
Boolean,
DateTime,
Double,
Integer
String.
For int value, it may be returned as an Integer object or a Double object. And there is no guarantee that the returned value will be kept as the same type of object always.
[C#]
Workbook excel = new Workbook();
Cells cells = excel.Worksheets[0].Cells;
cells["A1"].PutValue("Helloworld");
cells["A1"].Characters(5, 5).Font.IsBold = true;
cells["A1"].Characters(5, 5).Font.Color = Color.Blue;
[Visual Basic]
Dim excel as Workbook = new Workbook()
Dim cells as Cells = exce.Worksheets(0).Cells
cells("A1").PutValue("Helloworld")
cells("A1").Characters(5, 5).Font.IsBold = True
cells("A1").Characters(5, 5).Font.Color = Color.Blue
[C#]
//Create Cell Area
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 0;
ca.StartColumn = 0;
ca.EndColumn = 0;
[VB.NET]
'Create Cell Area
Dim ca As CellArea = New CellArea()
ca.StartRow = 0
ca.EndRow = 0
ca.StartColumn = 0
ca.EndColumn = 0
[C#]
Workbook excel = new Workbook();
Cells cells = excel.Worksheets[0].Cells;
//Set default row height
cells.StandardHeight = 20;
//Set row height
cells.SetRowHeight(2, 20.5);
//Set default colum width
cells.StandardWidth = 15;
//Set column width
cells.SetColumnWidth(3, 12.57);
//Merge cells
cells.Merge(5, 4, 2, 2);
//Put values to cells
cells[0, 0].PutValue(true);
cells[0, 1].PutValue(1);
cells[0, 2].PutValue("abc");
//Export data
object[,] arr = cells.ExportArray(0, 0, 10, 10);
[Visual Basic]
Dim excel as Workbook = new Workbook()
Dim cells as Cells = excel.Worksheets(0).Cells
'Set default row height
cells.StandardHeight = 20
'Set row height
cells.SetRowHeight(2, 20.5)
'Set default colum width
cells.StandardWidth = 15
'Set column width
cells.SetColumnWidth(3, 12.57)
'Merge cells
cells.Merge(5, 4, 2, 2)
'Export data
Dim outDataTable as DataTable = cells.ExportDataTable(12, 12, 10, 10)
[C#]
Workbook workbook = new Workbook("template.xlsx");
Cells cells = workbook.Worksheets[0].Cells;
IEnumerator en = cells.GetEnumerator();
while (en.MoveNext())
{
Cell cell = (Cell)en.Current;
Console.WriteLine(cell.Name + ": " + cell.Value);
}
[C#]
Workbook excel = new Workbook();
Cells cells = excel.Worksheets[0].Cells;
Cell cell = cells[0, 0]; //Gets the cell at "A1"
[Visual Basic]
Dim excel as Workbook = New Workbook()
Dim cells As Cells = excel.Worksheets(0).Cells
Dim cell As Cell = cells(0,0) 'Gets the cell at "A1"
[C#]
Workbook excel = new Workbook();
Cells cells = excel.Worksheets[0].Cells;
Cell cell = cells["A1"]; //Gets the cell at "A1"
[Visual Basic]
Dim excel as Workbook = New Workbook()
Dim cells As Cells = excel.Worksheets(0).Cells
Dim cell As Cell = cells("A1") 'Gets the cell at "A1"
[C#]
string designerFile = "List.xls";
Workbook excel = new Workbook(designerFile);
Worksheet sheet = excel.Worksheets[0];
DataTable dt = sheet.Cells.ExportDataTable(6, 1, 69, 4);
[Visual Basic]
Dim designerFile As String = "List.xls"
Dim excel As excel = New excel(designerFile)
Dim sheet As Worksheet = excel.Worksheets(0)
Dim dt As DataTable = sheet.Cells.ExportDataTable(6, 1, 69, 4)
[C#]
Workbook excel = new Workbook();
Cells cells = excel.Worksheets[0].Cells;
//Import data
DataTable dt = new DataTable("Products");
dt.Columns.Add("Product_ID",typeof(Int32));
dt.Columns.Add("Product_Name",typeof(string));
dt.Columns.Add("Units_In_Stock",typeof(Int32));
DataRow dr = dt.NewRow();
dr[0] = 1;
dr[1] = "Aniseed Syrup";
dr[2] = 15;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 2;
dr[1] = "Boston Crab Meat";
dr[2] = 123;
dt.Rows.Add(dr);
ImportTableOptions options = new ImportTableOptions();
options.IsFieldNameShown = true;
cells.ImportData(dt, 12, 12, options);
[Visual Basic]
Dim excel as Workbook = new Workbook()
Dim cells as Cells = excel.Worksheets(0).Cells
'Import data
Dim dt as DataTable = new DataTable("Employee")
dt.Columns.Add("Employee_ID",typeof(Int32))
dt.Columns.Add("Employee_Name",typeof(string))
dt.Columns.Add("Gender",typeof(string))
Dim dr as DataRow = dt.NewRow()
dr(0) = 1
dr(1) = "John Smith"
dr(2) = "Male"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = 2
dr(1) = "Mary Miller"
dr(2) = "Female"
dt.Rows.Add(dr)
Dim options as ImportTableOptions = new ImportTableOptions()
options.IsFieldNameShown = True
cells.ImportData(dt, 12, 12, options)
'Export data
Dim outDataTable as DataTable = cells.ExportDataTable(12, 12, 10, 10)
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get the first Worksheet.
Worksheet sheet = workbook.Worksheets[0];
// Add Cell Watch Item into the watch window
sheet.CellWatches.Add("B2");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Get the first Worksheet.
Dim sheet as Worksheet = workbook.Worksheets(0);
'Add Cell Watch Item into the watch window
sheet.CellWatches.Add("B2")
[C#]
Workbook workbook = new Workbook();
workbook.Worksheets.Add();
workbook.Worksheets.Add();
Cell cellInPage1 = workbook.Worksheets[0].Cells["A1"];
Cell cellInPage2 = workbook.Worksheets[1].Cells["A1"];
Cell cellInPage3 = workbook.Worksheets[2].Cells["A1"];
cellInPage1.PutValue("page1");
cellInPage2.PutValue("page2");
cellInPage3.PutValue("page3");
PdfBookmarkEntry pbeRoot = new PdfBookmarkEntry();
pbeRoot.Text = "root"; // if pbeRoot.Text = null, all children of pbeRoot will be inserted on the top level in the bookmark.
pbeRoot.Destination = cellInPage1;
pbeRoot.SubEntry = new ArrayList();
pbeRoot.IsOpen = false;
PdfBookmarkEntry subPbe1 = new PdfBookmarkEntry();
subPbe1.Text = "section1";
subPbe1.Destination = cellInPage2;
PdfBookmarkEntry subPbe2 = new PdfBookmarkEntry();
subPbe2.Text = "section2";
subPbe2.Destination = cellInPage3;
pbeRoot.SubEntry.Add(subPbe1);
pbeRoot.SubEntry.Add(subPbe2);
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.Bookmark = pbeRoot;
workbook.Save("output_bookmark.pdf", saveOptions);
[VB]
Dim workbook As Workbook = New Workbook
workbook.Worksheets.Add("sheet2")
workbook.Worksheets.Add("sheet3")
Dim cells As Cells = workbook.Worksheets(0).Cells
Dim cellInPage1 As Cell = cells("A1")
cellInPage1.PutValue("Page1")
cells = workbook.Worksheets(1).Cells
Dim cellInPage2 As Cell = cells("A1")
cellInPage2.PutValue("Page2")
cells = workbook.Worksheets(2).Cells
Dim cellInPage3 As Cell = cells("A1")
cellInPage3.PutValue("Page3")
Dim pbeRoot As PdfBookmarkEntry = New PdfBookmarkEntry()
pbeRoot.Text = "root"
pbeRoot.Destination = cellInPage1
pbeRoot.SubEntry = New ArrayList
pbeRoot.IsOpen = False
Dim subPbe1 As PdfBookmarkEntry = New PdfBookmarkEntry()
subPbe1.Text = "section1"
subPbe1.Destination = cellInPage2
Dim subPbe2 As PdfBookmarkEntry = New PdfBookmarkEntry()
subPbe2.Text = "section2"
subPbe2.Destination = cellInPage3
pbeRoot.SubEntry.Add(subPbe1)
pbeRoot.SubEntry.Add(subPbe2)
Dim saveOptions As PdfSaveOptions = New PdfSaveOptions()
saveOptions.Bookmark = pbeRoot
workbook.Save("output_bookmark.pdf", saveOptions)
[C#]
//Set Image Or Print Options
ImageOrPrintOptions options = new ImageOrPrintOptions();
//Set output image format
options.ImageType = ImageType.Png;
//Set Horizontal resolution
options.HorizontalResolution = 300;
//Set Vertical Resolution
options.VerticalResolution = 300;
//Instantiate Workbook
Workbook book = new Workbook("test.xls");
//Save chart as Image using ImageOrPrint Options
book.Worksheets[0].Charts[0].ToImage("chart.png", options);
[VB.NET]
'Set Image Or Print Options
Dim options As New ImageOrPrintOptions()
'Set output image format
options.ImageType = ImageType.Png
'Set Horizontal resolution
options.HorizontalResolution = 300
'Set Vertical Resolution
options.VerticalResolution = 300
'Instantiate Workbook
Dim book As New Workbook("test.xls")
'Save chart as Image using ImageOrPrint Options
book.Worksheets(0).Charts(0).ToImage("chart.png", options)
Workbook wb = new Workbook("Book1.xlsx");
ImageOrPrintOptions opts = new ImageOrPrintOptions();
//Set output image type: png.
opts.ImageType = ImageType.Png;
//Set resolution to 192.
opts.HorizontalResolution = 192;
opts.VerticalResolution = 192;
//Render worksheet page to image.
SheetRender sr = new SheetRender(wb.Worksheets[0], opts);
sr.ToImage(0, "Sheet_Page1.png");
Workbook wb = new Workbook("Book1.xlsx");
ImageOrPrintOptions opts = new ImageOrPrintOptions();
//Set output image type: png.
opts.ImageType = ImageType.Png;
//Set resolution to 192.
opts.HorizontalResolution = 192;
opts.VerticalResolution = 192;
//Render Chart to image.
wb.Worksheets[0].Charts[0].ToImage("Chart.png", opts);
Workbook workbook = new Workbook("Book1.xlsx");
SheetPrintingPreview sheetPrintingPreview = new SheetPrintingPreview(workbook.Worksheets[0], new ImageOrPrintOptions());
//fastest way to get page count especailly when there are massive data in worksheet.
Console.WriteLine(sheetPrintingPreview.EvaluatedPageCount);
Workbook wb = new Workbook("Book1.xlsx");
SheetRender sheetRender = new SheetRender(wb.Worksheets[0], new ImageOrPrintOptions());
//Gets calculated page scale of the sheet.
double pageScale = sheetRender.PageScale;
//load the source file with images.
Workbook wb = new Workbook("Book1.xlsx");
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
//set output image type.
imgOpt.ImageType = ImageType.Png;
//render the first sheet.
SheetRender sr = new SheetRender(wb.Worksheets[0], imgOpt);
//output the first page of the sheet to image.
sr.ToImage(0, "output.png");
//load the source file with images.
Workbook wb = new Workbook("Book1.xlsx");
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
//set output image type.
imgOpt.SaveFormat = SaveFormat.Tiff;
//render the first sheet.
SheetRender sr = new SheetRender(wb.Worksheets[0], imgOpt);
//output all the pages of the sheet to Tiff image.
sr.ToTiff("output.tiff");
Workbook workbook = new Workbook("Book1.xlsx");
WorkbookPrintingPreview workbookPrintingPreview = new WorkbookPrintingPreview(workbook, new ImageOrPrintOptions());
//fastest way to get page count especailly when there are massive data in workbook.
Console.WriteLine(workbookPrintingPreview.EvaluatedPageCount);
Workbook wb = new Workbook();
wb.Worksheets[0].Cells["A1"].Value = "Aspose";
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
PdfSecurityOptions pdfSecurityOptions = new PdfSecurityOptions();
//set owner password
pdfSecurityOptions.OwnerPassword = "YourOwnerPassword";
//set user password
pdfSecurityOptions.UserPassword = "YourUserPassword";
//set print permisson
pdfSecurityOptions.PrintPermission = true;
//set high resolution for print
pdfSecurityOptions.FullQualityPrintPermission = true;
pdfSaveOptions.SecurityOptions = pdfSecurityOptions;
wb.Save("output.pdf", pdfSaveOptions);
The owner password or user password will be required to open an encrypted PDF document for viewing.
The user password can be null or empty string, in this case no password will be required from the user when opening the PDF document.
Opening the document with the correct owner password allows full access to the document.
Opening the document with the correct user password (or opening a document that does not have a user password) allows limited access as the permissions specified.
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Workbook object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
//Setting the foreground color of the plot area
chart.PlotArea.Area.ForegroundColor = Color.Blue;
//Setting the foreground color of the chart area
chart.ChartArea.Area.ForegroundColor = Color.Yellow;
//Setting the foreground color of the 1st NSeries area
chart.NSeries[0].Area.ForegroundColor = Color.Red;
//Setting the foreground color of the area of the 1st NSeries point
chart.NSeries[0].Points[0].Area.ForegroundColor = Color.Cyan;
//Saving the Excel file
workbook.Save("book1.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Workbook object
Dim sheetIndex As Integer = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a chart to the worksheet
Dim chartIndex As Integer = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", True)
'Setting the foreground color of the plot area
chart.PlotArea.Area.ForegroundColor = Color.Blue
'Setting the foreground color of the chart area
chart.ChartArea.Area.ForegroundColor = Color.Yellow
'Setting the foreground color of the 1st NSeries area
chart.NSeries(0).Area.ForegroundColor = Color.Red
'Setting the foreground color of the area of the 1st NSeries point
chart.NSeries(0).Points(0).Area.ForegroundColor = Color.Cyan
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Workbook object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(-100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "A3"
chart.NSeries.Add("A1:A3", true);
chart.NSeries[0].Area.InvertIfNegative = true;
//Setting the foreground color of the 1st NSeries area
chart.NSeries[0].Area.ForegroundColor = Color.Red;
//Setting the background color of the 1st NSeries area.
//The displayed area color of second chart point will be the background color.
chart.NSeries[0].Area.BackgroundColor = Color.Yellow;
//Saving the Excel file
workbook.Save("book1.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Workbook object
Dim sheetIndex As Integer = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(-100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a chart to the worksheet
Dim chartIndex As Integer = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "A3"
chart.NSeries.Add("A1:A3", True)
chart.NSeries(0).Area.InvertIfNegative = True
'Setting the foreground color of the 1st NSeries area
chart.NSeries(0).Area.ForegroundColor = Color.Red
'Setting the background color of the 1st NSeries area.
'The displayed area color of second chart point will be the background color.
chart.NSeries(0).Area.BackgroundColor = Color.Yellow
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Initialize a new workbook.
Workbook book = new Workbook();
//Add a ToggleButtonActiveXControl.
Shape shape = book.Worksheets[0].Shapes.AddActiveXControl(ControlType.RadioButton, 1, 0, 1, 0, 100, 50);
RadioButtonActiveXControl activeXControl = (RadioButtonActiveXControl)shape.ActiveXControl;
//do your business
//Save the excel file.
book.Save("exmaple.xlsx");
[C#]
if(activeXControl.Type == Aspose.Cells.Drawing.ActiveXControls.ControlType.RadioButton)
{
//do something
}
[C#]
activeXControl.GroupName = "GroupName123";
[C#]
activeXControl.Alignment = Aspose.Cells.Drawing.ActiveXControls.ControlCaptionAlignmentType.Left;
[C#]
if(activeXControl.IsWordWrapped == false)
{
activeXControl.IsWordWrapped = true;
}
[C#]
//Initialize a new workbook.
Workbook book = new Workbook();
//Add a ToggleButtonActiveXControl.
Shape shape = book.Worksheets[0].Shapes.AddActiveXControl(ControlType.ScrollBar, 1, 0, 1, 0, 100, 50);
ScrollBarActiveXControl activeXControl = (ScrollBarActiveXControl)shape.ActiveXControl;
//do your business
//Save the excel file.
book.Save("exmaple.xlsx");
[C#]
if(activeXControl.Type == Aspose.Cells.Drawing.ActiveXControls.ControlType.ScrollBar)
{
//do something
}
[C#]
activeXControl.LargeChange = 5;
[C#]
//Initialize a new workbook.
Workbook book = new Workbook();
//Add a ToggleButtonActiveXControl.
Shape shape = book.Worksheets[0].Shapes.AddActiveXControl(ControlType.SpinButton, 1, 0, 1, 0, 100, 50);
SpinButtonActiveXControl activeXControl = (SpinButtonActiveXControl)shape.ActiveXControl;
//do your business
//Save the excel file.
book.Save("exmaple.xlsx");
[C#]
if(activeXControl.Type == Aspose.Cells.Drawing.ActiveXControls.ControlType.SpinButton)
{
//do something
}
[C#]
activeXControl.Min = 0;
[C#]
activeXControl.Max = 100;
[C#]
activeXControl.Position = 30;
[C#]
activeXControl.SmallChange = 5;
[C#]
if(activeXControl.Orientation == Aspose.Cells.Drawing.ActiveXControls.ControlScrollOrientation.Auto)
{
activeXControl.Orientation = Aspose.Cells.Drawing.ActiveXControls.ControlScrollOrientation.Horizontal;
}
[C#]
//Initialize a new workbook.
Workbook book = new Workbook();
//Add a TextBoxActiveXControl.
Shape shape = book.Worksheets[0].Shapes.AddActiveXControl(ControlType.TextBox, 1, 0, 1, 0, 100, 50);
TextBoxActiveXControl activeXControl = (TextBoxActiveXControl)shape.ActiveXControl;
//do your business
//Save the excel file.
book.Save("exmaple.xlsx");
[C#]
Aspose.Cells.Drawing.ActiveXControls.ControlType type = activeXControl.Type;
[C#]
activeXControl.BorderStyle = Aspose.Cells.Drawing.ActiveXControls.ControlBorderType.Single;
[C#]
//excel default color system 12 or green(0x0000FF00)
activeXControl.BorderOleColor = unchecked((int)0x80000012);
[C#]
activeXControl.SpecialEffect = Aspose.Cells.Drawing.ActiveXControls.ControlSpecialEffectType.Bump;
[C#]
if(activeXControl.MaxLength == 0)
{
activeXControl.MaxLength = 30;
}
[C#]
activeXControl.ScrollBars = Aspose.Cells.Drawing.ActiveXControls.ControlScrollBarType.BarsVertical;
[C#]
activeXControl.PasswordChar = 'a';
[C#]
if(!activeXControl.IsEditable)
{
activeXControl.IsEditable = true;
}
[C#]
if(!activeXControl.IntegralHeight)
{
activeXControl.IntegralHeight = true;
}
[C#]
if(!activeXControl.IsDragBehaviorEnabled)
{
activeXControl.IsDragBehaviorEnabled = true;
}
[C#]
if(!activeXControl.EnterKeyBehavior)
{
activeXControl.EnterKeyBehavior = true;
}
[C#]
if(!activeXControl.EnterFieldBehavior)
{
activeXControl.EnterFieldBehavior = true;
}
[C#]
if(!activeXControl.TabKeyBehavior)
{
activeXControl.TabKeyBehavior = true;
}
[C#]
if(!activeXControl.HideSelection)
{
activeXControl.HideSelection = true;
}
[C#]
if(!activeXControl.IsAutoTab)
{
activeXControl.IsAutoTab = true;
}
[C#]
if(!activeXControl.IsMultiLine)
{
activeXControl.IsMultiLine = true;
}
[C#]
if(!activeXControl.IsAutoWordSelected)
{
activeXControl.IsAutoWordSelected = true;
}
[C#]
if(!activeXControl.IsWordWrapped)
{
activeXControl.IsWordWrapped = true;
}
[C#]
activeXControl.Text = "This is a test.";
[C#]
activeXControl.DropButtonStyle = Aspose.Cells.Drawing.ActiveXControls.DropButtonStyle.Arrow;
[C#]
activeXControl.ShowDropButtonTypeWhen = Aspose.Cells.Drawing.ActiveXControls.ShowDropButtonType.Focus;
[C#]
//Initialize a new workbook.
Workbook book = new Workbook();
//Add a ToggleButtonActiveXControl.
Shape shape = book.Worksheets[0].Shapes.AddActiveXControl(ControlType.ToggleButton, 1, 0, 1, 0, 100, 50);
ToggleButtonActiveXControl activeXControl = (ToggleButtonActiveXControl)shape.ActiveXControl;
//do your business
//Save the excel file.
book.Save("exmaple.xlsx");
[C#]
Aspose.Cells.Drawing.ActiveXControls.ControlType type = activeXControl.Type;
[C#]
activeXControl.Caption = "ExampleButton";
[C#]
activeXControl.PicturePosition = Aspose.Cells.Drawing.ActiveXControls.ControlPicturePositionType.AboveLeft;
[C#]
activeXControl.SpecialEffect = Aspose.Cells.Drawing.ActiveXControls.ControlSpecialEffectType.Bump;
[C#]
//e.g byte[] data = File.ReadAllBytes("image.png");
byte[] data = null;
if(activeXControl.Picture != null)
{
activeXControl.Picture = data;
}
[C#]
if ('\0' != activeXControl.Accelerator)
{
activeXControl.Accelerator = '\0';
}
[C#]
if(activeXControl.Value == CheckValueType.UnChecked)
{
activeXControl.Value = CheckValueType.Checked;
}
[C#]
activeXControl.IsTripleState = false;
[C#]
//Instantiate a new Workbook.
Workbook excelbook = new Workbook();
//Add an arc shape.
Aspose.Cells.Drawing.ArcShape arc1 = excelbook.Worksheets[0].Shapes.AddArc(2, 0, 2, 0, 130, 130);
//Set the placement of the arc.
arc1.Placement = PlacementType.FreeFloating;
//Set the fill format.
arc1.Fill.FillType = FillType.Solid;
arc1.Fill.SolidFill.Color = Color.Blue;
//Set the line style.
arc1.Line.CompoundType = MsoLineStyle.Single;
//Set the line weight.
arc1.Line.Weight = 2;
//Set the color of the arc line.
arc1.Line.FillType = FillType.Solid;
arc1.Line.SolidFill.Color = Color.Red;
//Set the dash style of the arc.
arc1.Line.DashStyle = MsoLineDashStyle.Solid;
//Add another arc shape.
Aspose.Cells.Drawing.ArcShape arc2 = excelbook.Worksheets[0].Shapes.AddArc(9, 0, 2, 0, 130, 130);
//Set the placement of the arc.
arc2.Placement = PlacementType.FreeFloating;
//Set the line style.
arc2.Line.CompoundType = MsoLineStyle.Single;
//Set the line weight.
arc2.Line.Weight = 1;
//Set the color of the arc line.
arc2.Line.FillType = FillType.Solid;
arc2.Line.SolidFill.Color = Color.Blue;
//Set the dash style of the arc.
arc2.Line.DashStyle = MsoLineDashStyle.Solid;
//Save the excel file.
excelbook.Save("tstarcs.xls");
[VB..NET]
'Instantiate a new Workbook.
Dim excelbook As Workbook = New Workbook()
'Add an arc shape.
Dim arc1 As Aspose.Cells.Drawing.ArcShape = excelbook.Worksheets(0).Shapes.AddArc(2, 0, 2, 0, 130, 130)
'Set the placement of the arc.
arc1.Placement = PlacementType.FreeFloating
'Set the fill format.
arc1.Fill.FillType = FillType.Solid
arc1.Fill.SolidFill.Color = Color.Blue
'Set the line style.
arc1.Line.CompoundType = MsoLineStyle.Single
'Set the line weight.
arc1.Line.Weight = 2
'Set the color of the arc line.
arc1.Line.FillType = FillType.Solid
arc1.Line.SolidFill.Color = Color.Red
'Set the dash style of the arc.
arc1.Line.DashStyle = MsoLineDashStyle.Solid
'Add another arc shape.
Dim arc2 As Aspose.Cells.Drawing.ArcShape = excelbook.Worksheets(0).Shapes.AddArc(9, 0, 2, 0, 130, 130)
'Set the placement of the arc.
arc2.Placement = PlacementType.FreeFloating
'Set the line style.
arc2.Line.CompoundType = MsoLineStyle.Single
'Set the line weight.
arc2.Line.Weight = 1
'Set the color of the arc line.
arc2.Line.FillType = FillType.Solid
arc2.Line.SolidFill.Color = Color.Blue
'Set the dash style of the arc.
arc2.Line.DashStyle = MsoLineDashStyle.Solid
'Save the excel file.
excelbook.Save("tstarcs.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.PieExploded, 5, 0, 25, 10);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
//Show Data Labels
chart.NSeries[0].DataLabels.ShowValue = true;
//Getting Chart Shape
ChartShape chartShape = chart.ChartObject;
//Set Lower Right Column
chartShape.LowerRightColumn = 10;
//Set LowerDeltaX
chartShape.LowerDeltaX = 1024;
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a chart to the worksheet
Dim chartIndex As Integer = worksheet.Charts.Add(ChartType.PieExploded, 5, 0, 25, 10)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", True)
'Show Data Labels
chart.NSeries(0).DataLabels.ShowValue = True
'Getting Chart Shape
Dim chartShape As ChartShape = chart.ChartObject
'Set Lower Right Column
chartShape.LowerRightColumn = 10
'Set LowerDeltaX
chartShape.LowerDeltaX = 1024
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//source file
string fileName = "";
//Instantiating a Workbook object
Workbook workbook = new Workbook(fileName);
ShapeCollection shapes = workbook.Worksheets[0].Shapes;
//Check if a shape is CommentShape
CommentShape commentShape = null;
if (shapes[0].MsoDrawingType == Aspose.Cells.Drawing.MsoDrawingType.Comment)
{
//Represents the shape of the comment.
commentShape = (CommentShape)shapes[0];
}
//do your business
[C#]
Comment comment = commentShape.Comment;
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
ShapeCollection shapes = workbook.Worksheets[0].Shapes;
//add a CustomXmlShape
Shape shape = shapes.AddShape(MsoDrawingType.CustomXml, 3, 0, 3, 0, 50, 150);
//Check if a shape is CustomXmlShape
CustomXmlShape customXmlShape = null;
if (shapes[0].MsoDrawingType == Aspose.Cells.Drawing.MsoDrawingType.CustomXml)
{
//is CustomXmlShape
customXmlShape = (CustomXmlShape)shapes[0];
}
//do your business
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "A4" cell
worksheet.Cells["A4"].PutValue(200);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a sample value to "B4" cell
worksheet.Cells["B4"].PutValue(40);
//Adding a sample value to "C1" cell as category data
worksheet.Cells["C1"].PutValue("Q1");
//Adding a sample value to "C2" cell as category data
worksheet.Cells["C2"].PutValue("Q2");
//Adding a sample value to "C3" cell as category data
worksheet.Cells["C3"].PutValue("Y1");
//Adding a sample value to "C4" cell as category data
worksheet.Cells["C4"].PutValue("Y2");
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
int seriesIndex = chart.NSeries.Add("A1:B4", true);
//Setting the data source for the category data of NSeries
chart.NSeries.CategoryData = "C1:C4";
//Filling the area of the 2nd NSeries with a gradient
chart.NSeries[seriesIndex].Area.FillFormat.SetOneColorGradient(Color.Lime, 1, GradientStyleType.Horizontal, 1);
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Excel object
Dim sheetIndex As Int32 = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "A4" cell
worksheet.Cells("A4").PutValue(200)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a sample value to "B4" cell
worksheet.Cells("B4").PutValue(40)
'Adding a sample value to "C1" cell as category data
worksheet.Cells("C1").PutValue("Q1")
'Adding a sample value to "C2" cell as category data
worksheet.Cells("C2").PutValue("Q2")
'Adding a sample value to "C3" cell as category data
worksheet.Cells("C3").PutValue("Y1")
'Adding a sample value to "C4" cell as category data
worksheet.Cells("C4").PutValue("Y2")
'Adding a chart to the worksheet
Dim chartIndex As Int32 = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
Dim seriesIndex As Int32 = chart.NSeries.Add("A1:B4", True)
'Setting the data source for the category data of NSeries
chart.NSeries.CategoryData = "C1:C4"
'Filling the area of the 2nd NSeries with a gradient
chart.NSeries(seriesIndex).Area.FillFormat.SetOneColorGradient(Color.Lime, 1, GradientStyleType.Horizontal, 1)
[C#]
//Create a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet in the workbook.
Worksheet sheet = workbook.Worksheets[0];
//Add a new button to the worksheet.
Aspose.Cells.Drawing.Button button = sheet.Shapes.AddButton(2, 0, 2, 0, 28, 80);
//Set the caption of the button.
button.Text = "Aspose";
//Set the Placement Type, the way the
//button is attached to the cells.
button.Placement = PlacementType.FreeFloating;
//Set the font name.
button.Font.Name = "Tahoma";
//Set the caption string bold.
button.Font.IsBold = true;
//Set the color to blue.
button.Font.Color = Color.Blue;
//Set the hyperlink for the button.
button.AddHyperlink("http://www.aspose.com/");
//Saves the file.
workbook.Save(@"tstbutton.xls");
[VB.NET]
'Create a new Workbook.
Dim workbook As Workbook = New Workbook()
'Get the first worksheet in the workbook.
Dim sheet As Worksheet = workbook.Worksheets(0)
'Add a new button to the worksheet.
Dim button As Aspose.Cells.Drawing.Button = sheet.Shapes.AddButton(2, 0, 2, 0, 28, 80)
'Set the caption of the button.
button.Text = "Aspose"
'Set the Placement Type, the way the
'button is attached to the cells.
button.Placement = PlacementType.FreeFloating
'Set the font name.
button.Font.Name = "Tahoma"
'Set the caption string bold.
button.Font.IsBold = True
'Set the color to blue.
button.Font.Color = Color.Blue
'Set the hyperlink for the button.
button.AddHyperlink("http://www.aspose.com/")
'Saves the file.
workbook.Save("tstbutton.xls")
[C#]
//Instantiate a new Workbook.
Workbook excel = new Workbook();
int index = excel.Worksheets[0].CheckBoxes.Add(15, 15, 20, 100);
CheckBox checkBox = excel.Worksheets[0].CheckBoxes[index];
checkBox.Text = "Check Box 1";
//Save the excel file.
excel.Save("checkBox.xlsx");
[Visual Basic]
Dim excel As Workbook = new Workbook()
Dim index as integer = excel.Worksheets(0).CheckBoxes.Add(15, 15, 20, 100)
Dim checkBox as CheckBox = excel.Worksheets(0).CheckBoxes[index];
checkBox.Text = "Check Box 1"
excel.Save("checkBox.xlsx")
[C#]
//Create a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet in the workbook.
Worksheet sheet = workbook.Worksheets[0];
int index = sheet.CheckBoxes.Add(15, 15, 20, 100);
CheckBox checkBox = sheet.CheckBoxes[index];
checkBox.Text = "Check Box 1";
[Visual Basic]
'Create a new Workbook.
Dim workbook As Workbook = new Workbook()
'Get the first worksheet in the workbook.
Dim sheet As Worksheet = workbook.Worksheets(0)
Dim index as integer = sheet.CheckBoxes.Add(15, 15, 20, 100)
Dim checkBox as CheckBox = sheet.CheckBoxes[index];
checkBox.Text = "Check Box 1"
[C#]
//Create a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
//Get the worksheet cells collection.
Cells cells = sheet.Cells;
//Input a value.
cells["B3"].PutValue("Employee:");
//Set it bold.
Style style = cells["B3"].GetStyle();
style.Font.IsBold = true;
cells["B3"].SetStyle(style);
//Input some values that denote the input range
//for the combo box.
cells["A2"].PutValue("Emp001");
cells["A3"].PutValue("Emp002");
cells["A4"].PutValue("Emp003");
cells["A5"].PutValue("Emp004");
cells["A6"].PutValue("Emp005");
cells["A7"].PutValue("Emp006");
//Add a new combo box.
Aspose.Cells.Drawing.ComboBox comboBox = sheet.Shapes.AddComboBox(2, 0, 2, 0, 22, 100);
//Set the linked cell;
comboBox.LinkedCell = "A1";
//Set the input range.
comboBox.InputRange = "A2:A7";
//Set no. of list lines displayed in the combo
//box's list portion.
comboBox.DropDownLines = 5;
//Set the combo box with 3-D shading.
comboBox.Shadow = true;
//AutoFit Columns
sheet.AutoFitColumns();
//Saves the file.
workbook.Save(@"tstcombobox.xls");
[VB.NET]
'Create a new Workbook.
Dim workbook As Workbook = New Workbook()
'Get the first worksheet.
Dim sheet As Worksheet = workbook.Worksheets(0)
'Get the worksheet cells collection.
Dim cells As Cells = sheet.Cells
'Input a value.
cells("B3").PutValue("Employee:")
'Set it bold.
Dim style As Style = cells("B3").GetStyle()
style.Font.IsBold = true
cells("B3").SetStyle(style)
'Input some values that denote the input range
'for the combo box.
cells("A2").PutValue("Emp001")
cells("A3").PutValue("Emp002")
cells("A4").PutValue("Emp003")
cells("A5").PutValue("Emp004")
cells("A6").PutValue("Emp005")
cells("A7").PutValue("Emp006")
'Add a new combo box.
Dim comboBox As Aspose.Cells.Drawing.ComboBox = sheet.Shapes.AddComboBox(2, 0, 2, 0, 22, 100)
'Set the linked cell;
comboBox.LinkedCell = "A1"
'Set the input range.
comboBox.InputRange = "A2:A7"
'Set no. of list lines displayed in the combo
'box's list portion.
comboBox.DropDownLines = 5
'Set the combo box with 3-D shading.
comboBox.Shadow = True
'AutoFit Columns
sheet.AutoFitColumns()
'Saves the file.
workbook.Save("tstcombobox.xls")
[C#]
//Instantiate a new Workbook.
Workbook excelbook = new Workbook();
//Add a group box to the first worksheet.
GroupBox box = excelbook.Worksheets[0].Shapes.AddGroupBox(1, 0, 1, 0, 300, 250);
//Set the caption of the group box.
box.Text = "Age Groups";
box.Placement = PlacementType.FreeFloating;
//Make it 2-D box.
box.Shadow = false;
//Save the excel file.
excelbook.Save("groupbox.xls");
[VB.NET]
'Instantiate a new Workbook.
Dim excelbook As Workbook = New Workbook()
'Add a group box to the first worksheet.
Dim box As GroupBox = excelbook.Worksheets(0).Shapes.AddGroupBox(1, 0, 1, 0, 300, 250)
'Set the caption of the group box.
box.Text = "Age Groups"
box.Placement = PlacementType.FreeFloating
'Make it 2-D box.
box.Shadow = False
'Save the excel file.
excelbook.Save("groupbox.xls")
//Create a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet in the workbook.
Worksheet sheet = workbook.Worksheets[0];
//Add a new label to the worksheet.
Aspose.Cells.Drawing.Label label = sheet.Shapes.AddLabel(2, 0, 2, 0, 60, 120);
//Set the caption of the label.
label.Text = "This is a Label";
//Set the Placement Type, the way the
//label is attached to the cells.
label.Placement = PlacementType.FreeFloating;
//Set the fill color of the label.
label.Fill.FillType = FillType.Solid;
label.Fill.SolidFill.Color = Color.Yellow;
//Saves the file.
workbook.Save("tstlabel.xls");
[VB.NET]
'Create a new Workbook.
Dim workbook As Workbook = New Workbook()
'Get the first worksheet in the workbook.
Dim sheet As Worksheet = workbook.Worksheets(0)
'Add a new label to the worksheet.
Dim label As Aspose.Cells.Drawing.Label = sheet.Shapes.AddLabel(2, 0, 2, 0, 60, 120)
'Set the caption of the label.
label.Text = "This is a Label"
'Set the Placement Type, the way the
'label is attached to the cells.
label.Placement = PlacementType.FreeFloating
'Set the fill color of the label.
label.Fill.FillType = FillType.Solid
label.Fill.SolidFill.Color = Color.Yellow
'Saves the file.
workbook.Save("tstlabel.xls")
[C#]
//Create a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
//Get the worksheet cells collection.
Cells cells = sheet.Cells;
//Input a value.
cells["B3"].PutValue("Choose Dept:");
//Set it bold.
Style style = cells["B3"].GetStyle();
style.Font.IsBold = true;
cells["B3"].SetStyle(style);
//Input some values that denote the input range
//for the list box.
cells["A2"].PutValue("Sales");
cells["A3"].PutValue("Finance");
cells["A4"].PutValue("MIS");
cells["A5"].PutValue("R&D");
cells["A6"].PutValue("Marketing");
cells["A7"].PutValue("HRA");
//Add a new list box.
ListBox listBox = sheet.Shapes.AddListBox(2, 0, 3, 0, 122, 100);
//Set the placement type.
listBox.Placement = PlacementType.FreeFloating;
//Set the linked cell.
listBox.LinkedCell = "A1";
//Set the input range.
listBox.InputRange = "A2:A7";
//Set the selection style.
listBox.SelectionType = SelectionType.Single;
//Set the list box with 3-D shading.
listBox.Shadow = true;
//Saves the file.
workbook.Save(@"tstlistbox.xls");
[VB.NET]
'Create a new Workbook.
Dim workbook As Aspose.Cells.Workbook = New Aspose.Cells.Workbook()
'Get the first worksheet.
Dim sheet As Worksheet = workbook.Worksheets(0)
'Get the worksheet cells collection.
Dim cells As Cells = sheet.Cells
'Input a value.
cells("B3").PutValue("Choose Dept:")
'Set it bold.
Dim style As Style = cells("B3").GetStyle()
style.Font.IsBold = True
cells("B3").SetStyle(style)
'Input some values that denote the input range
'for the list box.
cells("A2").PutValue("Sales")
cells("A3").PutValue("Finance")
cells("A4").PutValue("MIS")
cells("A5").PutValue("R&D")
cells("A6").PutValue("Marketing")
cells("A7").PutValue("HRA")
'Add a new list box.
Dim listBox As Aspose.Cells.ListBox = sheet.Shapes.AddListBox(2, 0, 3, 0, 122, 100)
'Set the placement type.
listBox.Placement = PlacementType.FreeFloating
'Set the linked cell.
listBox.LinkedCell = "A1"
'Set the input range.
listBox.InputRange = "A2:A7"
'Set the selection tyle.
listBox.SelectionType = SelectionType.Single
'Set the list box with 3-D shading.
listBox.Shadow = True
'Saves the file.
workbook.Save("tstlistbox.xls")
[C#]
//Instantiate a new Workbook.
Workbook excelbook = new Workbook();
//Add a group box to the first worksheet.
GroupBox box = excelbook.Worksheets[0].Shapes.AddGroupBox(1, 0, 1, 0, 300, 250);
//Set the caption of the group box.
box.Text = "Age Groups";
box.Placement = PlacementType.FreeFloating;
//Make it 2-D box.
box.Shadow = false;
//Add a radio button.
RadioButton radio1 = excelbook.Worksheets[0].Shapes.AddRadioButton(3, 0, 2, 0, 30, 110);
//Set its text string.
radio1.Text = "20-29";
//Set A1 cell as a linked cell for the radio button.
radio1.LinkedCell = "A1";
//Make the radio button 3-D.
radio1.Shadow = true;
//Make the line format visible.
radio1.Line.FillType = FillType.Solid;
//Make the fill format visible.
radio1.Fill.FillType = FillType.Solid;
//Set the foreground color of the radio button.
radio1.Fill.SolidFill.Color = Color.LightGreen;
//Set the line style of the radio button.
radio1.Line.CompoundType = MsoLineStyle.ThickThin;
//Set the weight of the radio button.
radio1.Line.Weight = 4;
//Set the line color of the radio button.
radio1.Line.SolidFill.Color = Color.Blue;
//Set the dash style of the radio button.
radio1.Line.DashStyle = MsoLineDashStyle.Solid;
//Add another radio button.
RadioButton radio2 = excelbook.Worksheets[0].Shapes.AddRadioButton(6, 0, 2, 0, 30, 110);
//Set its text string.
radio2.Text = "30-39";
//Set A1 cell as a linked cell for the radio button.
radio2.LinkedCell = "A1";
//Make the radio button 3-D.
radio2.Shadow = true;
//Make the line format visible.
radio2.Line.FillType = FillType.Solid;
//Make the fill format visible.
radio2.Fill.FillType = FillType.Solid;
//Set the foreground color of the radio button.
radio2.Fill.SolidFill.Color = Color.LightGreen;
//Set the line style of the radio button.
radio2.Line.CompoundType = MsoLineStyle.ThickThin;
//Set the weight of the radio button.
radio2.Line.Weight = 4;
//Set the line color of the radio button.
radio2.Line.SolidFill.Color = Color.Blue;
//Set the dash style of the radio button.
radio2.Line.DashStyle = MsoLineDashStyle.Solid;
//Add another radio button.
RadioButton radio3 = excelbook.Worksheets[0].Shapes.AddRadioButton(9, 0, 2, 0, 30, 110);
//Set its text string.
radio3.Text = "40-49";
//Set A1 cell as a linked cell for the radio button.
radio3.LinkedCell = "A1";
//Make the radio button 3-D.
radio3.Shadow = true;
//Make the line format visible.
radio3.Line.FillType = FillType.Solid;
//Make the fill format visible.
radio3.Fill.FillType = FillType.Solid;
//Set the foreground color of the radio button.
radio3.Fill.SolidFill.Color = Color.LightGreen;
//Set the line style of the radio button.
radio3.Line.CompoundType = MsoLineStyle.ThickThin;
//Set the weight of the radio button.
radio3.Line.Weight = 4;
//Set the line color of the radio button.
radio3.Line.SolidFill.Color = Color.Blue;
//Set the dash style of the radio button.
radio3.Line.DashStyle = MsoLineDashStyle.Solid;
//Get the shapes.
Shape[] shapeobjects = new Shape[] { box, radio1, radio2, radio3 };
//Group the shapes.
GroupShape group = excelbook.Worksheets[0].Shapes.Group(shapeobjects);
//Save the excel file.
excelbook.Save("groupshapes.xls");
[VB.NET]
'Instantiate a new Workbook.
Dim excelbook As Workbook = New Workbook()
'Add a group box to the first worksheet.
Dim box As GroupBox = excelbook.Worksheets(0).Shapes.AddGroupBox(1, 0, 1, 0, 300, 250)
'Set the caption of the group box.
box.Text = "Age Groups"
box.Placement = PlacementType.FreeFloating
'Make it 2-D box.
box.Shadow = False
'Add a radio button.
Dim radio1 As RadioButton = excelbook.Worksheets(0).Shapes.AddRadioButton(3, 0, 2, 0, 30, 110)
'Set its text string.
radio1.Text = "20-29"
'Set A1 cell as a linked cell for the radio button.
radio1.LinkedCell = "A1"
'Make the radio button 3-D.
radio1.Shadow = True
'Make the fill format visible.
radio1.Fill.FillType = FillType.Solid
'Set the foreground color of the radio button.
radio1.Fill.SolidFill.Color = Color.LightGreen
'Make the line format visible.
radio1.Line.FillType = FillType.Solid
'Set the line style of the radio button.
radio1.Line.CompoundType = MsoLineStyle.ThickThin
'Set the weight of the radio button.
radio1.Line.Weight = 4
'Set the line color of the radio button.
radio1.Line.SolidFill.Color = Color.Blue
'Set the dash style of the radio button.
radio1.Line.DashStyle = MsoLineDashStyle.Solid
'Add another radio button.
Dim radio2 As RadioButton = excelbook.Worksheets(0).Shapes.AddRadioButton(6, 0, 2, 0, 30, 110)
'Set its text string.
radio2.Text = "30-39"
'Set A1 cell as a linked cell for the radio button.
radio2.LinkedCell = "A1"
'Make the radio button 3-D.
radio2.Shadow = True
'Make the fill format visible.
radio2.Fill.FillType = FillType.Solid
'Set the foreground color of the radio button.
radio2.Fill.SolidFill.Color = Color.LightGreen
'Make the line format visible.
radio2.Line.FillType = FillType.Solid
'Set the line style of the radio button.
radio2.Line.CompoundType = MsoLineStyle.ThickThin
'Set the weight of the radio button.
radio2.Line.Weight = 4
'Set the line color of the radio button.
radio2.Line.SolidFill.Color = Color.Blue
'Set the dash style of the radio button.
radio2.Line.DashStyle = MsoLineDashStyle.Solid
'Add another radio button.
Dim radio3 As RadioButton = excelbook.Worksheets(0).Shapes.AddRadioButton(9, 0, 2, 0, 30, 110)
'Set its text string.
radio3.Text = "40-49"
'Set A1 cell as a linked cell for the radio button.
radio3.LinkedCell = "A1"
'Make the radio button 3-D.
radio3.Shadow = True
'Make the fill format visible.
radio3.Fill.FillType = FillType.Solid
'Set the foreground color of the radio button.
radio3.Fill.SolidFill.Color = Color.LightGreen
'Make the line format visible.
radio3.Line.FillType = FillType.Solid
'Set the line style of the radio button.
radio3.Line.CompoundType = MsoLineStyle.ThickThin
'Set the weight of the radio button.
radio3.Line.Weight = 4
'Set the line color of the radio button.
radio3.Line.SolidFill.Color = Color.Blue
'Set the dash style of the radio button.
radio3.Line.DashStyle = MsoLineDashStyle.Solid
'Get the shapes.
Dim shapeobjects() As Shape = New Shape() {box, radio1, radio2, radio3}
'Group the shapes.
Dim group As GroupShape = excelbook.Worksheets(0).Shapes.Group(shapeobjects)
'Save the excel file.
excelbook.Save("groupshapes.xls")
[C#]
//Instantiate a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet in the book.
Worksheet worksheet = workbook.Worksheets[0];
//Add a new line to the worksheet.
Aspose.Cells.Drawing.LineShape line1 = worksheet.Shapes.AddLine(5, 0, 1, 0, 0, 250);
//Set the line dash style
line1.Line.DashStyle = MsoLineDashStyle.Solid;
//Set the placement.
line1.Placement = PlacementType.FreeFloating;
//Add another line to the worksheet.
Aspose.Cells.Drawing.LineShape line2 = worksheet.Shapes.AddLine(7, 0, 1, 0, 85, 250);
//Set the line dash style.
line2.Line.DashStyle = MsoLineDashStyle.DashLongDash;
//Set the weight of the line.
line2.Line.Weight = 4;
//Set the placement.
line2.Placement = PlacementType.FreeFloating;
//Add the third line to the worksheet.
Aspose.Cells.Drawing.LineShape line3 = worksheet.Shapes.AddLine(13, 0, 1, 0, 0, 250);
//Set the line dash style
line3.Line.DashStyle = MsoLineDashStyle.Solid;
//Set the placement.
line3.Placement = PlacementType.FreeFloating;
//Make the gridlines invisible in the first worksheet.
workbook.Worksheets[0].IsGridlinesVisible = false;
//Save the excel file.
workbook.Save("tstlines.xls");
[VB.NET]
'Instantiate a new Workbook.
Dim workbook As Workbook = New Workbook()
'Get the first worksheet in the book.
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Add a new line to the worksheet.
Dim line1 As Aspose.Cells.Drawing.LineShape = worksheet.Shapes.AddLine(5, 0, 1, 0, 0, 250)
'Set the line dash style
line1.Line.DashStyle = MsoLineDashStyle.Solid
'Set the placement.
line1.Placement = PlacementType.FreeFloating
'Add another line to the worksheet.
Dim line2 As Aspose.Cells.Drawing.LineShape = worksheet.Shapes.AddLine(7, 0, 1, 0, 85, 250)
'Set the line dash style.
line2.Line.DashStyle = MsoLineDashStyle.DashLongDash
'Set the weight of the line.
line2.Line.Weight = 4
'Set the placement.
line2.Placement = PlacementType.FreeFloating
'Add the third line to the worksheet.
Dim line3 As Aspose.Cells.Drawing.LineShape = worksheet.Shapes.AddLine(13, 0, 1, 0, 0, 250)
'Set the line dash style
line3.Line.DashStyle = MsoLineDashStyle.Solid
'Set the placement.
line3.Placement = PlacementType.FreeFloating
'Make the gridlines invisible in the first worksheet.
workbook.Worksheets(0).IsGridlinesVisible = False
'Save the excel file.
workbook.Save("tstlines.xls")
[C#]
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;
cells[0,1].PutValue("Income");
cells[1,0].PutValue("Company A");
cells[2,0].PutValue("Company B");
cells[3,0].PutValue("Company C");
cells[1,1].PutValue(10000);
cells[2,1].PutValue(20000);
cells[3,1].PutValue(30000);
int chartIndex = sheet.Charts.Add(ChartType.Line, 9, 9, 21, 15);
Chart chart = sheet.Charts[chartIndex];
//Add series
chart.NSeries.Add("A2:B4", true);
//Set category data
chart.NSeries.CategoryData = "=Sheet1!$A$2:$A$4";
//Applying a dotted line style on the lines of an NSeries
chart.NSeries[0].Border.Style = LineType.Dot;
chart.NSeries[0].Border.Color = Color.Red;
//Applying a triangular marker style on the data markers of an NSeries
chart.NSeries[0].Marker.MarkerStyle = ChartMarkerType.Triangle;
//Setting the weight of all lines in an NSeries to medium
chart.NSeries[0].Border.Weight = WeightType.MediumLine;
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim sheet as Worksheet = workbook.Worksheets(0)
Dim cells as Cells = sheet.Cells
cells(0,1).PutValue("Income")
cells(1,0).PutValue("Company A")
cells(2,0).PutValue("Company B")
cells(3,0).PutValue("Company C")
cells(1,1).PutValue(10000)
cells(2,1).PutValue(20000)
cells(3,1).PutValue(30000)
Dim chartIndex as Integer = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15) ///
Dim chart as Chart = sheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A2" cell to "B4"
chart.NSeries.Add("A2:B4", True)
'Setting the data source for the category data of NSeries
Chart.NSeries.CategoryData = "A2:A4"
'Applying a dotted line style on the lines of an NSeries
chart.NSeries(0).Border.Style = LineType.Dot
chart.NSeries(0).Border.Color = Color.Red
'Applying a triangular marker style on the data markers of an NSeries
chart.NSeries(0).Marker.MarkerStyle = ChartMarkerType.Triangle
'Setting the weight of all lines in an NSeries to medium
chart.NSeries(0).Border.Weight = WeightType.MediumLine
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
ShapeCollection shapes = workbook.Worksheets[0].Shapes;
Shape shape = shapes.AddRectangle(1, 0, 1, 0, 50, 100);
LineFormat lineFmt = shape.Line;
//do your business
[C#]
int hashCode = lineFmt.GetHashCode();
[C#]
//You have to make sure that the index value in this line of code exists
LineFormat obj = workbook.Worksheets[0].Shapes[0].Line;
if (lineFmt.Equals(obj))
{
//do what you want
}
[C#]
lineFmt.CompoundType = MsoLineStyle.Single;
[C#]
lineFmt.DashStyle = MsoLineDashStyle.Solid;
[C#]
lineFmt.CapType = LineCapType.Flat;
[C#]
lineFmt.JoinType = LineJoinType.Round;
[C#]
lineFmt.BeginArrowheadStyle = MsoArrowheadStyle.ArrowOpen;
[C#]
lineFmt.BeginArrowheadWidth = MsoArrowheadWidth.Medium;
[C#]
lineFmt.BeginArrowheadLength = MsoArrowheadLength.Long;
[C#]
lineFmt.EndArrowheadStyle = MsoArrowheadStyle.ArrowOpen;
[C#]
lineFmt.EndArrowheadWidth = MsoArrowheadWidth.Medium;
[C#]
lineFmt.EndArrowheadLength = MsoArrowheadLength.Long;
[C#]
lineFmt.Weight = 2.0d;
[C#]
//Instantiate a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
//Define a string variable to store the image path.
string ImageUrl = "school.jpg";
//Get the picture into the streams.
FileStream fs = new FileStream(ImageUrl, FileMode.Open);
//Define a byte array.
byte[] imageData = new Byte[fs.Length];
//Obtain the picture into the array of bytes from streams.
fs.Read(imageData, 0, imageData.Length);
//Close the stream.
fs.Close();
//Get an excel file path in a variable.
string path = "Book1.xls";
//Get the file into the streams.
fs = new FileStream(path, FileMode.Open);
//Define an array of bytes.
byte[] objectData = new Byte[fs.Length];
//Store the file from streams.
fs.Read(objectData, 0, objectData.Length);
//Close the stream.
fs.Close();
//Add an Ole object into the worksheet with the image
//shown in MS Excel.
sheet.OleObjects.Add(14, 3, 200, 220, imageData);
//Set embedded ole object data.
sheet.OleObjects[0].ObjectData = objectData;
//Save the excel file
workbook.Save(@"oleobjects.xls");
[Visual Basic]
'Instantiate a new Workbook.
Dim workbook As Workbook = New Workbook()
'Get the first worksheet.
Dim sheet As Worksheet = workbook.Worksheets(0)
'Define a string variable to store the image path.
Dim ImageUrl As String = @"school.jpg"
'Get the picture into the streams.
Dim fs As FileStream = File.OpenRead(ImageUrl)
'Define a byte array.
Dim imageData(fs.Length) As Byte
'Obtain the picture into the array of bytes from streams.
fs.Read(imageData, 0, imageData.Length)
'Close the stream.
fs.Close()
'Get an excel file path in a variable.
Dim path As String = @"Book1.xls"
'Get the file into the streams.
fs = File.OpenRead(path)
'Define an array of bytes.
Dim objectData(fs.Length) As Byte
'Store the file from streams.
fs.Read(objectData, 0, objectData.Length)
'Close the stream.
fs.Close()
'Add an Ole object into the worksheet with the image
'shown in MS Excel.
sheet.OleObjects.Add(14, 3, 200, 220, imageData)
'Set embedded ole object data.
sheet.OleObjects(0).ObjectData = objectData
'Save the excel file
workbook.Save("oleobjects.xls")
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//get ShapeCollection
ShapeCollection shapes = workbook.Worksheets[0].Shapes;
//add a oval
Oval oval = shapes.AddOval(1, 0, 1, 0, 50, 50);
//do your business
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Workbook object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a picture at the location of a cell whose row and column indices
//are 5 in the worksheet. It is "F6" cell
worksheet.Pictures.Add(5, 5, "image.gif");
//Saving the Excel file
workbook.Save("book1.xls", SaveFormat.Excel97To2003);
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Workbook object
Dim sheetIndex As Integer = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a picture at the location of a cell whose row and column indices
'are 5 in the worksheet. It is "F6" cell
worksheet.Pictures.Add(5, 5, "image.gif")
'Saving the Excel file
workbook.Save("book1.xls", SaveFormat.Excel97To2003)
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//insert first picture
int imgIndex1 = worksheet.Pictures.Add(1, 1, "1.png");
//Get the inserted picture object
Picture pic1 = worksheet.Pictures[imgIndex1];
//insert second picture
int imgIndex2 = worksheet.Pictures.Add(1, 9, "2.jpeg");
//Get the inserted picture object
Picture pic2 = worksheet.Pictures[imgIndex2];
//Copy picture 1 to picture 2.You'll get two picture 1 objects that are superimposed on top of each other.
CopyOptions opt = new CopyOptions();
pic2.Copy(pic1, opt);
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Set the new location of the picture
pic.Move(2, 4);
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original height of the picture.
int picHeight = pic.OriginalHeight;
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original width of the picture.
int picWidth = pic.OriginalWidth;
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Set the border color of the picture
pic.BorderLineColor = Color.Red;
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Set the border color of the picture
pic.BorderLineColor = Color.Red;
//Set the border width of the picture
pic.BorderWeight = 3;
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//insert first picture
int imgIndex1 = worksheet.Pictures.Add(1, 1, "example1.png");
//Get the inserted picture object
Picture pic1 = worksheet.Pictures[imgIndex1];
//insert second picture
int imgIndex2 = worksheet.Pictures.Add(1, 9, "example2.jpeg");
//Get the inserted picture object
Picture pic2 = worksheet.Pictures[imgIndex2];
//Assign the byte data of the first image to the second image
pic2.Data = pic1.Data;
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//insert first picture
int imgIndex1 = worksheet.Pictures.Add(1, 1, "1.png");
//Get the inserted picture object
Picture pic1 = worksheet.Pictures[imgIndex1];
if(pic1.ImageType == Aspose.Cells.Drawing.ImageType.Png)
{
//The picture's type is png.";
}
//insert second picture
int imgIndex2 = worksheet.Pictures.Add(1, 9, "2.jpeg");
//Get the inserted picture object
Picture pic2 = worksheet.Pictures[imgIndex2];
if(pic2.ImageType == Aspose.Cells.Drawing.ImageType.Jpeg)
{
//The picture's type is jpg.";
}
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original height of the picture.
double picHeightCM = pic.OriginalHeightCM;
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original width of the picture.
double picWidthCM = pic.OriginalWidthCM;
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original height of the picture.
double picHeightInch = pic.OriginalHeightInch;
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, "example.jpeg");
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
//Gets the original width of the picture.
double picWidthInch = pic.OriginalWidthInch;
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding a picture at the location of a cell whose row and column indices are 1 in the worksheet. It is "B2" cell
int imgIndex = worksheet.Pictures.Add(1, 1, (string)null);
//Get the inserted picture object
Picture pic = worksheet.Pictures[imgIndex];
// Create signature line object
SignatureLine s = new SignatureLine();
s.Signer = "Simon";
s.Title = "Development";
s.Email = "simon@aspose.com";
// Assign the signature line object to Picture.
pic.SignatureLine = s;
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//insert first picture
int imgIndex1 = worksheet.Pictures.Add(1, 1, "1.png");
//Get the inserted picture object
Picture pic1 = worksheet.Pictures[imgIndex1];
//insert second picture
int imgIndex2 = worksheet.Pictures.Add(1, 9, "2.jpeg");
//Get the inserted picture object
Picture pic2 = worksheet.Pictures[imgIndex2];
if(pic1.IsSameSetting(pic1))
{
//two image objects are the same.
}
if(!pic1.IsSameSetting(pic2))
{
//two image objects are not the same.
}
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//get PictureCollection
PictureCollection pictures = workbook.Worksheets[0].Pictures;
//do your business
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//add a picture
using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
pictures.Add(1, 1, 5, 5, fs);
}
[C#]
//add a picture
pictures.Add(1, 1, 5, 5, "image.jpg");
[C#]
//add a picture
using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
pictures.Add(1, 1, fs);
}
[C#]
//add a picture
pictures.Add(1, 1, "image.jpg");
[C#]
//add a picture
using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
pictures.Add(1, 1, fs, 50, 50);
}
[C#]
//add a picture
pictures.Add(1, 1, "image.jpg", 50, 50);
[C#]
//get picture collection
//PictureCollection pictures = workbook.Worksheets[0].Pictures;
//add a picture
int index = pictures.Add(1, 1, "image.png");
//get the picture
Picture pic = pictures[index];
[C#]
//clear
pictures.Clear();
[C#]
//add a picture
int index2 = pictures.Add(1, 1, "image.png");
//delete
pictures.RemoveAt(index2);
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//get ShapeCollection
ShapeCollection shapes = workbook.Worksheets[0].Shapes;
//add a rectangle
RectangleShape rectangle = shapes.AddRectangle(2, 0, 2, 0, 130, 130);
//do your business
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//Initialize a new workbook.
Workbook book = new Workbook();
//Add a shape.(e.g rectangle)
Aspose.Cells.Drawing.Shape shape = book.Worksheets[0].Shapes.AddRectangle(2, 0, 2, 0, 130, 130);
//do your business
//Save the excel file.
book.Save("exmaple.xlsx");
[C#]
//Sets the name of macro.
shape.MacroName = "DoWork()";
[C#]
//If true,the shape only contains an equation.
if(shape.IsEquation)
{
//The shape contains only an equation
}
[C#]
//if true,the shape is a smart art.
if(shape.IsSmartArt)
{
//The shape is SmartArt object.
}
[C#]
if(shape.IsSmartArt)
{
Aspose.Cells.Drawing.GroupShape groupShape = shape.GetResultOfSmartArt();
}
[C#]
shape.ToFrontOrBack(2);
//or shape.ToFrontOrBack(-1);
[C#]
shape.ZOrderPosition = 3;
[C#]
shape.Name = "shape1";
[C#]
shape.AlternativeText = "a rectangle";
[C#]
shape.Title = "title1";
[C#]
Aspose.Cells.Drawing.LineFormat lineFmt = shape.Line;
[C#]
Aspose.Cells.Drawing.FillFormat fillFmt = shape.Fill;
[C#]
Aspose.Cells.Drawing.ShadowEffect shadowEffect = shape.ShadowEffect;
[C#]
Aspose.Cells.Drawing.ReflectionEffect reflectionEffect = shape.Reflection;
[C#]
Aspose.Cells.Drawing.GlowEffect glowEffect = shape.Glow;
[C#]
shape.SoftEdges = 0.5d;
[C#]
Aspose.Cells.Drawing.ThreeDFormat threeDFormat = shape.ThreeDFormat;
[C#]
Aspose.Cells.Drawing.MsoFormatPicture msoFormatPicture = shape.FormatPicture;
[C#]
shape.IsHidden = false;
[C#]
shape.IsLockAspectRatio = false;
[C#]
shape.IsAspectRatioLocked = false;
[C#]
int noAdjustHandles = 0;
if (shape.GetLockedProperty(ShapeLockType.AdjustHandles))
noAdjustHandles = 1;
[C#]
shape.SetLockedProperty(ShapeLockType.AdjustHandles, true);
[C#]
//Gets rotation angle of the shape.
double angle = shape.RotationAngle ;
//Gets rotation angle of the shape.
shape.RotationAngle = 60;
[C#]
Aspose.Cells.Hyperlink hyperlink = shape.AddHyperlink("https://www.aspose.com/");
[C#]
shape.RemoveHyperlink();
[C#]
Aspose.Cells.Hyperlink hyperlink = shape.Hyperlink;
[C#]
shape.MoveToRange(12, 3, 13, 5);
[C#]
shape.AlignTopRightCorner(2, 5);
[C#]
int id = shape.Id;
[C#]
string spid = shape.Spid;
[C#]
int spt = shape.Spt;
[C#]
Aspose.Cells.Worksheet worksheet = shape.Worksheet;
[C#]
if(shape.IsGroup)
{
//This shape is a group.
}
[C#]
if(shape.IsWordArt)
{
//This shape is a WordArt object.
}
[C#]
if(shape.IsWordArt)
{
Aspose.Cells.Drawing.TextEffectFormat textEffectFormat = shape.TextEffect;
}
[C#]
//Sets the specified shape to unlocked state
if (shape.Worksheet.IsProtected && shape.IsLocked)
{
shape.IsLocked = false;
}
//Sets the specified shape to a locked state
if (shape.Worksheet.IsProtected && !shape.IsLocked)
{
shape.IsLocked = true;
}
[C#]
if(shape.IsPrintable)
shape.IsPrintable = false;
[C#]
Aspose.Cells.Drawing.MsoDrawingType msoDrawingType = shape.MsoDrawingType;
[C#]
if (shape.AutoShapeType == Aspose.Cells.Drawing.AutoShapeType.Unknown)
shape.AutoShapeType = Aspose.Cells.Drawing.AutoShapeType.Rectangle;
[C#]
if (shape.AnchorType == ShapeAnchorType.OneCellAnchor)
shape.AnchorType = ShapeAnchorType.TwoCellAnchor;
[C#]
if (shape.Placement == PlacementType.Move)
shape.Placement = PlacementType.MoveAndSize;
[C#]
if (shape.UpperLeftRow == 3)
shape.UpperLeftRow = 1;
[C#]
if (shape.UpperDeltaY == 3)
shape.UpperDeltaY = 1;
[C#]
if (shape.UpperLeftColumn == 3)
shape.UpperLeftColumn = 1;
[C#]
if (shape.UpperDeltaX == 3)
shape.UpperDeltaX = 1;
[C#]
if (shape.LowerRightRow == 3)
shape.LowerRightRow = 1;
[C#]
if (shape.LowerDeltaY == 3)
shape.LowerDeltaY = 1;
[C#]
if (shape.LowerRightColumn == 3)
shape.LowerRightColumn = 1;
[C#]
if (shape.LowerDeltaX == 3)
shape.LowerDeltaX = 1;
[C#]
if (shape.Right == 3)
shape.Right = 1;
[C#]
if (shape.Bottom == 3)
shape.Bottom = 1;
[C#]
if (shape.Width == 3)
shape.Width = 1;
[C#]
if (shape.WidthInch == 3)
shape.WidthInch = 1;
[C#]
if (shape.WidthPt == 3)
shape.WidthPt = 1;
[C#]
if (shape.WidthCM == 3)
shape.WidthCM = 1;
[C#]
if (shape.Height == 3)
shape.Height = 1;
[C#]
if (shape.HeightInch == 3)
shape.HeightInch = 1;
[C#]
if (shape.HeightPt == 3)
shape.HeightPt = 1;
[C#]
if (shape.HeightCM == 3)
shape.HeightCM = 1;
[C#]
if (shape.Left == 3)
shape.Left = 1;
[C#]
if (shape.LeftInch == 3)
shape.LeftInch = 1;
[C#]
if (shape.LeftCM == 3)
shape.LeftCM = 1;
[C#]
if (shape.Top == 3)
shape.Top = 1;
[C#]
if (shape.TopInch == 3)
shape.TopInch = 1;
[C#]
if (shape.TopCM == 3)
shape.TopCM = 1;
[C#]
if (shape.TopToCorner == 3)
shape.TopToCorner = 1;
[C#]
if (shape.LeftToCorner == 3)
shape.LeftToCorner = 1;
[C#]
if (shape.X == 3)
shape.X = 1;
[C#]
if (shape.Y == 3)
shape.Y = 1;
[C#]
if (shape.WidthScale == 3)
shape.WidthScale = 1;
[C#]
if (shape.HeightScale == 3)
shape.HeightScale = 1;
[C#]
if (shape.IsInGroup && shape.TopInShape == 8000)
shape.TopInShape = 4000;
[C#]
if (shape.IsInGroup && shape.LeftInShape == 2000)
shape.LeftInShape = 4000;
[C#]
if (shape.IsInGroup && shape.WidthInShape == 2000)
shape.WidthInShape = 4000;
[C#]
if (shape.IsInGroup && shape.HeightInShape == 4000)
shape.HeightInShape = 2000;
[C#]
Aspose.Cells.Drawing.GroupShape groupShape = shape.Group;
[C#]
Aspose.Cells.Drawing.AutoShapeType autoShapeType = shape.Type;
[C#]
if(shape.HasLine == false)
shape.HasLine = true;
[C#]
if(shape.IsFilled == false)
shape.IsFilled = true;
[C#]
if(shape.IsFlippedHorizontally == false)
shape.IsFlippedHorizontally = true;
[C#]
if(shape.IsFlippedVertically == false)
shape.IsFlippedVertically = true;
[C#]
int rRow = shape.ActualLowerRightRow;
[C#]
float[][] points = shape.GetConnectionPoints();
The following formats are supported: .bmp, .gif, .jpg, .jpeg, .tiff, .emf.
[C#]
MemoryStream imageStream = new MemoryStream();
shape.ToImage(imageStream, ImageType.Png);
[C#]
ImageOrPrintOptions op = new ImageOrPrintOptions();
shape.ToImage("exmaple.png", op);
[C#]
MemoryStream imageStream = new MemoryStream();
ImageOrPrintOptions op = new ImageOrPrintOptions();
shape.ToImage(imageStream, op);
[C#]
if(shape.RelativeToOriginalPictureSize)
shape.RelativeToOriginalPictureSize = false;
[C#]
if (shape.LinkedCell.Equals("$B$6"))
shape.LinkedCell = "A1";
[C#]
if (shape.InputRange.Equals("$B$6:$B10"))
shape.InputRange = "$A$1:$A$5";
[C#]
//You may get results like '$A$1'
string link = shape.GetLinkedCell(false, false);
[C#]
//After executing the code below, a ScrollBar object is created in the generated file. As you drag the slider, the value is displayed in cell A12.
//ActiveX Controls
//Aspose.Cells.Drawing.Shape scrollBar = book.Worksheets[0].Shapes.AddActiveXControl( Aspose.Cells.Drawing.ActiveXControls.ControlType.ScrollBar,2, 0, 2, 0, 30, 130);
//Form Controls
Aspose.Cells.Drawing.Shape scrollBar = book.Worksheets[0].Shapes.AddScrollBar(2, 0, 2, 0, 130, 30);
//Sets the range linked to the control's value.
scrollBar.SetLinkedCell("$A$12", false, true);
[C#]
string range = shape.GetInputRange(false, true);
//If successful, a value like "$A$1:$A$3" will be returned
[C#]
//After executing the code below, a ListBox object is created in the generated file. When the selected option is clicked, the selected value is displayed in cell A12.
for (int i = 0; i< 10; ++i)
{
Cell cell = book.Worksheets[0].Cells[i, 0];
cell.Value = i + 1;
}
//Create a ListBox object
//ActiveX Controls
//Aspose.Cells.Drawing.Shape listBox = book.Worksheets[0].Shapes.AddActiveXControl( Aspose.Cells.Drawing.ActiveXControls.ControlType.ListBox,2, 0, 2, 0, 130, 130);
//Form Controls
Aspose.Cells.Drawing.Shape listBox = book.Worksheets[0].Shapes.AddListBox(2, 0, 2, 0, 130, 130);
//Sets the range used to fill the control.
listBox.SetInputRange("$A$1:$A$6", false, false);
//Sets the range linked to the control's value.
listBox.SetLinkedCell("$A$12", false, true);
[C#]
Cell cell = null;
for (int i = 0; i< 10; ++i)
{
cell = book.Worksheets[0].Cells[i, 0];
cell.Value = i + 1;
}
//Create a ListBox object
//ActiveX Controls
//Aspose.Cells.Drawing.Shape listBox = book.Worksheets[0].Shapes.AddActiveXControl( Aspose.Cells.Drawing.ActiveXControls.ControlType.ListBox,2, 0, 2, 0, 130, 130);
//Form Controls
Aspose.Cells.Drawing.Shape listBox = book.Worksheets[0].Shapes.AddListBox(2, 0, 2, 0, 130, 130);
//Sets the range used to fill the control.
listBox.SetInputRange("$A$1:$A$6", false, false);
//Sets the range linked to the control's value.
listBox.SetLinkedCell("$A$12", false, true);
ListBox listbx = (ListBox)listBox;
//Set the value of cell A12
cell = book.Worksheets[0].Cells[11, 0];
cell.Value = 3;
//Update the selected value by the value of the linked cell.
listBox.UpdateSelectedValue();
//-1 default, no option selected
if(listbx.IsSelected(2))
{
//Option 3 of the ListBox is selected
}
//Change the value of a linked cell
cell.Value = 4;
//Update the selected value by the value of the linked cell.
listBox.UpdateSelectedValue();
if(listbx.IsSelected(3))
{
//Option 4 of the ListBox is selected
}
[C#]
if (shape.TextShapeType == Aspose.Cells.Drawing.AutoShapeType.Unknown)
shape.TextShapeType = Aspose.Cells.Drawing.AutoShapeType.Rectangle;
[C#]
Aspose.Cells.Drawing.Texts.FontSettingCollection fontSettingCollection = shape.TextBody;
fontSettingCollection.Text = "This is a test.";
[C#]
Aspose.Cells.Font font = shape.Font;
font.Name = "Arial";
font.Size = 12;
font.Color = Color.Red;
[C#]
Aspose.Cells.Drawing.Texts.TextOptions opt = shape.TextOptions;
opt.Color = Color.Blue;
opt.Size = 8;
[C#]
//The size of the text area is:w=size[0],h=size[1]
int[] size = shape.CalculateTextSize();
[C#]
if(shape.Text == null)
shape.Text = "This is a test.";
[C#]
if(shape.IsRichText)
Console.WriteLine("The text is rich text.");
[C#]
string html = shape.HtmlText;
if(html == null || html == "")
{
shape.HtmlText = "<Font Style='FONT-FAMILY: Calibri;FONT-SIZE: 11pt;COLOR: #0000ff;TEXT-ALIGN: left;'>This is a <b>test</b>.</Font>";
}
[C#]
Aspose.Cells.FontSetting fontSetting = shape.Characters(0, 4);
[C#]
ArrayList list = shape.GetCharacters();
[C#]
FontSetting[] list = shape.GetRichFormattings();
[C#]
if (shape.TextVerticalOverflow == Aspose.Cells.Drawing.TextOverflowType.Clip)
shape.TextVerticalOverflow = Aspose.Cells.Drawing.TextOverflowType.Overflow;
[C#]
if (shape.TextHorizontalOverflow == Aspose.Cells.Drawing.TextOverflowType.Clip)
shape.TextHorizontalOverflow = Aspose.Cells.Drawing.TextOverflowType.Overflow;
[C#]
if (shape.IsTextWrapped)
shape.IsTextWrapped = !shape.IsTextWrapped;
[C#]
if (shape.TextOrientationType == Aspose.Cells.TextOrientationType.NoRotation)
shape.TextOrientationType = Aspose.Cells.TextOrientationType.TopToBottom;
[C#]
if (shape.TextHorizontalAlignment == Aspose.Cells.TextAlignmentType.Bottom)
shape.TextHorizontalAlignment = Aspose.Cells.TextAlignmentType.Center;
[C#]
if (shape.TextVerticalAlignment == Aspose.Cells.TextAlignmentType.Bottom)
shape.TextVerticalAlignment = Aspose.Cells.TextAlignmentType.Center;
[C#]
if (shape.TextDirection == Aspose.Cells.TextDirectionType.Context)
shape.TextDirection = Aspose.Cells.TextDirectionType.LeftToRight;
[C#]
if(shape.ControlData == null)
Console.WriteLine("No data.");
[C#]
if(shape.ActiveXControl != null)
{
CheckBoxActiveXControl checkBox1 = (CheckBoxActiveXControl)shape.ActiveXControl;
//The font name of CheckBox
string fontName = checkBox1.Font.Name;
}
[C#]
if(shape.ActiveXControl != null)
{
shape.RemoveActiveXControl();
}
[C#]
//Returns non-null if there is a path to the custom geometry
if(shape.Paths == null)
Console.WriteLine("No custom geometry path.");
[C#]
if (shape.Geometry != null && shape.Geometry.ShapeAdjustValues.Count == 0)
Console.WriteLine("No geometry path.");
[C#]
if (shape.IsSameSetting(shape))
Console.WriteLine("Two objects the same.");
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//get ShapeCollection
ShapeCollection shapes = workbook.Worksheets[0].Shapes;
//do your business
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
//get the first shape
Shape shape = shapes[0];
[C#]
//add a shape
shapes.AddRectangle(2, 0, 2, 0, 130, 130);
//get the shape by the name.
Shape shape1 = shapes["Rectangle 1"];
if(shape1 != null)
{
//Got the shape named 'Rectangle 1'.
}
[C#]
//add a shape
RectangleShape rectangle = shapes.AddRectangle(2, 0, 2, 0, 130, 130);
//Adds and copies a shape.
shapes.AddCopy(rectangle, 7, 0, 7, 0);
[C#]
//add a CheckBox
CheckBox checkBox = shapes.AddCheckBox(1, 0, 1, 0, 100, 50);
[C#]
//add a TextBox
TextBox textBox = shapes.AddTextBox(1, 0, 1, 0, 100, 50);
[C#]
//add a spinner
Spinner spinner = shapes.AddSpinner(1, 0, 1, 0, 100, 50);
[C#]
//add a scroll bar
ScrollBar scrollBar = shapes.AddScrollBar(1, 0, 1, 0, 100, 20);
[C#]
//add a radio button
RadioButton radioButton = shapes.AddRadioButton(1, 0, 1, 0, 100, 50);
[C#]
//add a list box
ListBox listBox = shapes.AddListBox(1, 0, 1, 0, 100, 50);
[C#]
//add a combo box
ComboBox comboBox = shapes.AddComboBox(1, 0, 1, 0, 100, 50);
[C#]
//add a group box
GroupBox groupBox = shapes.AddGroupBox(1, 0, 1, 0, 100, 50);
[C#]
//add a button
Button button = shapes.AddButton(1, 0, 1, 0, 100, 50);
[C#]
//add a label
Label label = shapes.AddLabel(1, 0, 1, 0, 100, 50);
[C#]
//add a WordArt
Shape wordArt1 = shapes.AddTextEffect(MsoPresetTextEffect.TextEffect10, "WordArt", "arial", 18, false, false, 3, 0, 3, 0, 200, 50);
[C#]
//add a WordArt
Shape wordArt2 = shapes.AddWordArt(PresetWordArtStyle.WordArtStyle1, "WordArt", 3, 0, 3, 0, 50, 200);
[C#]
// add a rectangle
RectangleShape rectangleShape = shapes.AddRectangle(2, 0, 2, 0, 130, 130);
[C#]
//add a oval
Oval oval = shapes.AddOval(1, 0, 1, 0, 50, 50);
[C#]
// add a line object
LineShape lineShape = shapes.AddLine(1, 0, 1, 0, 100, 50);
[C#]
//add a line
Shape floatingShape_Line = shapes.AddFreeFloatingShape(MsoDrawingType.Line, 100, 100, 100, 50, null, false);
//add a picture
byte[] imageData = null;
using(FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
int len = (int)fs.Length;
imageData = new byte[len];
fs.Read(imageData, 0, len);
}
Shape floatingShape_Picture = shapes.AddFreeFloatingShape(MsoDrawingType.Picture, 200, 100, 100, 50, imageData, false);
[C#]
//add a arc
ArcShape arcShape = shapes.AddArc(1, 0, 1, 0, 100, 50);
[C#]
//Add a shape of the specified type
Shape shapeByType = shapes.AddShape(MsoDrawingType.CellsDrawing, 1, 0, 1, 0, 100, 50);
[C#]
//Adds a AutoShape to the worksheet.
Shape autoShape = shapes.AddAutoShape(AutoShapeType.Cube, 1, 0, 1, 0, 100, 50);
[C#]
//add an ActiveX control
Shape activeXControl = shapes.AddActiveXControl(Aspose.Cells.Drawing.ActiveXControls.ControlType.CheckBox, 1, 0, 1, 0, 100, 50);
[C#]
//add a picture
using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
Picture picture = shapes.AddPicture(1, 0, 1, 0, fs);
}
[C#]
//add a picture
using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
Picture picture = shapes.AddPicture(1, 1, fs, 50, 60);
}
[C#]
// add a svg
using (FileStream fs = new FileStream("image.svg", FileMode.Open))
{
int len = (int)fs.Length;
byte[] imageData = new byte[len];
fs.Read(imageData, 0, len);
Picture picture = shapes.AddSvg(4, 0, 5, 0, -1, -1, imageData, null);
}
[C#]
//add icon
using (FileStream fs = new FileStream("icon.svg", FileMode.Open))
{
int len = (int)fs.Length;
byte[] imageData = new byte[len];
fs.Read(imageData, 0, len);
Picture picture = shapes.AddIcons(4, 0, 5, 0, -1, -1, imageData, null);
}
[C#]
using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
int len = (int)fs.Length;
byte[] imageData = new byte[len];
fs.Read(imageData, 0, len);
OleObject oleObject = shapes.AddOleObject(4, 0, 5, 0, 300, 500, imageData);
}
[C#]
CommentCollection comments = workbook.Worksheets[0].Comments;
//Add comment to cell A1
int commentIndex = comments.Add(0, 0);
Comment comment = comments[commentIndex];
comment.Note = "First note.";
comment.Font.Name = "Times New Roman";
//Add comment to cell B2
comments.Add("B2");
comment = comments["B2"];
comment.Note = "Second note.";
CellArea area1 = new CellArea();
area1.StartColumn = 1;
area1.StartRow = 1;
area1.EndColumn = 5;
area1.EndRow = 4;
//copy
shapes.CopyCommentsInRange(shapes, area1, 5, 1);
[C#]
//add a shape
shapes.AddRectangle(2, 0, 2, 0, 130, 130);
CellArea area2 = new CellArea();
area2.StartColumn = 1;
area2.StartRow = 1;
area2.EndColumn = 5;
area2.EndRow = 11;
//copy
shapes.CopyInRange(shapes, area2, 12, 1, false);
[C#]
//add first shape
shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
shapes.AddRectangle(6, 0, 2, 0, 30, 30);
CellArea area3 = new CellArea();
area3.StartColumn = 0;
area3.StartRow = 5;
area3.EndColumn = 5;
area3.EndRow = 8;
//del
shapes.DeleteInRange(area3);
[C#]
//add first shape
Shape firstShape = shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
Shape secondShape = shapes.AddRectangle(6, 0, 2, 0, 30, 30);
//del
shapes.DeleteShape(firstShape);
[C#]
//add first shape
shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
shapes.AddRectangle(6, 0, 2, 0, 30, 30);
Shape[] shapesArr = new Shape[] { shapes[0], shapes[1] };
GroupShape groupShape = shapes.Group(shapesArr);
[C#]
//add first shape
shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
shapes.AddRectangle(6, 0, 2, 0, 30, 30);
//group
Shape[] shapesArr = new Shape[] { shapes[0], shapes[1] };
GroupShape groupShape = shapes.Group(shapesArr);
//ungroup
shapes.Ungroup(groupShape);
[C#]
//add first shape
shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
shapes.AddRectangle(6, 0, 2, 0, 30, 30);
//remove
shapes.RemoveAt(0);
[C#]
//add first shape
shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
shapes.AddRectangle(6, 0, 2, 0, 30, 30);
//get the shape
Shape s = shapes["Rectangle 1"];// or shapes[0];
if (s != null)
{
//remove
shapes.Remove(s);
}
[C#]
if (shapes.Count > 0)
{
shapes.Clear();
}
[C#]
//Custom figure
ShapePath shapePath = new ShapePath();
shapePath.MoveTo(60, 45);
shapePath.ArcTo(25, 25, 0, 270);
shapePath.Close();
shapePath.MoveTo(60, 20);
shapePath.LineTo(110, 70);
shapePath.LineTo(125, 155.5f);
shapePath.ArcTo(35.5f, 35.5f, 0, 270);
shapePath.Close();
shapePath.MoveTo(150, 45);
shapePath.ArcTo(25, 25, 0, 270);
ShapePath shapePath1 = new ShapePath();
shapePath1.MoveTo(0, 0);
shapePath1.CubicBezierTo(48.24997f, 0.6844f,
96.5f, -7.148871f,
130, 11.517795f);
shapePath1.CubicBezierTo(163.5f, 30.18446f,
182.24997f, 75.351f,
201, 120.517795f);
shapePath1.MoveTo(150, 80);
shapePath1.ArcTo(25, 25, 0, 270);
//Insert custom figure into worksheet
shapes.AddFreeform(1, 0, 1, 0, 200, 200, new ShapePath[] { shapePath, shapePath1});
[C#]
SignatureLine wSignatureLine = new SignatureLine();
wSignatureLine.AllowComments = true;
wSignatureLine.Email = "example@example.com";
wSignatureLine.Instructions = "Sign to confirm the excel content.";
wSignatureLine.IsLine = true;
wSignatureLine.ShowSignedDate = true;
wSignatureLine.Signer = "User";
wSignatureLine.Title = "tester";
//wSignatureLine.SignatureLineType = SignatureType.Stamp;
Picture signatureLine1 = shapes.AddSignatureLine(0, 0, wSignatureLine);
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
// Create signature line object
SignatureLine s = new SignatureLine();
s.Signer = "Simon";
s.Title = "Development";
s.Email = "simon@aspose.com";
s.Instructions = "Sign to confirm the excel content.";
// Adds a Signature Line to the worksheet.
Picture signatureLine = worksheet.Shapes.AddSignatureLine(0, 0, s);
//do your business
//Save the excel file.
workbook.Save("result.xlsx");
[C#]
// Create signature line object
SignatureLine s1 = new SignatureLine();
s1.Id = System.Guid.NewGuid();
[C#]
// Create signature line object
SignatureLine s2 = new SignatureLine();
s2.ProviderId = new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");//The GUID should be obtained from the documentation shipped with the provider.
[C#]
// Create signature line object
SignatureLine s3 = new SignatureLine();
s3.Signer = "Mr xxx";
[C#]
// Create signature line object
SignatureLine s4 = new SignatureLine();
s4.Title = "Development Lead";
[C#]
// Create signature line object
SignatureLine s5 = new SignatureLine();
s5.Email = "Simon.Zhao@aspose.com";
[C#]
if(s.IsLine)
{
//Is line.
}
[C#]
if(s.AllowComments)
{
// Comments could be attached.
}
[C#]
if(s.ShowSignedDate)
{
//Show signed date.
}
[C#]
// Create signature line object
SignatureLine s6 = new SignatureLine();
s6.Instructions = "Just do it.";
[C#]
//Initialize a new workbook.
Workbook book = new Workbook("YourFile.xlsx");
//Gets a SmartArt shape.
Shape shape = null;
ShapeCollection shapes = book.Worksheets[0].Shapes;
foreach(Shape s in shapes)
{
if(s.MsoDrawingType == Aspose.Cells.Drawing.MsoDrawingType.SmartArt)
{
//is SmartArt Shape
//do what you want
break;
}
}
//do your business
//Save the excel file.
book.Save("exmaple.xlsx");
[C#]
Aspose.Cells.Drawing.GroupShape groupShape = shape.GetResultOfSmartArt();
if(groupShape != null)
{
//do what you want
}
[C#]
//Instantiate a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet in the book.
Worksheet worksheet = workbook.Worksheets[0];
//Add a new textbox to the collection.
int textboxIndex = worksheet.TextBoxes.Add(2, 1, 160, 200);
//Get the textbox object.
Aspose.Cells.Drawing.TextBox textbox0 = worksheet.TextBoxes[textboxIndex];
//Fill the text.
textbox0.Text = "ASPOSE______The .NET and JAVA Component Publisher!";
//Set the textbox to adjust it according to its contents.
textbox0.TextBody.TextAlignment.AutoSize = true;
//Set the placement.
textbox0.Placement = PlacementType.FreeFloating;
//Set the font color.
textbox0.Font.Color = Color.Blue;
//Set the font to bold.
textbox0.Font.IsBold = true;
//Set the font size.
textbox0.Font.Size = 14;
//Set font attribute to italic.
textbox0.Font.IsItalic = true;
//Add a hyperlink to the textbox.
textbox0.AddHyperlink("http://www.aspose.com/");
//Get the filformat of the textbox.
FillFormat fillformat = textbox0.Fill;
//Set the fillcolor.
fillformat.SolidFill.Color = Color.Silver;
//Get the lineformat type of the textbox.
LineFormat lineformat = textbox0.Line;
//Set the line style.
lineformat.CompoundType = MsoLineStyle.ThinThick;
//Set the line weight.
lineformat.Weight = 6;
//Set the dash style to squaredot.
lineformat.DashStyle = MsoLineDashStyle.SquareDot;
//Add another textbox.
textboxIndex = worksheet.TextBoxes.Add(15, 4, 85, 120);
//Get the second textbox.
Aspose.Cells.Drawing.TextBox textbox1 = worksheet.TextBoxes[textboxIndex];
//Input some text to it.
textbox1.Text = "This is another simple text box";
//Set the placement type as the textbox will move and
//resize with cells.
textbox1.Placement = PlacementType.MoveAndSize;
//Save the excel file.
workbook.Save("tsttextboxes.xlsx");
[Visual Basic]
'Instantiate a new Workbook.
Dim workbook As Workbook = New Workbook()
'Get the first worksheet in the book.
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Add a new textbox to the collection.
Dim textboxIndex As Integer = worksheet.TextBoxes.Add(2, 1, 160, 200)
'Get the textbox object.
Dim textbox0 As Aspose.Cells.Drawing.TextBox = worksheet.TextBoxes(textboxIndex)
'Fill the text.
textbox0.Text = "ASPOSE______The .NET and JAVA Component Publisher!"
'Set the textbox to adjust it according to its contents.
textbox0.TextBody.TextAlignment.AutoSize = True
'Set the placement.
textbox0.Placement = PlacementType.FreeFloating
'Set the font color.
textbox0.Font.Color = Color.Blue
'Set the font to bold.
textbox0.Font.IsBold = True
'Set the font size.
textbox0.Font.Size = 14
'Set font attribute to italic.
textbox0.Font.IsItalic = True
'Add a hyperlink to the textbox.
textbox0.AddHyperlink("http://www.aspose.com/")
'Get the filformat of the textbox.
Dim fillformat As FillFormat = textbox0.Fill
'Set the fillcolor.
fillformat.SolidFill.Color = Color.Silver
'Get the lineformat type of the textbox.
Dim lineformat As LineFormat = textbox0.Line
'Set the line style.
lineformat.CompoundType = MsoLineStyle.ThinThick
'Set the line weight.
lineformat.Weight = 6
'Set the dash style to squaredot.
lineformat.DashStyle = MsoLineDashStyle.SquareDot
'Add another textbox.
textboxIndex = worksheet.TextBoxes.Add(15, 4, 85, 120)
'Get the second textbox.
Dim textbox1 As Aspose.Cells.Drawing.TextBox = worksheet.TextBoxes(textboxIndex)
'Input some text to it.
textbox1.Text = "This is another simple text box"
'Set the placement type as the textbox will move and
'resize with cells.
textbox1.Placement = PlacementType.MoveAndSize
'Save the excel file.
workbook.Save("tsttextboxes.xlsx")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//get collection object
TextBoxCollection textBoxCollection = workbook.Worksheets[0].TextBoxes;
//add a textbox
textBoxCollection.Add(1, 1, 50, 100);
foreach(TextBox tbox in textBoxCollection)
{
//do what you want
}
//do your business
[C#]
int index = textBoxCollection.Count - 1;
TextBox txb = textBoxCollection[index];
[C#]
string txtboxName = "textbox 1";
TextBox txb2 = textBoxCollection[txtboxName];
if(txb2 != null)
{
//do what you want
}
[C#]
//add a TextBox
int index2 = textBoxCollection.Add(1, 1, 50, 100);
[C#]
int index3 = textBoxCollection.Count - 1;
textBoxCollection.RemoveAt(index3);
[C#]
//clear all textbox
textBoxCollection.Clear();
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Shape shape = workbook.Worksheets[0].Shapes.AddRectangle(1, 0, 1, 0, 50, 100);
Aspose.Cells.Drawing.Texts.ShapeTextAlignment shapeTextAlignment = shape.TextBody.TextAlignment;
//do your business
[C#]
shapeTextAlignment.IsTextWrapped = true;
[C#]
shapeTextAlignment.RotateTextWithShape = true;
[C#]
shapeTextAlignment.TextVerticalOverflow = TextOverflowType.Clip;
[C#]
shapeTextAlignment.TextHorizontalOverflow = TextOverflowType.Clip;
[C#]
shapeTextAlignment.RotationAngle = 90;
[C#]
shapeTextAlignment.TextVerticalType = Aspose.Cells.Drawing.Texts.TextVerticalType.Horizontal;
[C#]
shapeTextAlignment.AutoSize = false;
[C#]
//Usually do not modify this value unless you know exactly what the modification will result in
shapeTextAlignment.TextShapeType = AutoShapeType.TextBox;
[C#]
shapeTextAlignment.TopMarginPt = 2.0d;
[C#]
shapeTextAlignment.BottomMarginPt = 2.0d;
[C#]
shapeTextAlignment.LeftMarginPt = 2.0d;
[C#]
shapeTextAlignment.RightMarginPt = 2.0d;
[C#]
shapeTextAlignment.IsAutoMargin = true;
[C#]
//You have to make sure that the index value in this line of code exists
Aspose.Cells.Drawing.Texts.ShapeTextAlignment obj = workbook.Worksheets[0].Shapes[0].TextBody.TextAlignment;
if (shapeTextAlignment.Equals(obj))
{
//do what you want
}
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
int index = workbook.Worksheets[0].TextBoxes.Add(0, 0, 350, 350);
Shape shape = workbook.Worksheets[0].TextBoxes[index];
shape.Text = "This is test.";
//do your business
//Save the excel file.
workbook.Save("exmaple.xlsx");
[C#]
shape.TextBoxOptions.ShapeTextVerticalAlignment = ShapeTextVerticalAlignmentType.Left;
[C#]
shape.TextBoxOptions.ResizeToFitText = true;
[C#]
shape.TextBoxOptions.ShapeTextDirection = TextVerticalType.Vertical;
[C#]
shape.TextBoxOptions.LeftMarginPt = 0.2d;
[C#]
shape.TextBoxOptions.RightMarginPt = 0.2d;
[C#]
shape.TextBoxOptions.TopMarginPt = 0.2d;
[C#]
shape.TextBoxOptions.BottomMarginPt = 0.2d;
[C#]
shape.TextBoxOptions.AllowTextToOverflow = true;
[C#]
shape.TextBoxOptions.WrapTextInShape = true;
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Aspose.Cells.Drawing.ShapeCollection shapes = workbook.Worksheets[0].Shapes;
shapes.AddTextEffect(MsoPresetTextEffect.TextEffect1, "Aspose", "Arial", 30, false, false, 0, 0, 0, 0, 100, 200);
TextEffectFormat textEffectFormat = shapes[0].TextEffect;
textEffectFormat.SetTextEffect(MsoPresetTextEffect.TextEffect10);
workbook.Save("Book1.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
Dim shapes As Aspose.Cells.Drawing.ShapeCollection = workbook.Worksheets(0).Shapes
shapes.AddTextEffect(MsoPresetTextEffect.TextEffect1, "Aspose", "Arial", 30, false, false, 0, 0, 0, 0, 100, 200)
Dim textEffectFormat As TextEffectFormat = shapes(0).TextEffect
TextEffectFormat.SetTextEffect(MsoPresetTextEffect.TextEffect10)
workbook.Save("Book1.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(4);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(20);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 25, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
//Set the max value of value axis
chart.ValueAxis.MaxValue = 200;
//Set the min value of value axis
chart.ValueAxis.MinValue = 0;
//Set the major unit
chart.ValueAxis.MajorUnit = 25;
//Category(X) axis crosses at the maxinum value.
chart.ValueAxis.CrossType = CrossType.Maximum;
//Set he number of categories or series between tick-mark labels.
chart.CategoryAxis.TickLabelSpacing = 2;
//do your business
//Saving the Excel file
workbook.Save("book1.xlsx");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Excel object
Dim sheetIndex As Int32 = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(4)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(20)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a chart to the worksheet
Dim chartIndex As Int32 = worksheet.Charts.Add(ChartType.Column, 5, 0, 25, 5)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", True)
'Set the max value of value axis
chart.ValueAxis.MaxValue = 200
'Set the min value of value axis
chart.ValueAxis.MinValue = 0
'Set the major unit
chart.ValueAxis.MajorUnit = 25
'Category(X) axis crosses at the maxinum value.
chart.ValueAxis.CrossType = CrossType.Maximum
'Set he number of categories or series between tick-mark labels.
chart.CategoryAxis.TickLabelSpacing = 2
'Saving the Excel file
workbook.Save("book1.xlsx")
[C#]
chart.CategoryAxis.CategoryType = CategoryType.TimeScale;
chart.CategoryAxis.MajorUnitScale = TimeUnit.Months;
chart.CategoryAxis.MajorUnit = 2;
[Visual Basic]
chart.CategoryAxis.CategoryType = CategoryType.TimeScale
chart.CategoryAxis.MajorUnitScale = TimeUnit.Months
chart.CategoryAxis.MajorUnit = 2
[C#]
chart.CategoryAxis.CategoryType = CategoryType.TimeScale;
chart.CategoryAxis.MinorUnitScale = TimeUnit.Months;
chart.CategoryAxis.MinorUnit = 2;
[Visual Basic]
chart.CategoryAxis.CategoryType = CategoryType.TimeScale
chart.CategoryAxis.MinorUnitScale = TimeUnit.Months
chart.CategoryAxis.MinorUnit = 2
[C#]
chart.ValueAxis.MajorGridLines.IsVisible = false;
chart.CategoryAxis.MajorGridLines.IsVisible = true;
[Visual Basic]
chart.ValueAxis.MajorGridLines.IsVisible = false
chart.CategoryAxis.MajorGridLines.IsVisible = true
[C#]
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;
cells[0,1].PutValue("Income");
cells[1,0].PutValue("Company A");
cells[2,0].PutValue("Company B");
cells[3,0].PutValue("Company C");
cells[1,1].PutValue(10000);
cells[2,1].PutValue(20000);
cells[3,1].PutValue(30000);
int chartIndex = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15);
Chart chart = sheet.Charts[chartIndex];
chart.SetChartDataRange("A1:B4", true);
chart.ShowLegend = true;
chart.Title.Text = "Income Analysis";
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim sheet as Worksheet = workbook.Worksheets(0)
Dim cells as Cells = sheet.Cells
cells(0,1).PutValue("Income")
cells(1,0).PutValue("Company A")
cells(2,0).PutValue("Company B")
cells(3,0).PutValue("Company C")
cells(1,1).PutValue(10000)
cells(2,1).PutValue(20000)
cells(3,1).PutValue(30000)
Dim chartIndex as Integer = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15)
Dim chart as Chart = sheet.Charts(chartIndex)
chart.SetChartDataRange("A1:B4", True);
chart.ShowLegend = True
chart.Title.Text = "Income Analysis"
The format of the image is specified by using the extension of the file name. For example, if you specify "myfile.png", then the image will be saved in the PNG format. The following file extensions are recognized: .bmp, .gif, .png, .jpg, .jpeg, .tiff, .tif, .emf.
If the width or height is zero or the chart is not supported according to Supported Charts List, this method will do nothing.The type of the image is specified by using
The type of the image is specified by using
The format of the image is specified by using the extension of the file name. For example, if you specify "myfile.png", then the image will be saved in the PNG format. The following file extensions are recognized: .bmp, .gif, .png, .jpg, .jpeg, .tiff, .tif, .emf.
If the width or height is zero or the chart is not supported according to Supported Charts List, this method will do nothing. Please refer to Supported Charts List for more details.
[C#]
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.HorizontalResolution = 300;
options.VerticalResolution = 300;
options.TiffCompression = TiffCompression.CompressionCCITT4;
Workbook book = new Workbook(@"test.xls");
book.Worksheets[0].Charts[0].ToImage(@"chart.Tiff", options);
[VB]
Dim options As ImageOrPrintOptions = New ImageOrPrintOptions()
options.HorizontalResolution = 300
options.VerticalResolution = 300
options.TiffCompression = TiffCompression.CompressionCCITT4
Dim book As Workbook = New Workbook("test.xls")
book.Worksheets(0).Charts(0).ToImage("chart.Tiff", options)
Saves to Jpeg with 300 dpi and 80 image quality.
[C#]
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.HorizontalResolution = 300;
options.VerticalResolution = 300;
options.Quality = 80;
Workbook book = new Workbook(@"test.xls");
book.Worksheets[0].Charts[0].ToImage(@"chart.Jpeg", options);
[VB]
Dim options As ImageOrPrintOptions = New ImageOrPrintOptions()
options.HorizontalResolution = 300
options.VerticalResolution = 300
options.Quality = 80
Dim book As Workbook = New Workbook("test.xls")
book.Worksheets(0).Charts(0).ToImage("chart.Jpeg", options)
The type of the image is specified by using
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
//Getting Chart Area
ChartArea chartArea = chart.ChartArea;
//Setting the foreground color of the chart area
chartArea.Area.ForegroundColor = Color.Yellow;
//Setting Chart Area Shadow
chartArea.Shadow = true;
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a chart to the worksheet
Dim chartIndex As Integer = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", True)
'Getting Chart Area
Dim chartArea As ChartArea = chart.ChartArea
'Setting the foreground color of the chart area
chartArea.Area.ForegroundColor = Color.Yellow
'Setting Chart Area Shadow
chartArea.Shadow = True
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
Workbook workbook = new Workbook();
ChartCollection charts = workbook.Worksheets[0].Charts;
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim ChartCollection as Charts = workbook.Worksheets(0).Charts
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 25, 10);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
chart.ShowDataTable = true;
//Getting Chart Table
ChartDataTable chartTable = chart.ChartDataTable;
//Setting Chart Table Font Color
chartTable.Font.Color = System.Drawing.Color.Red;
//Setting Legend Key VisibilityOptions
chartTable.ShowLegendKey = false;
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a chart to the worksheet
Dim chartIndex As Integer = worksheet.Charts.Add(ChartType.Column, 5, 0, 25, 10)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", True)
chart.ShowDataTable = True
'Getting Chart Table
Dim chartTable As ChartDataTable = chart.ChartDataTable
'Setting Chart Table Font Color
chartTable.Font.Color = System.Drawing.Color.Red
'Setting Legend Key VisibilityOptions
chartTable.ShowLegendKey = False
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.PieExploded, 5, 0, 25, 10);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
//Show Data Labels
chart.NSeries[0].DataLabels.ShowValue = true;
for (int i = 0; i < chart.NSeries[0].Points.Count; i++)
{
//Get Data Point
ChartPoint point = chart.NSeries[0].Points[i];
//Set Pir Explosion
point.Explosion = 15;
//Set Border Color
point.Border.Color = System.Drawing.Color.Red;
}
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a chart to the worksheet
Dim chartIndex As Integer = worksheet.Charts.Add(ChartType.PieExploded, 5, 0, 25, 10)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", True)
'Show Data Labels
chart.NSeries(0).DataLabels.IsValueShown = True
For i As Integer = 0 To chart.NSeries(0).Points.Count - 1
'Get Data Point
Dim point As ChartPoint = chart.NSeries(0).Points(i)
'Set Pir Explosion
point.Explosion = 15
'Set Border Color
point.Border.Color = System.Drawing.Color.Red
Next i
'Saving the Excel file
workbook.Save("book1.xls")
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.PieExploded, 5, 0, 25, 10);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
//Show Data Labels
chart.NSeries[0].DataLabels.ShowValue = true;
ChartPointCollection points = chart.NSeries[0].Points;
for (int i = 0; i < points.Count; i++)
{
//Get Data Point
ChartPoint point = points[i];
//Set Pir Explosion
point.Explosion = 15;
//Set Border Color
point.Border.Color = System.Drawing.Color.Red;
}
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a chart to the worksheet
Dim chartIndex As Integer = worksheet.Charts.Add(ChartType.PieExploded, 5, 0, 25, 10)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", True)
'Show Data Labels
chart.NSeries(0).DataLabels.ShowValue = True
Dim points As ChartPointCollection = chart.NSeries(0).Points
For i As Integer = 0 To points.Count - 1
'Get Data Point
Dim point As ChartPoint = points(i)
'Set Pir Explosion
point.Explosion = 15
'Set Border Color
point.Border.Color = System.Drawing.Color.Red
Next i
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Set the DataLabels in the chart
Workbook wb = new Workbook("chart.xlsx");
Chart chart = wb.Worksheets[0].Charts[0];
DataLabels datalabels;
for (int i = 0; i <chart.NSeries.Count; i++)
{
datalabels = chart.NSeries[i].DataLabels;
//Set the position of DataLabels
datalabels.Position = LabelPositionType.InsideBase;
//Show the category name in the DataLabels
datalabels.ShowCategoryName = true;
//Show the value in the DataLabels
datalabels.ShowValue = true;
//Not show the percentage in the DataLabels
datalabels.ShowPercentage = false;
//Not show the legend key.
datalabels.ShowLegendKey = false;
}
[Visual Basic]
'Set the DataLabels in the chart
Dim datalabels As DataLabels
Dim i As Integer
For i = 0 To chart.NSeries.Count - 1 Step 1
datalabels = chart.NSeries(i).DataLabels
'Set the position of DataLabels
datalabels.Position = LabelPositionType.InsideBase
'Show the category name in the DataLabels
datalabels.ShowCategoryName= True
'Show the value in the DataLabels
datalabels.ShowValue = True
'Not show the percentage in the DataLabels
datalabels.ShowPercentage = False
'Not show the legend key.
datalabels.ShowLegendKey = False
Next
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "A4" cell
worksheet.Cells["A4"].PutValue(200);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a sample value to "B4" cell
worksheet.Cells["B4"].PutValue(40);
//Adding a sample value to "C1" cell as category data
worksheet.Cells["C1"].PutValue("Q1");
//Adding a sample value to "C2" cell as category data
worksheet.Cells["C2"].PutValue("Q2");
//Adding a sample value to "C3" cell as category data
worksheet.Cells["C3"].PutValue("Y1");
//Adding a sample value to "C4" cell as category data
worksheet.Cells["C4"].PutValue("Y2");
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.NSeries.Add("A1:B4", true);
//Setting the data source for the category data of NSeries
chart.NSeries.CategoryData = "C1:C4";
//Setting the display unit of value(Y) axis.
chart.ValueAxis.DisplayUnit = DisplayUnitType.Hundreds;
DisplayUnitLabel displayUnitLabel = chart.ValueAxis.DisplayUnitLabel;
//Setting the custom display unit label
displayUnitLabel.Text = "100";
//Saving the Excel file
workbook.Save("book1.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Excel object
Dim sheetIndex As Int32 = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "A4" cell
worksheet.Cells("A4").PutValue(200)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a sample value to "B4" cell
worksheet.Cells("B4").PutValue(40)
'Adding a sample value to "C1" cell as category data
worksheet.Cells("C1").PutValue("Q1")
'Adding a sample value to "C2" cell as category data
worksheet.Cells("C2").PutValue("Q2")
'Adding a sample value to "C3" cell as category data
worksheet.Cells("C3").PutValue("Y1")
'Adding a sample value to "C4" cell as category data
worksheet.Cells("C4").PutValue("Y2")
'Adding a chart to the worksheet
Dim chartIndex As Int32 = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.NSeries.Add("A1:B4", True)
'Setting the data source for the category data of NSeries
Chart.NSeries.CategoryData = "C1:C4"
'Setting the display unit of value(Y) axis.
chart.ValueAxis.DisplayUnit = DisplayUnitType.Hundreds
Dim displayUnitLabel As DisplayUnitLabel = chart.ValueAxis.DisplayUnitLabel
'Setting the custom display unit label
displayUnitLabel.Text = "100"
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
cells["a1"].PutValue(2);
cells["a2"].PutValue(5);
cells["a3"].PutValue(3);
cells["a4"].PutValue(6);
cells["b1"].PutValue(4);
cells["b2"].PutValue(3);
cells["b3"].PutValue(6);
cells["b4"].PutValue(7);
cells["C1"].PutValue("Q1");
cells["C2"].PutValue("Q2");
cells["C3"].PutValue("Y1");
cells["C4"].PutValue("Y2");
int chartIndex = workbook.Worksheets[0].Charts.Add(ChartType.Column, 11, 0, 27, 10);
Chart chart = workbook.Worksheets[0].Charts[chartIndex];
chart.NSeries.Add("A1:B4", true);
chart.NSeries.CategoryData = "C1:C4";
for(int i = 0; i < chart.NSeries.Count; i ++)
{
Series aseries = chart.NSeries[i];
aseries.YErrorBar.DisplayType = ErrorBarDisplayType.Minus;
aseries.YErrorBar.Type = ErrorBarType.FixedValue;
aseries.YErrorBar.Amount = 5;
}
[Visual Basic]
Dim workbook As Workbook = New Workbook()
Dim cells As Cells = workbook.Worksheets(0).Cells
cells("a1").PutValue(2)
cells("a2").PutValue(5)
cells("a3").PutValue(3)
cells("a4").PutValue(6)
cells("b1").PutValue(4)
cells("b2").PutValue(3)
cells("b3").PutValue(6)
cells("b4").PutValue(7)
cells("C1").PutValue("Q1")
cells("C2").PutValue("Q2")
cells("C3").PutValue("Y1")
cells("C4").PutValue("Y2")
Dim chartIndex As Integer = workbook.Worksheets(0).Charts.Add(ChartType.Column,11,0,27,10)
Dim chart As Chart = workbook.Worksheets(0).Charts(chartIndex)
chart.NSeries.Add("A1:B4", True)
chart.NSeries.CategoryData = "C1:C4"
Dim i As Integer
For i = 0 To chart.NSeries.Count - 1
Dim aseries As ASeries = chart.NSeries(i)
aseries.YErrorBar.DisplayType = ErrorBarDisplayType.Minus
aseries.YErrorBar.Type = ErrorBarType.FixedValue
aseries.YErrorBar.Amount = 5
Next
[C#]
Workbook wb = new Workbook("chart.xlsx");
Chart chart = wb.Worksheets[0].Charts[0];
Series aseries = chart.NSeries[0];
//Sets custom error bar type
aseries.YErrorBar.Type = ErrorBarType.Custom;
aseries.YErrorBar.PlusValue = "=Sheet1!A1";
aseries.YErrorBar.MinusValue = "=Sheet1!A2";
[Visual Basic]
'Sets custom error bar type
aseries.YErrorBar.Type = ErrorBarType.Custom
aseries.YErrorBar.PlusValue = "=Sheet1!A1"
aseries.YErrorBar.MinusValue = "=Sheet1!A2"
[C#]
//Instantiate the License class
Aspose.Cells.License license = new Aspose.Cells.License();
//Pass only the name of the license file embedded in the assembly
license.SetLicense("Aspose.Cells.lic");
//Instantiate the workbook object
Workbook workbook = new Workbook();
//Get cells collection
Cells cells = workbook.Worksheets[0].Cells;
//Put values in cells
cells["A1"].PutValue(1);
cells["A2"].PutValue(2);
cells["A3"].PutValue(3);
//get charts colletion
ChartCollection charts = workbook.Worksheets[0].Charts;
//add a new chart
int index = charts.Add(ChartType.Column3DStacked, 5, 0, 15, 5);
//get the newly added chart
Chart chart = charts[index];
//set charts nseries
chart.NSeries.Add("A1:A3", true);
//Show data labels
chart.NSeries[0].DataLabels.ShowValue = true;
//Get chart's floor
Floor floor = chart.Floor;
//set floor's border as red
floor.Border.Color = System.Drawing.Color.Red;
//set fill format
floor.FillFormat.SetPresetColorGradient(GradientPresetType.CalmWater, GradientStyleType.DiagonalDown, 2);
//save the file
workbook.Save(@"dest.xls");
[VB.NET]
'Instantiate the License class
Dim license As New Aspose.Cells.License()
'Pass only the name of the license file embedded in the assembly
license.SetLicense("Aspose.Cells.lic")
'Instantiate the workbook object
Dim workbook As Workbook = New Workbook()
'Get cells collection
Dim cells As Cells = workbook.Worksheets(0).Cells
'Put values in cells
cells("A1").PutValue(1)
cells("A2").PutValue(2)
cells("A3").PutValue(3)
'get charts colletion
Dim charts As ChartCollection = workbook.Worksheets(0).Charts
'add a new chart
Dim index As Integer = charts.Add(ChartType.Column3DStacked, 5, 0, 15, 5)
'get the newly added chart
Dim chart As Chart = charts(index)
'set charts nseries
chart.NSeries.Add("A1:A3", True)
'Show data labels
chart.NSeries(0).DataLabels.ShowValue = True
'Get chart's floor
Dim floor As Floor = chart.Floor
'set floor's border as red
floor.Border.Color = System.Drawing.Color.Red
'set fill format
floor.FillFormat.SetPresetColorGradient(GradientPresetType.CalmWater, GradientStyleType.DiagonalDown, 2)
'save the file
workbook.Save("dest.xls")
[C#]
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;
cells[0,1].PutValue("Income");
cells[1,0].PutValue("Company A");
cells[2,0].PutValue("Company B");
cells[3,0].PutValue("Company C");
cells[1,1].PutValue(10000);
cells[2,1].PutValue(20000);
cells[3,1].PutValue(30000);
int chartIndex = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15);
Chart chart = sheet.Charts[chartIndex];
chart.SetChartDataRange("A1:B4", true);
//Set Legend's width and height
Legend legend = chart.Legend;
//Legend is at right side of chart by default.
//If the legend is at left or right side of the chart, setting Legend.X property will not take effect.
//If the legend is at top or bottom side of the chart, setting Legend.Y property will not take effect.
legend.Y = 1500;
legend.Width = 50;
legend.Height = 50;
//Set legend's position
legend.Position = LegendPositionType.Left;
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim sheet as Worksheet = workbook.Worksheets(0)
Dim cells as Cells = sheet.Cells
cells(0,1).PutValue("Income")
cells(1,0).PutValue("Company A")
cells(2,0).PutValue("Company B")
cells(3,0).PutValue("Company C")
cells(1,1).PutValue(10000)
cells(2,1).PutValue(20000)
cells(3,1).PutValue(30000)
Dim chartIndex as Integer = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15)
Dim chart as Chart = sheet.Charts(chartIndex)
chart.SetChartDataRange("A1:B4", True);
'Set Legend's width and height
Dim legend as Legend = chart.Legend
'Legend is at right side of chart by default.
'If the legend is at left or right side of the chart, setting Legend.X property will not take effect.
'If the legend is at top or bottom side of the chart, setting Legend.Y property will not take effect.
legend.Y = 1500
legend.Width = 50
legend.Height = 50
'Set legend's position
legend.Position = LegendPositionType.Left
The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The X, Y, Width and Height of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The X, Y, Width and Height of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The X, Y, Width and Height of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The X, Y, Width and Height of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The X, Y, Width and Height of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The X, Y, Width and Height of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The X, Y, Width and Height of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The X, Y, Width and Height of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The XRatioToChart, YRatioToChart, WidthRatioToChart and HeightRatioToChart of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
XPixel = XRatioToChart * chart.ChartObject.Width.The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The XRatioToChart, YRatioToChart, WidthRatioToChart and HeightRatioToChart of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
YPixel = YRatioToChart * chart.ChartObject.Width.The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The XRatioToChart, YRatioToChart, WidthRatioToChart and HeightRatioToChart of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
HeightPixel = HeightRatioToChart * chart.ChartObject.Width.The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The XRatioToChart, YRatioToChart, WidthRatioToChart and HeightRatioToChart of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
WidthPixel = WidthRatioToChart * chart.ChartObject.Width.The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The XRatioToChart, YRatioToChart, WidthRatioToChart and HeightRatioToChart of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
InnerX in Pixel = InnerXRatioToChart * chart.ChartObject.Width.The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The XRatioToChart, YRatioToChart, WidthRatioToChart and HeightRatioToChart of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
InnerY in Pixel = InnerYRatioToChart * chart.ChartObject.Width.The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The XRatioToChart, YRatioToChart, WidthRatioToChart and HeightRatioToChart of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
InnerHeight in Pixel = InnerXRatioToChart * chart.ChartObject.Width.The plot-area bounding box includes the plot area, tick marks(tick labels), and a small border around the tick marks. If the value is not created by MS Excel, please call Chart.Calculate() method before calling this method.
The XRatioToChart, YRatioToChart, WidthRatioToChart and HeightRatioToChart of PlotArea represents the plot-area bounding box that includes the plot area, tick marks(tick labels), and a small border around the tick marks. If you want to get actual size of plot area, you should call InnerXRatioToChart, InnerYRatioToChart, InnerWidthRatioToChart and InnerHeightRatioToChart properties.
For excel 2007 or latter, the default value is zero. you should call get the value after calling Chart.Calculate().
InnerWidth in Pixel = InnerXRatioToChart * chart.ChartObject.Width.
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "A4" cell
worksheet.Cells["A4"].PutValue(200);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a sample value to "B4" cell
worksheet.Cells["B4"].PutValue(40);
//Adding a sample value to "C1" cell as category data
worksheet.Cells["C1"].PutValue("Q1");
//Adding a sample value to "C2" cell as category data
worksheet.Cells["C2"].PutValue("Q2");
//Adding a sample value to "C3" cell as category data
worksheet.Cells["C3"].PutValue("Y1");
//Adding a sample value to "C4" cell as category data
worksheet.Cells["C4"].PutValue("Y2");
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
int seriesIndex = chart.NSeries.Add("A1:B4", true);
//Setting the data source for the category data of NSeries
chart.NSeries.CategoryData = "C1:C4";
Series series = chart.NSeries[seriesIndex];
//Setting the values of the series.
series.Values = "=B1:B4";
//Changing the chart type of the series.
series.Type = ChartType.Line;
//Setting marker properties.
series.Marker.MarkerStyle = ChartMarkerType.Circle;
series.Marker.ForegroundColorSetType = FormattingType.Automatic;
series.Marker.ForegroundColor = System.Drawing.Color.Black;
series.Marker.BackgroundColorSetType = FormattingType.Automatic;
//do your business
//Saving the Excel file
workbook.Save("book1.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Excel object
Dim sheetIndex As Int32 = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "A4" cell
worksheet.Cells("A4").PutValue(200)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a sample value to "B4" cell
worksheet.Cells("B4").PutValue(40)
'Adding a sample value to "C1" cell as category data
worksheet.Cells("C1").PutValue("Q1")
'Adding a sample value to "C2" cell as category data
worksheet.Cells("C2").PutValue("Q2")
'Adding a sample value to "C3" cell as category data
worksheet.Cells("C3").PutValue("Y1")
'Adding a sample value to "C4" cell as category data
worksheet.Cells("C4").PutValue("Y2")
'Adding a chart to the worksheet
Dim chartIndex As Int32 = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
Dim seriesIndex As Int32 = chart.NSeries.Add("A1:B4", True)
'Setting the data source for the category data of NSeries
chart.NSeries.CategoryData = "C1:C4"
Dim series As Series = chart.NSeries(seriesIndex)
'Setting the values of the series.
series.Values = "=B1:B4"
'Changing the chart type of the series.
series.Type = ChartType.Line
'Setting marker properties.
series.Marker.MarkerStyle = ChartMarkerType.Circle
series.Marker.ForegroundColorSetType = FormattingType.Automatic
series.Marker.ForegroundColor = System.Drawing.Color.Black
series.Marker.BackgroundColorSetType = FormattingType.Automatic
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Reference name to a cell
chart.NSeries[0].Name = "=A1";
//Set a string to name
chart.NSeries[0].Name = "First Series";
[Visual Basic]
'Reference name to a cell
chart.NSeries[0].Name = "=A1"
'Set a string to name
chart.NSeries[0].Name = "First Series"
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "A4" cell
worksheet.Cells["A4"].PutValue(200);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a sample value to "B4" cell
worksheet.Cells["B4"].PutValue(40);
//Adding a sample value to "C1" cell as category data
worksheet.Cells["C1"].PutValue("Q1");
//Adding a sample value to "C2" cell as category data
worksheet.Cells["C2"].PutValue("Q2");
//Adding a sample value to "C3" cell as category data
worksheet.Cells["C3"].PutValue("Y1");
//Adding a sample value to "C4" cell as category data
worksheet.Cells["C4"].PutValue("Y2");
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.NSeries.Add("A1:B4", true);
//Setting the data source for the category data of NSeries
chart.NSeries.CategoryData = "C1:C4";
//Saving the Excel file
workbook.Save("book1.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Excel object
Dim sheetIndex As Integer = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "A4" cell
worksheet.Cells("A4").PutValue(200)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a sample value to "B4" cell
worksheet.Cells("B4").PutValue(40)
'Adding a sample value to "C1" cell as category data
worksheet.Cells("C1").PutValue("Q1")
'Adding a sample value to "C2" cell as category data
worksheet.Cells("C2").PutValue("Q2")
'Adding a sample value to "C3" cell as category data
worksheet.Cells("C3").PutValue("Y1")
'Adding a sample value to "C4" cell as category data
worksheet.Cells("C4").PutValue("Y2")
'Adding a chart to the worksheet
Dim chartIndex As Integer = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.NSeries.Add("A1:B4", True)
'Setting the data source for the category data of NSeries
chart.NSeries.CategoryData = "C1:C4"
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;
cells[0,1].PutValue("Income");
cells[1,0].PutValue("Company A");
cells[2,0].PutValue("Company B");
cells[3,0].PutValue("Company C");
cells[1,1].PutValue(10000);
cells[2,1].PutValue(20000);
cells[3,1].PutValue(30000);
int chartIndex = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15);
Chart chart = sheet.Charts[chartIndex];
//Setting the title of a chart
chart.Title.Text = "Title";
//Setting the font color of the chart title to blue
chart.Title.Font.Color = Color.Blue;
//Setting the title of category axis of the chart
chart.CategoryAxis.Title.Text = "Category";
//Setting the title of value axis of the chart
chart.ValueAxis.Title.Text = "Value";
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim sheet as Worksheet = workbook.Worksheets(0)
Dim cells as Cells = sheet.Cells
cells(0,1).PutValue("Income")
cells(1,0).PutValue("Company A")
cells(2,0).PutValue("Company B")
cells(3,0).PutValue("Company C")
cells(1,1).PutValue(10000)
cells(2,1).PutValue(20000)
cells(3,1).PutValue(30000)
Dim chartIndex as Integer = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15) ///
Dim chart as Chart = sheet.Charts(chartIndex)
'Setting the title of a chart
chart.Title.Text = "Title"
'Setting the font color of the chart title to blue
chart.Title.Font.Color = Color.Blue
'Setting the title of category axis of the chart
chart.CategoryAxis.Title.Text = "Category"
'Setting the title of value axis of the chart
chart.ValueAxis.Title.Text = "Value"
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "A4" cell
worksheet.Cells["A4"].PutValue(200);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(60);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(32);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
//Adding a sample value to "B4" cell
worksheet.Cells["B4"].PutValue(40);
//Adding a sample value to "C1" cell as category data
worksheet.Cells["C1"].PutValue("Q1");
//Adding a sample value to "C2" cell as category data
worksheet.Cells["C2"].PutValue("Q2");
//Adding a sample value to "C3" cell as category data
worksheet.Cells["C3"].PutValue("Y1");
//Adding a sample value to "C4" cell as category data
worksheet.Cells["C4"].PutValue("Y2");
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.Charts[chartIndex];
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.NSeries.Add("A1:B4", true);
//Setting the data source for the category data of NSeries
chart.NSeries.CategoryData = "C1:C4";
//adding a linear trendline
int index = chart.NSeries[0].TrendLines.Add(TrendlineType.Linear);
Trendline trendline = chart.NSeries[0].TrendLines[index];
//Setting the custom name of the trendline.
trendline.Name = "Linear";
//Displaying the equation on chart
trendline.DisplayEquation = true;
//Displaying the R-Squared value on chart
trendline.DisplayRSquared = true;
//Saving the Excel file
workbook.Save("book1.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Excel object
Dim sheetIndex As Int32 = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)
'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)
'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)
'Adding a sample value to "A4" cell
worksheet.Cells("A4").PutValue(200)
'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)
'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)
'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)
'Adding a sample value to "B4" cell
worksheet.Cells("B4").PutValue(40)
'Adding a sample value to "C1" cell as category data
worksheet.Cells("C1").PutValue("Q1")
'Adding a sample value to "C2" cell as category data
worksheet.Cells("C2").PutValue("Q2")
'Adding a sample value to "C3" cell as category data
worksheet.Cells("C3").PutValue("Y1")
'Adding a sample value to "C4" cell as category data
worksheet.Cells("C4").PutValue("Y2")
'Adding a chart to the worksheet
Dim chartIndex As Int32 = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5)
'Accessing the instance of the newly added chart
Dim chart As Chart = worksheet.Charts(chartIndex)
'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.NSeries.Add("A1:B4", True)
'Setting the data source for the category data of NSeries
Chart.NSeries.CategoryData = "C1:C4"
'adding a linear trendline
Dim index As Int32 = chart.NSeries(0).TrendLines.Add(TrendlineType.Linear)
Dim trendline As Trendline = chart.NSeries(0).TrendLines(index)
'Setting the custom name of the trendline.
trendline.Name = "Linear"
'Displaying the equation on chart
trendline.DisplayEquation = True
'Displaying the R-Squared value on chart
trendline.DisplayRSquared = True
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
worksheet.Cells["A1"].PutValue(50);
worksheet.Cells["A2"].PutValue(100);
worksheet.Cells["A3"].PutValue(150);
worksheet.Cells["A4"].PutValue(200);
worksheet.Cells["B1"].PutValue(60);
worksheet.Cells["B2"].PutValue(32);
worksheet.Cells["B3"].PutValue(50);
worksheet.Cells["B4"].PutValue(40);
//Adding a chart to the worksheet
int chartIndex = workbook.Worksheets[0].Charts.Add(ChartType.Column, 3, 3, 15, 10);
Chart chart = workbook.Worksheets[0].Charts[chartIndex];
chart.NSeries.Add("A1:a3", true);
chart.NSeries[0].TrendLines.Add(TrendlineType.Linear, "MyTrendLine");
Trendline line = chart.NSeries[0].TrendLines[0];
line.DisplayEquation = true;
line.DisplayRSquared = true;
line.Color = Color.Red;
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Excel object
Dim sheetIndex As Int32 = workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)
worksheet.Cells("A1").PutValue(50)
worksheet.Cells("A2").PutValue(100)
worksheet.Cells("A3").PutValue(150)
worksheet.Cells("A4").PutValue(200)
worksheet.Cells("B1").PutValue(60)
worksheet.Cells("B2").PutValue(32)
worksheet.Cells("B3").PutValue(50)
worksheet.Cells("B4").PutValue(40)
'Adding a chart to the worksheet
Dim chartIndex As Integer = workbook.Worksheets(0).Charts.Add(ChartType.Column,3,3,15,10)
Dim chart As Chart = workbook.Worksheets(0).Charts(chartIndex)
chart.NSeries.Add("A1:a3", True)
chart.NSeries(0).TrendLines.Add(TrendlineType.Linear, "MyTrendLine")
Dim line As Trendline = chart.NSeries(0).TrendLines(0)
line.DisplayEquation = True
line.DisplayRSquared = True
line.Color = Color.Red
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.Cells["A1"].PutValue(5);
sheet.Cells["B1"].PutValue(2);
sheet.Cells["C1"].PutValue(1);
sheet.Cells["D1"].PutValue(3);
// Define the CellArea
CellArea ca = new CellArea();
ca.StartColumn = 4;
ca.EndColumn = 4;
ca.StartRow = 0;
ca.EndRow = 0;
int idx = sheet.SparklineGroups.Add(Aspose.Cells.Charts.SparklineType.Line, sheet.Name + "!A1:D1", false, ca);
SparklineGroup group = sheet.SparklineGroups[idx];
idx = group.Sparklines.Add(sheet.Name + "!A1:D1", 0, 4);
Sparkline line = group.Sparklines[idx];
Console.WriteLine("Saprkline data range: " + line.DataRange + ", row: " + line.Row + ", column: " + line.Column);
line.ToImage("output.png", new ImageOrPrintOptions());
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.Cells["A1"].PutValue(5);
sheet.Cells["B1"].PutValue(2);
sheet.Cells["C1"].PutValue(1);
sheet.Cells["D1"].PutValue(3);
// Define the CellArea
CellArea ca = new CellArea();
ca.StartColumn = 4;
ca.EndColumn = 4;
ca.StartRow = 0;
ca.EndRow = 0;
int idx = sheet.SparklineGroups.Add(Aspose.Cells.Charts.SparklineType.Line, sheet.Name + "!A1:D1", false, ca);
SparklineGroup group = sheet.SparklineGroups[idx];
group.Sparklines.Add(sheet.Name + "!A1:D1", 0, 4);
book.Save("output.xlsx", SaveFormat.Xlsx);
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.Cells["A1"].PutValue(5);
sheet.Cells["B1"].PutValue(2);
sheet.Cells["C1"].PutValue(1);
sheet.Cells["D1"].PutValue(3);
// Define the CellArea
CellArea ca = new CellArea();
ca.StartColumn = 4;
ca.EndColumn = 4;
ca.StartRow = 0;
ca.EndRow = 0;
int idx = sheet.SparklineGroups.Add(Aspose.Cells.Charts.SparklineType.Line, "A1:D1", false, ca);
SparklineGroup group = sheet.SparklineGroups[idx];
group.Sparklines.Add(sheet.Name + "!A1:D1", 0, 4);
// Create CellsColor
CellsColor clr = book.CreateCellsColor();
clr.Color = Color.Orange;
group.SeriesColor = clr;
// set the high points are colored green and the low points are colored red
group.ShowHighPoint = true;
group.ShowLowPoint = true;
group.HighPointColor.Color = Color.Green;
group.LowPointColor.Color = Color.Red;
// set line weight
group.LineWeight = 1.0;
book.Save("output.xlsx", SaveFormat.Xlsx);
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.Cells["A1"].PutValue(5);
sheet.Cells["B1"].PutValue(2);
sheet.Cells["C1"].PutValue(1);
sheet.Cells["D1"].PutValue(3);
// Define the CellArea
CellArea ca = new CellArea();
ca.StartColumn = 4;
ca.EndColumn = 4;
ca.StartRow = 0;
ca.EndRow = 0;
int idx = sheet.SparklineGroups.Add(Aspose.Cells.Charts.SparklineType.Line, "A1:D1", false, ca);
SparklineGroup group = sheet.SparklineGroups[idx];
group.Sparklines.Add(sheet.Name + "!A1:D1", 0, 4);
book.Save("output.xlsx", SaveFormat.Xlsx);
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
Style style = workbook.CreateStyle();
//Setting the background color to Blue
style.BackgroundColor = Color.Blue;
//Setting the foreground color to Red
style.ForegroundColor= Color.Red;
//setting Background Pattern
style.Pattern = BackgroundType.DiagonalStripe;
//New Style Flag
StyleFlag styleFlag = new StyleFlag();
//Set All Styles
styleFlag.All = true;
//Get first Column
Column column = worksheet.Cells.Columns[0];
//Apply Style to first Column
column.ApplyStyle(style, styleFlag);
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
Dim style As Style = workbook.CreateStyle()
'Setting the background color to Blue
style.BackgroundColor = Color.Blue
'Setting the foreground color to Red
style.ForegroundColor = Color.Red
'setting Background Pattern
style.Pattern = BackgroundType.DiagonalStripe
'New Style Flag
Dim styleFlag As New StyleFlag()
'Set All Styles
styleFlag.All = True
'Get first Column
Dim column As Column = worksheet.Cells.Columns(0)
'Apply Style to first Column
column.ApplyStyle(style, styleFlag)
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Add new Style to Workbook
Style style = workbook.CreateStyle();
//Setting the background color to Blue
style.ForegroundColor = Color.Blue;
//setting Background Pattern
style.Pattern = BackgroundType.Solid;
//New Style Flag
StyleFlag styleFlag = new StyleFlag();
//Set All Styles
styleFlag.All = true;
//Change the default width of first ten columns
for (int i = 0; i < 10; i++)
{
worksheet.Cells.Columns[i].Width = 20;
}
//Get the Column with non default formatting
ColumnCollection columns = worksheet.Cells.Columns;
foreach (Column column in columns)
{
//Apply Style to first ten Columns
column.ApplyStyle(style, styleFlag);
}
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Add new Style to Workbook
Dim style As Style = workbook.CreateStyles()
'Setting the background color to Blue
style.ForegroundColor = Color.Blue
'setting Background Pattern
style.Pattern = BackgroundType.Solid
'New Style Flag
Dim styleFlag As New StyleFlag()
'Set All Styles
styleFlag.All = True
'Change the default width of first ten columns
For i As Integer = 0 To 9
worksheet.Cells.Columns(i).Width = 20
Next i
'Get the Column with non default formatting
Dim columns As ColumnCollection = worksheet.Cells.Columns
For Each column As Column In columns
'Apply Style to first ten Columns
column.ApplyStyle(style, styleFlag)
Next column
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Get Conditional Formatting
ConditionalFormattingCollection cformattings = sheet.ConditionalFormattings;
//Adds an empty conditional formatting
int index = cformattings.Add();
//Get newly added Conditional formatting
FormatConditionCollection fcs = cformattings[index];
//Sets the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 0;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);
ca = new CellArea();
ca.StartRow = 1;
ca.EndRow = 1;
ca.StartColumn = 1;
ca.EndColumn = 1;
fcs.AddArea(ca);
//Sets condition
int idx = fcs.AddCondition(FormatConditionType.IconSet);
FormatCondition cond = fcs[idx];
//Sets condition's type
cond.IconSet.Type = IconSetType.ArrowsGray3;
//Add custom iconset condition.
ConditionalFormattingIcon cfIcon = cond.IconSet.CfIcons[0];
cfIcon.Type = IconSetType.Arrows3;
cfIcon.Index = 0;
ConditionalFormattingIcon cfIcon1 = cond.IconSet.CfIcons[1];
cfIcon1.Type = IconSetType.ArrowsGray3;
cfIcon1.Index = 1;
ConditionalFormattingIcon cfIcon2 = cond.IconSet.CfIcons[2];
cfIcon2.Type = IconSetType.Boxes5;
cfIcon2.Index = 2;
//Saving the Excel file
workbook.Save("output.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)
'Get Conditional Formatting
Dim cformattings As ConditionalFormattingCollection = sheet.ConditionalFormattings
'Adds an empty conditional formatting
Dim index As Integer = cformattings.Add()
'Get newly added Conditional formatting
Dim fcs As FormatConditionCollection = cformattings(index)
'Sets the conditional format range.
Dim ca As New CellArea()
ca.StartRow = 0
ca.EndRow = 0
ca.StartColumn = 0
ca.EndColumn = 0
fcs.AddArea(ca)
ca = New CellArea()
ca.StartRow = 1
ca.EndRow = 1
ca.StartColumn = 1
ca.EndColumn = 1
fcs.AddArea(ca)
//Sets condition
Dim idx As Integer =fcs.AddCondition(FormatConditionType.IconSet)
Dim cond As FormatCondition=fcs[idx]
//Sets condition's type
cfIcon.Type = IconSetType.ArrowsGray3
'Add custom iconset condition.
Dim cfIcon As ConditionalFormattingIcon = cond.IconSet.CfIcons[0]
cfIcon.Type = IconSetType.Arrows3
cfIcon.Index=0
Dim cfIcon1 As ConditionalFormattingIcon = cond.IconSet.CfIcons[1]
cfIcon1.Type = IconSetType.ArrowsGray3
cfIcon1.Index=1
Dim cfIcon2 As ConditionalFormattingIcon = cond.IconSet.CfIcons[2]
cfIcon2.Type = IconSetType.Boxes5
cfIcon2.Index=2
'Saving the Excel file
workbook.Save("output.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Get Conditional Formatting
ConditionalFormattingCollection cformattings = sheet.ConditionalFormattings;
//Adds an empty conditional formatting
int index = cformattings.Add();
//Get newly added Conditional formatting
FormatConditionCollection fcs = cformattings[index];
//Sets the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 0;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);
ca = new CellArea();
ca.StartRow = 1;
ca.EndRow = 1;
ca.StartColumn = 1;
ca.EndColumn = 1;
fcs.AddArea(ca);
//Add condition.
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100");
//Add condition.
int conditionIndex2 = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");
//Sets the background color.
FormatCondition fc = fcs[conditionIndex];
fc.Style.BackgroundColor = Color.Red;
//Saving the Excel file
workbook.Save("output.xls");
[VB.NET]
'Instantiating a Workbook object
DDim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)
'Get Conditional Formatting
Dim cformattings As ConditionalFormattingCollection = sheet.ConditionalFormattings
'Adds an empty conditional formatting
Dim index As Integer = cformattings.Add()
'Get newly added Conditional formatting
Dim fcs As FormatConditionCollection = cformattings(index)
'Sets the conditional format range.
Dim ca As New CellArea()
ca.StartRow = 0
ca.EndRow = 0
ca.StartColumn = 0
ca.EndColumn = 0
fcs.AddArea(ca)
ca = New CellArea()
ca.StartRow = 1
ca.EndRow = 1
ca.StartColumn = 1
ca.EndColumn = 1
fcs.AddArea(ca)
'Add condition.
Dim conditionIndex As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100")
'Add condition.
Dim conditionIndex2 As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100")
'Sets the background color.
Dim fc As FormatCondition = fcs(conditionIndex)
fc.Style.BackgroundColor = Color.Red
'Saving the Excel file
workbook.Save("output.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Adds an empty conditional formatting
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];
//Sets the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 2;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);
//Adds condition.
int idx = fcs.AddCondition(FormatConditionType.DataBar);
fcs.AddArea(ca);
FormatCondition cond = fcs[idx];
//Get Databar
DataBar dataBar = cond.DataBar;
dataBar.Color = Color.Orange;
//Set Databar properties
dataBar.MinCfvo.Type = FormatConditionValueType.Percentile;
dataBar.MinCfvo.Value = 30;
dataBar.ShowValue = false;
dataBar.BarBorder.Type = DataBarBorderType.Solid;
dataBar.BarBorder.Color = Color.Plum;
dataBar.BarFillType = DataBarFillType.Solid;
dataBar.AxisColor = Color.Red;
dataBar.AxisPosition = DataBarAxisPosition.Midpoint;
dataBar.NegativeBarFormat.ColorType = DataBarNegativeColorType.Color;
dataBar.NegativeBarFormat.Color = Color.White;
dataBar.NegativeBarFormat.BorderColorType = DataBarNegativeColorType.Color;
dataBar.NegativeBarFormat.BorderColor = Color.Yellow;
//Put Cell Values
Aspose.Cells.Cell cell1 = sheet.Cells["A1"];
cell1.PutValue(10);
Aspose.Cells.Cell cell2 = sheet.Cells["A2"];
cell2.PutValue(120);
Aspose.Cells.Cell cell3 = sheet.Cells["A3"];
cell3.PutValue(260);
//Saving the Excel file
workbook.Save("book1.xlsx");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)
'Adds an empty conditional formatting
Dim index As Integer = sheet.ConditionalFormattings.Add()
Dim fcs As FormatConditionCollection = sheet.ConditionalFormattings(index)
'Sets the conditional format range.
Dim ca As New CellArea()
ca.StartRow = 0
ca.EndRow = 2
ca.StartColumn = 0
ca.EndColumn = 0
fcs.AddArea(ca)
'Adds condition.
Dim idx As Integer = fcs.AddCondition(FormatConditionType.DataBar)
fcs.AddArea(ca)
Dim cond As FormatCondition = fcs(idx)
'Get Databar
Dim dataBar As DataBar = cond.DataBar
dataBar.Color = Color.Orange
'Set Databar properties
dataBar.MinCfvo.Type = FormatConditionValueType.Percentile
dataBar.MinCfvo.Value = 30
dataBar.ShowValue = False
dataBar.BarBorder.Type = DataBarBorderType.Solid
dataBar.BarBorder.Color = Color.Plum
dataBar.BarFillType = DataBarFillType.Solid
dataBar.AxisColor = Color.Red
dataBar.AxisPosition = DataBarAxisPosition.Midpoint
dataBar.NegativeBarFormat.ColorType = DataBarNegativeColorType.Color
dataBar.NegativeBarFormat.Color = Color.White
dataBar.NegativeBarFormat.BorderColorType = DataBarNegativeColorType.Color
dataBar.NegativeBarFormat.BorderColor = Color.Yellow
'Put Cell Values
Dim cell1 As Aspose.Cells.Cell = sheet.Cells("A1")
cell1.PutValue(10)
Dim cell2 As Aspose.Cells.Cell = sheet.Cells("A2")
cell2.PutValue(120)
Dim cell3 As Aspose.Cells.Cell = sheet.Cells("A3")
cell3.PutValue(260)
'Saving the Excel file
workbook.Save("book1.xlsx")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Adds an empty conditional formatting
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];
//Sets the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 0;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);
ca = new CellArea();
ca.StartRow = 1;
ca.EndRow = 1;
ca.StartColumn = 1;
ca.EndColumn = 1;
fcs.AddArea(ca);
//Adds condition.
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100");
//Adds condition.
int conditionIndex2 = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");
//Sets the background color.
FormatCondition fc = fcs[conditionIndex];
fc.Style.BackgroundColor = Color.Red;
//Saving the Excel file
workbook.Save("output.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)
' Adds an empty conditional formatting
Dim index As Integer = sheet.ConditionalFormattings.Add()
Dim fcs As FormatConditionCollection = sheet.ConditionalFormattings(index)
'Sets the conditional format range.
Dim ca As CellArea = New CellArea()
ca.StartRow = 0
ca.EndRow = 0
ca.StartColumn = 0
ca.EndColumn = 0
fcs.AddArea(ca)
ca = New CellArea()
ca.StartRow = 1
ca.EndRow = 1
ca.StartColumn = 1
ca.EndColumn = 1
fcs.AddArea(ca)
'Adds condition.
Dim conditionIndex As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100")
'Adds condition.
Dim conditionIndex2 As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100")
'Sets the background color.
Dim fc As FormatCondition = fcs(conditionIndex)
fc.Style.BackgroundColor = Color.Red
'Saving the Excel file
workbook.Save("output.xls")
[C#]
//Create a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
//Adds an empty conditional formatting
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];
//Sets the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 0;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);
ca = new CellArea();
ca.StartRow = 1;
ca.EndRow = 1;
ca.StartColumn = 1;
ca.EndColumn = 1;
fcs.AddArea(ca);
//Adds condition.
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100");
//Adds condition.
int conditionIndex2 = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");
//Sets the background color.
FormatCondition fc = fcs[conditionIndex];
fc.Style.BackgroundColor = Color.Red;
//Saving the Excel file
workbook.Save("output.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)
' Adds an empty conditional formatting
Dim index As Integer = sheet.ConditionalFormattings.Add()
Dim fcs As FormatConditionCollection = sheet.ConditionalFormattings(index)
'Sets the conditional format range.
Dim ca As CellArea = New CellArea()
ca.StartRow = 0
ca.EndRow = 0
ca.StartColumn = 0
ca.EndColumn = 0
fcs.AddArea(ca)
ca = New CellArea()
ca.StartRow = 1
ca.EndRow = 1
ca.StartColumn = 1
ca.EndColumn = 1
fcs.AddArea(ca)
'Adds condition.
Dim conditionIndex As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100")
'Adds condition.
Dim conditionIndex2 As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100")
'Sets the background color.
Dim fc As FormatCondition = fcs(conditionIndex)
fc.Style.BackgroundColor = Color.Red
'Saving the Excel file
workbook.Save("output.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Adds an empty conditional formatting
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];
//Sets the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 2;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);
//Adds condition.
int idx = fcs.AddCondition(FormatConditionType.IconSet);
fcs.AddArea(ca);
FormatCondition cond = fcs[idx];
//Get Icon Set
IconSet iconSet = cond.IconSet;
//Set Icon Type
iconSet.Type = IconSetType.Arrows3;
//Put Cell Values
Aspose.Cells.Cell cell1 = sheet.Cells["A1"];
cell1.PutValue(10);
Aspose.Cells.Cell cell2 = sheet.Cells["A2"];
cell2.PutValue(120);
Aspose.Cells.Cell cell3 = sheet.Cells["A3"];
cell3.PutValue(260);
//Saving the Excel file
workbook.Save("book1.xlsx");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)
'Adds an empty conditional formatting
Dim index As Integer = sheet.ConditionalFormattings.Add()
Dim fcs As FormatConditionCollection = sheet.ConditionalFormattings(index)
'Sets the conditional format range.
Dim ca As New CellArea()
ca.StartRow = 0
ca.EndRow = 2
ca.StartColumn = 0
ca.EndColumn = 0
fcs.AddArea(ca)
'Adds condition.
Dim idx As Integer = fcs.AddCondition(FormatConditionType.IconSet)
fcs.AddArea(ca)
Dim cond As FormatCondition = fcs(idx)
'Get Icon Set
Dim iconSet As IconSet = cond.IconSet
'Set Icon Type
iconSet.Type = IconSetType.Arrows3
'Put Cell Values
Dim cell1 As Aspose.Cells.Cell = sheet.Cells("A1")
cell1.PutValue(10)
Dim cell2 As Aspose.Cells.Cell = sheet.Cells("A2")
cell2.PutValue(120)
Dim cell3 As Aspose.Cells.Cell = sheet.Cells("A3")
cell3.PutValue(260)
'Saving the Excel file
workbook.Save("book1.xlsx")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Adds an empty conditional formatting
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];
//Sets the conditional format range.
CellArea ca = CellArea.CreateCellArea(0, 0, 10, 10);
fcs.AddArea(ca);
//Adds condition.
int conditionIndex = fcs.AddCondition(FormatConditionType.Top10, OperatorType.None, null, null);
//Sets the background color.
FormatCondition fc = fcs[conditionIndex];
fc.Style.BackgroundColor = Color.Red;
Top10 top10 = fc.Top10;
//Set the Top N
top10.Rank = 5;
//Saving the Excel file
workbook.Save("output.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)
' Adds an empty conditional formatting
Dim index As Integer = sheet.ConditionalFormattings.Add()
Dim fcs As FormatConditionCollection = sheet.ConditionalFormattings(index)
'Sets the conditional format range.
Dim ca As CellArea = CellArea.CreateCellArea(0, 0, 10, 10)
fcs.AddArea(ca)
'Adds condition.
Dim conditionIndex As Integer = fcs.AddCondition(FormatConditionType.Top10, OperatorType.None, null, null);
'Sets the background color.
Dim fc As FormatCondition = fcs(conditionIndex)
fc.Style.BackgroundColor = Color.Red
Dim top10 as Top10 = fc.Top10
'Set the Top N
top10.Rank = 5
'Saving the Excel file
workbook.Save("output.xls")
[C#]
//custom implementation of IExportObjectListener
class CustomExportObjectListener : IExportObjectListener
{
private int imgIdx = 0;
public object ExportObject(ExportObjectEvent e)
{
Object source = e.GetSource();
if (source is Shape)
{
Shape shape = (Shape)source;
string url = null;
switch (shape.MsoDrawingType)
{
case MsoDrawingType.Picture:
{
url = SaveImage(((Picture)shape).Data, imgIdx, ((Picture)shape).ImageType);
break;
}
}
if (url != null)
{
imgIdx++;
}
return url;
}
return null;
}
private string SaveImage(byte[] data, int imgIdx, ImageType format)
{
//here save the image to any location, then return the url(relative or absolute) that the generated html can get the image
return "temp1/temp2.png";
}
}
//Save html file with custom listener
Workbook book = null; //build your workbook here
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.ExportObjectListener = new CustomExportObjectListener();
Stream stream = null; //build your stream here
book.Save("res.html", saveOptions); //or here you can build your out put stream and save the workbook to stream
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
cells[5, 0].Value = "grape";
cells[6, 0].Value = "blueberry";
cells[7, 0].Value = "kiwi";
cells[8, 0].Value = "cherry";
cells[0, 1].Value = "year";
cells[1, 1].Value = 2020;
cells[2, 1].Value = 2020;
cells[3, 1].Value = 2020;
cells[4, 1].Value = 2020;
cells[5, 1].Value = 2021;
cells[6, 1].Value = 2021;
cells[7, 1].Value = 2021;
cells[8, 1].Value = 2021;
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
cells[5, 2].Value = 90;
cells[6, 2].Value = 100;
cells[7, 2].Value = 110;
cells[8, 2].Value = 120;
PivotTableCollection pivots = sheet.PivotTables;
int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "year");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
//Add PivotFormatCondition
int formatIndex = pivot.ConditionalFormats.Add();
PivotConditionalFormat pfc = pivot.ConditionalFormats[formatIndex];
pfc.AddFieldArea(PivotFieldType.Data, pivot.DataFields[0]);
int idx = pfc.FormatConditions.AddCondition(FormatConditionType.CellValue);
FormatCondition fc = pfc.FormatConditions[idx];
fc.Formula1 = "100";
fc.Operator = OperatorType.GreaterOrEqual;
fc.Style.BackgroundColor = Color.Red;
pivot.RefreshData();
pivot.CalculateData();
//do your business
book.Save("out.xlsx");
[Visual Basic]
Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets(0)
Dim cells As Cells = sheet.Cells
cells(0, 0).Value = "fruit"
cells(1, 0).Value = "grape"
cells(2, 0).Value = "blueberry"
cells(3, 0).Value = "kiwi"
cells(4, 0).Value = "cherry"
cells(5, 0).Value = "grape"
cells(6, 0).Value = "blueberry"
cells(7, 0).Value = "kiwi"
cells(8, 0).Value = "cherry"
cells(0, 1).Value = "year"
cells(1, 1).Value = 2020
cells(2, 1).Value = 2020
cells(3, 1).Value = 2020
cells(4, 1).Value = 2020
cells(5, 1).Value = 2021
cells(6, 1).Value = 2021
cells(7, 1).Value = 2021
cells(8, 1).Value = 2021
cells(0, 2).Value = "amount"
cells(1, 2).Value = 50
cells(2, 2).Value = 60
cells(3, 2).Value = 70
cells(4, 2).Value = 80
cells(5, 2).Value = 90
cells(6, 2).Value = 100
cells(7, 2).Value = 110
cells(8, 2).Value = 120
Dim pivots As PivotTableCollection = sheet.PivotTables
Dim pivotIndex As Int32 = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable")
Dim pivot As PivotTable = pivots(pivotIndex)
pivot.AddFieldToArea(PivotFieldType.Row, "fruit")
Pivot.AddFieldToArea(PivotFieldType.Column, "year")
Pivot.AddFieldToArea(PivotFieldType.Data, "amount")
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10
'Add PivotFormatCondition
Dim formatIndex As Int32 = pivot.ConditionalFormats.Add()
Dim pfc As PivotConditionalFormat = pivot.ConditionalFormats(formatIndex)
pfc.AddFieldArea(PivotFieldType.Data, pivot.DataFields(0))
Dim idx As Int32 = pfc.FormatConditions.AddCondition(FormatConditionType.CellValue)
Dim fc As FormatCondition = pfc.FormatConditions(idx)
fc.Formula1 = "100"
fc.Operator = OperatorType.GreaterOrEqual
fc.Style.BackgroundColor = Color.Red
pivot.RefreshData()
pivot.CalculateData()
book.Save("out_vb.xlsx")
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
cells[5, 0].Value = "grape";
cells[6, 0].Value = "blueberry";
cells[7, 0].Value = "kiwi";
cells[8, 0].Value = "cherry";
cells[0, 1].Value = "year";
cells[1, 1].Value = 2020;
cells[2, 1].Value = 2020;
cells[3, 1].Value = 2020;
cells[4, 1].Value = 2020;
cells[5, 1].Value = 2021;
cells[6, 1].Value = 2021;
cells[7, 1].Value = 2021;
cells[8, 1].Value = 2021;
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
cells[5, 2].Value = 90;
cells[6, 2].Value = 100;
cells[7, 2].Value = 110;
cells[8, 2].Value = 120;
PivotTableCollection pivots = sheet.PivotTables;
int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "year");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
//Add PivotFormatCondition
int formatIndex = pivot.PivotFormatConditions.Add();
PivotFormatCondition pfc = pivot.PivotFormatConditions[formatIndex];
pfc.AddDataAreaCondition(pivot.DataFields[0]);
FormatConditionCollection fcc = pfc.FormatConditions;
fcc.AddArea(pivot.DataBodyRange);
int idx = fcc.AddCondition(FormatConditionType.CellValue);
FormatCondition fc = fcc[idx];
fc.Formula1 = "100";
fc.Operator = OperatorType.GreaterOrEqual;
fc.Style.BackgroundColor = Color.Red;
pivot.RefreshData();
pivot.CalculateData();
//do your business
book.Save("out.xlsx");
[Visual Basic]
Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets(0)
Dim cells As Cells = sheet.Cells
cells(0, 0).Value = "fruit"
cells(1, 0).Value = "grape"
cells(2, 0).Value = "blueberry"
cells(3, 0).Value = "kiwi"
cells(4, 0).Value = "cherry"
cells(5, 0).Value = "grape"
cells(6, 0).Value = "blueberry"
cells(7, 0).Value = "kiwi"
cells(8, 0).Value = "cherry"
cells(0, 1).Value = "year"
cells(1, 1).Value = 2020
cells(2, 1).Value = 2020
cells(3, 1).Value = 2020
cells(4, 1).Value = 2020
cells(5, 1).Value = 2021
cells(6, 1).Value = 2021
cells(7, 1).Value = 2021
cells(8, 1).Value = 2021
cells(0, 2).Value = "amount"
cells(1, 2).Value = 50
cells(2, 2).Value = 60
cells(3, 2).Value = 70
cells(4, 2).Value = 80
cells(5, 2).Value = 90
cells(6, 2).Value = 100
cells(7, 2).Value = 110
cells(8, 2).Value = 120
Dim pivots As PivotTableCollection = sheet.PivotTables
Dim pivotIndex As Int32 = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable")
Dim pivot As PivotTable = pivots(pivotIndex)
pivot.AddFieldToArea(PivotFieldType.Row, "fruit")
Pivot.AddFieldToArea(PivotFieldType.Column, "year")
Pivot.AddFieldToArea(PivotFieldType.Data, "amount")
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10
'Add PivotFormatCondition
Dim formatIndex As Int32 = pivot.PivotFormatConditions.Add()
Dim pfc As PivotFormatCondition = pivot.PivotFormatConditions(formatIndex)
pfc.AddDataAreaCondition(pivot.DataFields(0))
Dim fcc As FormatConditionCollection = pfc.FormatConditions
fcc.AddArea(pivot.DataBodyRange)
Dim idx As Int32 = fcc.AddCondition(FormatConditionType.CellValue)
Dim fc As FormatCondition = fcc(idx)
fc.Formula1 = "100"
fc.Operator = OperatorType.GreaterOrEqual
fc.Style.BackgroundColor = Color.Red
pivot.RefreshData()
pivot.CalculateData()
book.Save("out_vb.xlsx")
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
cells[5, 0].Value = "grape";
cells[6, 0].Value = "blueberry";
cells[7, 0].Value = "kiwi";
cells[8, 0].Value = "cherry";
cells[0, 1].Value = "year";
cells[1, 1].Value = 2020;
cells[2, 1].Value = 2020;
cells[3, 1].Value = 2020;
cells[4, 1].Value = 2020;
cells[5, 1].Value = 2021;
cells[6, 1].Value = 2021;
cells[7, 1].Value = 2021;
cells[8, 1].Value = 2021;
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
cells[5, 2].Value = 90;
cells[6, 2].Value = 100;
cells[7, 2].Value = 110;
cells[8, 2].Value = 120;
PivotTableCollection pivots = sheet.PivotTables;
int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "year");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
//Change PivotField's attributes
PivotField rowField = pivot.RowFields[0];
rowField.DisplayName = "custom display name";
pivot.RefreshData();
pivot.CalculateData();
//do your business
book.Save("out.xlsx");
[Visual Basic]
Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets(0)
Dim cells As Cells = sheet.Cells
cells(0, 0).Value = "fruit"
cells(1, 0).Value = "grape"
cells(2, 0).Value = "blueberry"
cells(3, 0).Value = "kiwi"
cells(4, 0).Value = "cherry"
cells(5, 0).Value = "grape"
cells(6, 0).Value = "blueberry"
cells(7, 0).Value = "kiwi"
cells(8, 0).Value = "cherry"
cells(0, 1).Value = "year"
cells(1, 1).Value = 2020
cells(2, 1).Value = 2020
cells(3, 1).Value = 2020
cells(4, 1).Value = 2020
cells(5, 1).Value = 2021
cells(6, 1).Value = 2021
cells(7, 1).Value = 2021
cells(8, 1).Value = 2021
cells(0, 2).Value = "amount"
cells(1, 2).Value = 50
cells(2, 2).Value = 60
cells(3, 2).Value = 70
cells(4, 2).Value = 80
cells(5, 2).Value = 90
cells(6, 2).Value = 100
cells(7, 2).Value = 110
cells(8, 2).Value = 120
Dim pivots As PivotTableCollection = sheet.PivotTables
Dim pivotIndex As Int32 = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable")
Dim pivot As PivotTable = pivots(pivotIndex)
pivot.AddFieldToArea(PivotFieldType.Row, "fruit")
Pivot.AddFieldToArea(PivotFieldType.Column, "year")
Pivot.AddFieldToArea(PivotFieldType.Data, "amount")
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10
'Change PivotField's attributes
Dim rowField As PivotField = pivot.RowFields(0)
rowField.DisplayName = "custom display name"
pivot.RefreshData()
pivot.CalculateData()
book.Save("out_vb.xlsx")
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
cells[5, 0].Value = "grape";
cells[6, 0].Value = "blueberry";
cells[7, 0].Value = "kiwi";
cells[8, 0].Value = "cherry";
cells[0, 1].Value = "year";
cells[1, 1].Value = 2020;
cells[2, 1].Value = 2020;
cells[3, 1].Value = 2020;
cells[4, 1].Value = 2020;
cells[5, 1].Value = 2021;
cells[6, 1].Value = 2021;
cells[7, 1].Value = 2021;
cells[8, 1].Value = 2021;
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
cells[5, 2].Value = 90;
cells[6, 2].Value = 100;
cells[7, 2].Value = 110;
cells[8, 2].Value = 120;
PivotTableCollection pivots = sheet.PivotTables;
int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "year");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
//Add top 10 filter
pivot.BaseFields[0].FilterTop10(0, PivotFilterType.Count,false,2);
pivot.RefreshData();
pivot.CalculateData();
//do your business
book.Save("out.xlsx");
[Visual Basic]
Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets(0)
Dim cells As Cells = sheet.Cells
cells(0, 0).Value = "fruit"
cells(1, 0).Value = "grape"
cells(2, 0).Value = "blueberry"
cells(3, 0).Value = "kiwi"
cells(4, 0).Value = "cherry"
cells(5, 0).Value = "grape"
cells(6, 0).Value = "blueberry"
cells(7, 0).Value = "kiwi"
cells(8, 0).Value = "cherry"
cells(0, 1).Value = "year"
cells(1, 1).Value = 2020
cells(2, 1).Value = 2020
cells(3, 1).Value = 2020
cells(4, 1).Value = 2020
cells(5, 1).Value = 2021
cells(6, 1).Value = 2021
cells(7, 1).Value = 2021
cells(8, 1).Value = 2021
cells(0, 2).Value = "amount"
cells(1, 2).Value = 50
cells(2, 2).Value = 60
cells(3, 2).Value = 70
cells(4, 2).Value = 80
cells(5, 2).Value = 90
cells(6, 2).Value = 100
cells(7, 2).Value = 110
cells(8, 2).Value = 120
Dim pivots As PivotTableCollection = sheet.PivotTables
Dim pivotIndex As Int32 = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable")
Dim pivot As PivotTable = pivots(pivotIndex)
pivot.AddFieldToArea(PivotFieldType.Row, "fruit")
Pivot.AddFieldToArea(PivotFieldType.Column, "year")
Pivot.AddFieldToArea(PivotFieldType.Data, "amount")
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10
'Add PivotFilter
pivot.BaseFields(0).Filter.FilterTop10(0, PivotFilterType.Count,false,2)
pivot.RefreshData()
pivot.CalculateData()
book.Save("out_vb.xlsx")
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
cells[5, 0].Value = "grape";
cells[6, 0].Value = "blueberry";
cells[7, 0].Value = "kiwi";
cells[8, 0].Value = "cherry";
cells[0, 1].Value = "year";
cells[1, 1].Value = 2020;
cells[2, 1].Value = 2020;
cells[3, 1].Value = 2020;
cells[4, 1].Value = 2020;
cells[5, 1].Value = 2021;
cells[6, 1].Value = 2021;
cells[7, 1].Value = 2021;
cells[8, 1].Value = 2021;
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
cells[5, 2].Value = 90;
cells[6, 2].Value = 100;
cells[7, 2].Value = 110;
cells[8, 2].Value = 120;
PivotTableCollection pivots = sheet.PivotTables;
int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "year");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
//Change PivotField's attributes
PivotField rowField = pivot.RowFields[0];
rowField.DisplayName = "custom display name";
//Add PivotFilter
int index = pivot.PivotFilters.Add(0, PivotFilterType.Count);
PivotFilter filter = pivot.PivotFilters[index];
filter.AutoFilter.FilterTop10(0, false, false, 2);
//Add PivotFormatCondition
int formatIndex = pivot.PivotFormatConditions.Add();
PivotFormatCondition pfc = pivot.PivotFormatConditions[formatIndex];
FormatConditionCollection fcc = pfc.FormatConditions;
fcc.AddArea(pivot.DataBodyRange);
int idx = fcc.AddCondition(FormatConditionType.CellValue);
FormatCondition fc = fcc[idx];
fc.Formula1 = "100";
fc.Operator = OperatorType.GreaterOrEqual;
fc.Style.BackgroundColor = Color.Red;
pivot.RefreshData();
pivot.CalculateData();
//do your business
book.Save("out.xlsx");
[Visual Basic]
Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets(0)
Dim cells As Cells = sheet.Cells
cells(0, 0).Value = "fruit"
cells(1, 0).Value = "grape"
cells(2, 0).Value = "blueberry"
cells(3, 0).Value = "kiwi"
cells(4, 0).Value = "cherry"
cells(5, 0).Value = "grape"
cells(6, 0).Value = "blueberry"
cells(7, 0).Value = "kiwi"
cells(8, 0).Value = "cherry"
cells(0, 1).Value = "year"
cells(1, 1).Value = 2020
cells(2, 1).Value = 2020
cells(3, 1).Value = 2020
cells(4, 1).Value = 2020
cells(5, 1).Value = 2021
cells(6, 1).Value = 2021
cells(7, 1).Value = 2021
cells(8, 1).Value = 2021
cells(0, 2).Value = "amount"
cells(1, 2).Value = 50
cells(2, 2).Value = 60
cells(3, 2).Value = 70
cells(4, 2).Value = 80
cells(5, 2).Value = 90
cells(6, 2).Value = 100
cells(7, 2).Value = 110
cells(8, 2).Value = 120
Dim pivots As PivotTableCollection = sheet.PivotTables
Dim pivotIndex As Int32 = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable")
Dim pivot As PivotTable = pivots(pivotIndex)
pivot.AddFieldToArea(PivotFieldType.Row, "fruit")
Pivot.AddFieldToArea(PivotFieldType.Column, "year")
Pivot.AddFieldToArea(PivotFieldType.Data, "amount")
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10
'Change PivotField's attributes
Dim rowField As PivotField = pivot.RowFields(0)
rowField.DisplayName = "custom display name"
'Add PivotFilter
Dim filterIndex As Int32 = pivot.PivotFilters.Add(0, PivotFilterType.Count)
Dim filter As PivotFilter = pivot.PivotFilters(filterIndex)
filter.AutoFilter.FilterTop10(0, False, False, 2)
'Add PivotFormatCondition
Dim formatIndex As Int32 = pivot.PivotFormatConditions.Add()
Dim pfc As PivotFormatCondition = pivot.PivotFormatConditions(formatIndex)
Dim fcc As FormatConditionCollection = pfc.FormatConditions
fcc.AddArea(pivot.DataBodyRange)
Dim idx As Int32 = fcc.AddCondition(FormatConditionType.CellValue)
Dim fc As FormatCondition = fcc(idx)
fc.Formula1 = "100"
fc.Operator = OperatorType.GreaterOrEqual
fc.Style.BackgroundColor = Color.Red
pivot.RefreshData()
pivot.CalculateData()
book.Save("out_vb.xlsx")
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
cells[5, 0].Value = "grape";
cells[6, 0].Value = "blueberry";
cells[7, 0].Value = "kiwi";
cells[8, 0].Value = "cherry";
cells[0, 1].Value = "year";
cells[1, 1].Value = 2020;
cells[2, 1].Value = 2020;
cells[3, 1].Value = 2020;
cells[4, 1].Value = 2020;
cells[5, 1].Value = 2021;
cells[6, 1].Value = 2021;
cells[7, 1].Value = 2021;
cells[8, 1].Value = 2021;
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
cells[5, 2].Value = 90;
cells[6, 2].Value = 100;
cells[7, 2].Value = 110;
cells[8, 2].Value = 120;
PivotTableCollection pivots = sheet.PivotTables;
int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "year");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
//Change PivotField's attributes
PivotField rowField = pivot.RowFields[0];
rowField.DisplayName = "custom display name";
//Add PivotFilter
int index = pivot.PivotFilters.Add(0, PivotFilterType.Count);
PivotFilter filter = pivot.PivotFilters[index];
filter.AutoFilter.FilterTop10(0, false, false, 2);
//Add PivotFormatCondition
int formatIndex = pivot.PivotFormatConditions.Add();
PivotFormatCondition pfc = pivot.PivotFormatConditions[formatIndex];
FormatConditionCollection fcc = pfc.FormatConditions;
fcc.AddArea(pivot.DataBodyRange);
int idx = fcc.AddCondition(FormatConditionType.CellValue);
FormatCondition fc = fcc[idx];
fc.Formula1 = "100";
fc.Operator = OperatorType.GreaterOrEqual;
fc.Style.BackgroundColor = Color.Red;
pivot.RefreshData();
pivot.CalculateData();
//do your business
book.Save("out.xlsx");
[Visual Basic]
Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets(0)
Dim cells As Cells = sheet.Cells
cells(0, 0).Value = "fruit"
cells(1, 0).Value = "grape"
cells(2, 0).Value = "blueberry"
cells(3, 0).Value = "kiwi"
cells(4, 0).Value = "cherry"
cells(5, 0).Value = "grape"
cells(6, 0).Value = "blueberry"
cells(7, 0).Value = "kiwi"
cells(8, 0).Value = "cherry"
cells(0, 1).Value = "year"
cells(1, 1).Value = 2020
cells(2, 1).Value = 2020
cells(3, 1).Value = 2020
cells(4, 1).Value = 2020
cells(5, 1).Value = 2021
cells(6, 1).Value = 2021
cells(7, 1).Value = 2021
cells(8, 1).Value = 2021
cells(0, 2).Value = "amount"
cells(1, 2).Value = 50
cells(2, 2).Value = 60
cells(3, 2).Value = 70
cells(4, 2).Value = 80
cells(5, 2).Value = 90
cells(6, 2).Value = 100
cells(7, 2).Value = 110
cells(8, 2).Value = 120
Dim pivots As PivotTableCollection = sheet.PivotTables
Dim pivotIndex As Int32 = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable")
Dim pivot As PivotTable = pivots(pivotIndex)
pivot.AddFieldToArea(PivotFieldType.Row, "fruit")
Pivot.AddFieldToArea(PivotFieldType.Column, "year")
Pivot.AddFieldToArea(PivotFieldType.Data, "amount")
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10
'Change PivotField's attributes
Dim rowField As PivotField = pivot.RowFields(0)
rowField.DisplayName = "custom display name"
'Add PivotFilter
Dim filterIndex As Int32 = pivot.PivotFilters.Add(0, PivotFilterType.Count)
Dim filter As PivotFilter = pivot.PivotFilters(filterIndex)
filter.AutoFilter.FilterTop10(0, False, False, 2)
'Add PivotFormatCondition
Dim formatIndex As Int32 = pivot.PivotFormatConditions.Add()
Dim pfc As PivotFormatCondition = pivot.PivotFormatConditions(formatIndex)
Dim fcc As FormatConditionCollection = pfc.FormatConditions
fcc.AddArea(pivot.DataBodyRange)
Dim idx As Int32 = fcc.AddCondition(FormatConditionType.CellValue)
Dim fc As FormatCondition = fcc(idx)
fc.Formula1 = "100"
fc.Operator = OperatorType.GreaterOrEqual
fc.Style.BackgroundColor = Color.Red
pivot.RefreshData()
pivot.CalculateData()
book.Save("out_vb.xlsx")
[C#]
//Instantiate the workbook object
Workbook workbook = new Workbook("book1.xls");
//Get Cells collection
Cells cells = workbook.Worksheets[0].Cells;
//Instantiate FindOptions Object
FindOptions findOptions = new FindOptions();
//Create a Cells Area
CellArea ca = new CellArea();
ca.StartRow = 8;
ca.StartColumn = 2;
ca.EndRow = 17;
ca.EndColumn = 13;
//Set cells area for find options
findOptions.SetRange(ca);
//Set searching properties
findOptions.SearchBackward = false;
findOptions.SeachOrderByRows = true;
findOptions.LookInType = LookInType.Values;
//Find the cell with 0 value
Cell cell = cells.Find(0, null, findOptions);
[VB.NET]
'Instantiate the workbook object
Dim workbook As New Workbook("book1.xls")
'Get Cells collection
Dim cells As Cells = workbook.Worksheets(0).Cells
'Instantiate FindOptions Object
Dim findOptions As New FindOptions()
'Create a Cells Area
Dim ca As New CellArea()
ca.StartRow = 8
ca.StartColumn = 2
ca.EndRow = 17
ca.EndColumn = 13
'Set cells area for find options
findOptions.SetRange(ca)
'Set searching properties
findOptions.SearchBackward = True
findOptions.SeachOrderByRows = True
findOptions.LookInType = LookInType.Values
'Find the cell with 0 value
Dim cell As Cell = cells.Find(0, Nothing, findOptions)
Provides access to
The string names of the properties correspond to the names of the typed
properties available from
If you request a property that is not present in the document, but the name
of the property is recognized as a valid built-in name, a new
If you request a property that is not present in the document and the name is not recognized as a built-in name, a null is returned.
Aspose.Cells does not update this property when you modify the document.
Aspose.Cells does not update this property when you modify the document.
If the document was never printed, this property will return DateTime.MinValue.
Aspose.Cells does not update this property when you modify the document.
Aspose.Cells does not update this property when you modify the document.
Aspose.Cells does not update this property when you modify the document.
Aspose.Cells does not update this property when you modify the document.
Aspose.Cells does not update this property when you modify the document.
Aspose.Cells does not update this property when you modify the document.
Each
[C#]
//Instantiate a Workbook object
Workbook workbook = new Workbook("book1.xls");
//Retrieve a list of all custom document properties of the Excel file
CustomDocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
[VB.NET]
'Instantiate a Workbook object
Dim workbook As New Workbook("book1.xls")
'Retrieve a list of all custom document properties of the Excel file
Dim customProperties As CustomDocumentPropertyCollection = workbook.Worksheets.CustomDocumentProperties
[C#]
//Instantiate a Workbook object
Workbook workbook = new Workbook("book1.xls");
//Retrieve a list of all custom document properties of the Excel file
DocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
//Accessng a custom document property by using the property index
DocumentProperty customProperty1 = customProperties[3];
//Accessng a custom document property by using the property name
DocumentProperty customProperty2 = customProperties["Owner"];
[VB.NET]
'Instantiate a Workbook object
Dim workbook As Workbook = New Workbook("book1.xls")
'Retrieve a list of all custom document properties of the Excel file
Dim customProperties As DocumentPropertyCollection = workbook.Worksheets.CustomDocumentProperties
'Accessng a custom document property by using the property index
Dim customProperty1 As DocumentProperty = customProperties(3)
'Accessng a custom document property by using the property name
Dim customProperty2 As DocumentProperty = customProperties("Owner")
Converts a number property using Object.ToString(). Converts a boolean property into "Y" or "N". Converts a date property into a short date string.
Throws an exception if the property type is not PropertyType.Date.
Throws an exception if the property type is not PropertyType.Boolean.
[C#]
//Instantiate a Workbook object by calling its empty constructor
Workbook workbook = new Workbook("book1.xls");
//Retrieve a list of all custom document properties of the Excel file
DocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;
//Accessng a custom document property by using the property index
DocumentProperty customProperty1 = customProperties[3];
//Accessng a custom document property by using the property name
DocumentProperty customProperty2 = customProperties["Owner"];
[VB.NET]
'Instantiate a Workbook object by calling its empty constructor
Dim workbook As Workbook = New Workbook("book1.xls")
'Retrieve a list of all custom document properties of the Excel file
Dim customProperties As DocumentPropertyCollection = workbook.Worksheets.CustomDocumentProperties
'Accessng a custom document property by using the property index
Dim customProperty1 As DocumentProperty = customProperties(3)
'Accessng a custom document property by using the property name
Dim customProperty2 As DocumentProperty = customProperties("Owner")
Returns null if a property with the specified name is not found.
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Add a new property.
workbook.ContentTypeProperties.Add("Admin", "Aspose", "text");
//Save the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Add a new property.
workbook.ContentTypeProperties.Add("Admin", "Aspose", "text")
'Save the Excel file
workbook.Save("book1.xlsm")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Add a new property.
workbook.ContentTypeProperties.Add("Admin", "Aspose", "text");
//Save the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Add a new property.
workbook.ContentTypeProperties.Add("Admin", "Aspose", "text")
'Save the Excel file
workbook.Save("book1.xlsm")
[C#]
//signature collection contains one or more signature needed to sign
DigitalSignatureCollection dsc = new DigitalSignatureCollection();
//The cert must contain private key, it can be contructed from cert file or windows certificate collection.
//123456 is password of cert
X509Certificate2 cert = new X509Certificate2("mykey2.pfx", "123456");
DigitalSignature ds = new DigitalSignature(cert, "test for sign", DateTime.Now);
dsc.Add(ds);
Workbook wb = new Workbook();
//set all signatures to workbook
wb.SetDigitalSignature(dsc);
wb.Save(@"newfile.xlsx");
[Visual Basic]
'signature collection contains one or more signature needed to sign
Dim dsc As DigitalSignatureCollection = New DigitalSignatureCollection()
'The cert must contain private key, it can be contructed from cert file or windows certificate collection.
Dim cert As X509Certificate2 = New X509Certificate2("mykey2.pfx", "123456")
'create a signature with certificate, sign purpose and sign time
Dim ds As DigitalSignature = New DigitalSignature(cert, "test for sign", DateTime.Now)
dsc.Add(ds)
Dim wb As Workbook = New Workbook()
'set all signatures to workbook
wb.SetDigitalSignature(dsc)
wb.Save("newfile.xlsx")
[C#]
//workbook from a signed source file
Workbook signedWorkbook = new Workbook(@"signedFile.xlsx");
//wb.IsDigitallySigned is true when the workbook is signed already.
Console.WriteLine(signedWorkbook.IsDigitallySigned);
//get digitalSignature collection from workbook
DigitalSignatureCollection existingDsc = signedWorkbook.GetDigitalSignature();
foreach (DigitalSignature existingDs in existingDsc)
{
Console.WriteLine(existingDs.Comments);
Console.WriteLine(existingDs.SignTime);
Console.WriteLine(existingDs.IsValid);
}
[Visual Basic]
'workbook from a signed source file
Dim signedWorkbook As Workbook = New Workbook("newfile.xlsx")
'Workbook.IsDigitallySigned is true when the workbook is signed already.
Console.WriteLine(signedWorkbook.IsDigitallySigned)
'get digitalSignature collection from workbook
Dim existingDsc As DigitalSignatureCollection = signedWorkbook.GetDigitalSignature()
Dim existingDs As DigitalSignature
For Each existingDs In existingDsc
Console.WriteLine(existingDs.Comments)
Console.WriteLine(existingDs.SignTime)
Console.WriteLine(existingDs.IsValid)
Next
[C#]
Workbook workbook = new Workbook();
CommentCollection comments = workbook.Worksheets[0].Comments;
//Add comment to cell A1
int commentIndex1 = comments.Add(0, 0);
Comment comment1 = comments[commentIndex1];
comment1.Note = "First note.";
comment1.Font.Name = "Times New Roman";
//Add comment to cell B2
comments.Add("B2");
Comment comment2 = comments["B2"];
comment2.Note = "Second note.";
//do your business
//Save the excel file.
workbook.Save("exmaple.xlsx");
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim comments as CommentCollection = workbook.Worksheets(0).Comments
'Add comment to cell A1
Dim commentIndex1 as Integer = comments.Add(0, 0)
Dim comment1 as Comment = comments(commentIndex1)
comment1.Note = "First note."
comment1.Font.Name = "Times New Roman"
'Add comment to cell B2
comments.Add("B2")
Dim comment2 As Comment = comments("B2")
comment2.Note = "Second note."
[C#]
comment1.Author = "Carl.Yang";
[C#]
CommentShape shape = comment1.CommentShape;
int w = shape.Width;
int h = shape.Height;
[C#]
int row = comment1.Row;
[C#]
int column = comment1.Column;
[C#]
if(comment1.IsThreadedComment)
{
//This comment is a threaded comment.
}
[C#]
ThreadedCommentCollection threadedComments = comment1.ThreadedComments;
for (int i = 0; i < threadedComments.Count; ++i)
{
ThreadedComment tc = threadedComments[i];
string note = tc.Notes;
}
[C#]
comment1.Note = "First note.";
[C#]
comment1.HtmlNote = "<Font Style='FONT-FAMILY: Calibri;FONT-SIZE: 11pt;COLOR: #0000ff;TEXT-ALIGN: left;'>This is a <b>test</b>.</Font>";
[C#]
Aspose.Cells.Font font = comment1.Font;
font.Size = 12;
[C#]
Aspose.Cells.FontSetting fontSetting = comment1.Characters(0, 4);
[C#]
ArrayList list = comment1.GetCharacters();
[C#]
FontSetting[] list = comment1.GetRichFormattings();
[C#]
if(comment1.IsVisible)
{
//The comment is visible
}
[C#]
if(comment1.TextOrientationType == TextOrientationType.NoRotation)
{
comment1.TextOrientationType = TextOrientationType.TopToBottom;
}
[C#]
if (comment1.TextHorizontalAlignment == TextAlignmentType.Fill)
{
comment1.TextHorizontalAlignment = TextAlignmentType.Center;
}
[C#]
if (comment1.TextVerticalAlignment == TextAlignmentType.Fill)
{
comment1.TextVerticalAlignment = TextAlignmentType.Center;
}
[C#]
if(!comment1.AutoSize)
{
//The size of the comment varies with the content
comment1.AutoSize = true;
}
[C#]
comment1.HeightCM = 1.0;
[C#]
comment1.WidthCM = 1.0;
[C#]
comment1.Width = 10;
[C#]
comment1.Height = 10;
[C#]
comment1.WidthInch = 1.0;
[C#]
comment1.HeightInch = 1.0;
[C#]
Workbook workbook = new Workbook();
CommentCollection comments = workbook.Worksheets[0].Comments;
//do your business
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim comments as CommentCollection = workbook.Worksheets(0).Comments
[C#]
ThreadedCommentCollection threadedComments1 = comments.GetThreadedComments(1, 1);
for (int i = 0; i < threadedComments1.Count; ++i)
{
ThreadedComment tc = threadedComments1[i];
string note = tc.Notes;
}
[C#]
ThreadedCommentCollection threadedComments2 = comments.GetThreadedComments("B2");
for (int i = 0; i < threadedComments2.Count; ++i)
{
ThreadedComment tc = threadedComments2[i];
string note = tc.Notes;
}
[C#]
int commentIndex1 = comments.Add(0, 0);
Comment comment1 = comments[commentIndex1];
comment1.Note = "First note.";
comment1.Font.Name = "Times New Roman";
[C#]
int commentIndex2 = comments.Add("B2");
Comment comment2 = comments[commentIndex2];
comment2.Note = "Second note.";
comment2.Font.Name = "Times New Roman";
[C#]
Comment comment3 = comments[0];
comment3.Note = "Three note.";
[C#]
Comment comment4 = comments["B2"];
comment4.Note = "Four note.";
[C#]
Comment comment5 = comments[1,1];
comment5.Note = "Five note.";
[C#]
comments.RemoveAt("B2");
[C#]
comments.RemoveAt(1,1);
[C#]
comments.Clear();
[C#]
Workbook workbook = new Workbook();
ErrorCheckOptionCollection opts = workbook.Worksheets[0].ErrorCheckOptions;
int optionIdx = opts.Add();
ErrorCheckOption opt = opts[optionIdx];
opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.InconsistFormula, false);
opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.InconsistRange, false);
opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.TextDate, false);
opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.TextNumber, false);
opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.Validation, false);
opt.AddRange(CellArea.CreateCellArea("A1", "B10"));
workbook.Save(@"Book1.xlsx");
[Visual Basic]
Dim workbook As Workbook = New Workbook()
Dim opts As ErrorCheckOptionCollection = workbook.Worksheets(0).ErrorCheckOptions
Dim optionIdx As Integer = opts.Add()
Dim opt As ErrorCheckOption = opts(optionIdx)
opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.InconsistFormula, False)
opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.InconsistRange, False)
opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.TextDate, False)
opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.TextNumber, False)
opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.Validation, False)
opt.AddRange(CellArea.CreateCellArea("A1", "B10"))
workbook.Save("Book1.xlsx")
[C#]
Workbook wb = new Workbook("connection.xlsx");
ExternalConnectionCollection dataConns = wb.DataConnections;
ExternalConnection dataConn = null;
for (int i = 0; i < dataConns.Count; i++)
{
dataConn = dataConns[i];
//get external connection id
Console.WriteLine(dataConn.ConnectionId);
}
[Visual Basic]
Dim wb As Workbook = New Workbook("connection.xlsx")
Dim dataConns As ExternalConnectionCollection = wb.DataConnections
Dim dataConn As ExternalConnection
Dim count As Integer = dataConns.Count - 1
Dim i As Integer
For i = 0 To count Step 1
dataConn = dataConns(i)
'get external connection id
Console.WriteLine(dataConn.ConnectionId)
Next
[C#]
//Open a file with external links
Workbook workbook = new Workbook("book1.xls");
//Get External Link
ExternalLink externalLink = workbook.Worksheets.ExternalLinks[0];
//Change External Link's Data Source
externalLink.DataSource = "d:\\link.xls";
[VB.NET]
'Open a file with external links
Dim workbook As New Workbook("book1.xls")
'Get External Link
Dim externalLink As ExternalLink = workbook.Worksheets.ExternalLinks(0)
'Change External Link's Data Source
externalLink.DataSource = "d:\link.xls"
[C#]
//Open a file with external links
Workbook workbook = new Workbook("book1.xls");
//Change external link data source
workbook.Worksheets.ExternalLinks[0].DataSource = "d:\\link.xls";
[Visual Basic]
'Open a file with external links
Dim workbook As Workbook = New Workbook("book1.xls")
'Change external link data source
workbook.Worksheets.ExternalLinks(0).DataSource = "d:\\link.xls"
[C#]
Workbook wb = new Workbook("custom_calc.xlsx");
CalculationOptions opts = new CalculationOptions();
opts.CustomEngine = new MyEngine();
wb.CalculateFormula(opts);
class MyEngine : AbstractCalculationEngine
{
public override void Calculate(CalculationData data)
{
string funcName = data.FunctionName.ToUpper();
if ("MYFUNC".Equals(funcName))
{
//do calculation for MYFUNC here
int count = data.ParamCount;
object res = null;
for (int i = 0; i < count; i++)
{
object pv = data.GetParamValue(i);
if (pv is ReferredArea)
{
ReferredArea ra = (ReferredArea)pv;
pv = ra.GetValue(0, 0);
}
//process the parameter here
//res = ...;
}
data.CalculatedValue = res;
}
}
}
[C#]
Workbook wb = new Workbook("calc.xlsx");
CalculationOptions opts = new CalculationOptions();
opts.CalculationMonitor = new MyCalculationMonitor();
wb.CalculateFormula(opts);
class MyCalculationMonitor : AbstractCalculationMonitor
{
public override void BeforeCalculate(int sheetIndex, int rowIndex, int colIndex)
{
if(sheetIndex!=0 || rowIndex!=0 || colIndex!=0)
{
return;
}
Console.WriteLine("Cell A1 will be calculated.");
}
}
[C#]
Workbook wb = new Workbook("template.xlsx");
InsertOptions options = new InsertOptions();
options.FormulaChangeMonitor = new MyFormulaChangeMonitor(wb.Worksheets);
wb.Worksheets[0].Cells.InsertRows(0, 2, options);
class MyFormulaChangeMonitor : AbstractFormulaChangeMonitor
{
private readonly WorksheetCollection mWorksheets;
public MyFormulaChangeMonitor(WorksheetCollection worksheets)
{
mWorksheets = worksheets;
}
public override void OnCellFormulaChanged(int sheetIndex, int rowIndex, int columnIndex)
{
Console.WriteLine("Cell " + mWorksheets[sheetIndex].Name + "!"
+ CellsHelper.CellIndexToName(rowIndex, columnIndex)
+ "'s formula was changed while inserting rows.");
}
}
If it is plain value, then returns the plain value itself;
If it is reference, then returns ReferredArea object;
If it references to dataset(s) with multiple values, then returns array of objects;
If it is some kind of expression that needs to be calculated, then it will be calculated in value mode
and generally a single value will be returned according to current cell base. For example,
if one parameter of D2's formula is A:A+B:B, then A2+B2 will be calculated and returned.
However, if this parameter has been specified as array mode
(by
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Workbook object
workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
//Adding a hyperlink to a URL at "A1" cell
int index = worksheet.Hyperlinks.Add("A1", 1, 1, "http://www.aspose.com");
//Getting a Hyperlink by index.
Hyperlink hyperlink = worksheet.Hyperlinks[index];
//Setting display text of this hyperlink.
hyperlink.TextToDisplay = "Aspose";
//Saving the Excel file
workbook.Save("book1.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Workbook object
workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Adding a hyperlink to a URL at "A1" cell
Dim index as Integer = worksheet.Hyperlinks.Add("A1", 1, 1, "http://www.aspose.com")
'Getting a Hyperlink by index.
Dim hyperlink as Hyperlink = worksheet.Hyperlinks(index);
'Setting display text of this hyperlink.
hyperlink.TextToDisplay = "Aspose";
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
//Get Hyperlinks Collection
HyperlinkCollection hyperlinks = worksheet.Hyperlinks;
//Adding a hyperlink to a URL at "A1" cell
hyperlinks.Add("A1", 1, 1, "http://www.aspose.com");
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Get Hyperlinks Collection
Dim hyperlinks As HyperlinkCollection = worksheet.Hyperlinks
'Adding a hyperlink to a URL at "A1" cell
hyperlinks.Add("A1", 1, 1, "http://www.aspose.com")
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Instantiating a Workbook object
Workbook excel = new Workbook();
Worksheet worksheet = excel.Worksheets[0];
worksheet.Hyperlinks.Add("A4", 1, 1, "http://www.aspose.com");
worksheet.Hyperlinks.Add("A5", 1, 1, "c:\\book1.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim excel As Workbook = New Workbook()
Dim worksheet as Worksheet = excel.Worksheets(0)
worksheet.Hyperlinks.Add("A4", 1, 1, "http://www.aspose.com")
worksheet.Hyperlinks.Add("A5", 1, 1, "c:\\book1.xls")
[C#]
License license = new License();
license.SetLicense("MyLicense.lic");
[Visual Basic]
Dim license As license = New license
License.SetLicense("MyLicense.lic")
[C#]
License license = new License();
license.SetLicense("MyLicense.lic");
[Visual Basic]
Dim license As license = New license
License.SetLicense("MyLicense.lic")
Tries to find the license in the following locations:
1. Explicit path.
2. The folder that contains the Aspose component assembly.
3. The folder that contains the client's calling assembly.
4. The folder that contains the entry (startup) assembly.
5. An embedded resource in the client's calling assembly.
Note:On the .NET Compact Framework, tries to find the license only in these locations:
1. Explicit path.
2. An embedded resource in the client's calling assembly.
[C#]
License license = new License();
license.SetLicense("MyLicense.lic");
[Visual Basic]
Dim license As License = New License
license.SetLicense("MyLicense.lic")
Can be a full or short file name or name of an embedded resource.
Use an empty string to switch to evaluation mode.Use this method to load a license from a stream.
[C#]
License license = new License();
license.SetLicense(myStream);
[Visual Basic]
Dim license as License = new License
license.SetLicense(myStream)
sheetIndex
later
in startRow(Row) or startCell(Cell) method,
that is, if the process needs to know which worksheet is being processed,
the implementation should retain the sheetIndex
value here.
[C#]
LoadOptions opts = new LoadOptions();
opts.LoadFilter = new LoadFilterSheet();
Workbook wb = new Workbook("template.xlsx", opts);
//Custom LoadFilter implementation
class LoadFilterSheet : LoadFilter
{
public override void StartSheet(Worksheet sheet)
{
if (sheet.Name == "Sheet1")
{
LoadDataFilterOptions = LoadDataFilterOptions.All;
}
else
{
LoadDataFilterOptions = LoadDataFilterOptions.Structure;
}
}
}
[C#]
MetadataOptions options = new MetadataOptions(MetadataType.DocumentProperties);
WorkbookMetadata meta = new WorkbookMetadata("book1.xlsx", options);
meta.CustomDocumentProperties.Add("test", "test");
meta.Save("book2.xlsx");
[C#]
Metered matered = new Metered();
matered.SetMeteredKey("PublicKey", "PrivateKey");
[Visual Basic]
Dim matered As Metered = New Metered
matered.SetMeteredKey("PublicKey", "PrivateKey")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
//Creating a named range
Range range = worksheet.Cells.CreateRange("B4", "G14");
//Setting the name of the named range
range.Name = "TestRange";
//Saving the modified Excel file in default (that is Excel 2000) format
workbook.Save("output.xls");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Accessing the first worksheet in the Excel file
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Creating a named range
Dim range As Range = worksheet.Cells.CreateRange("B4", "G14")
'Setting the name of the named range
range.Name = "TestRange"
'Saving the modified Excel file in default (that is Excel 2000) format
workbook.Save("output.xls")
[C#]
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
for (int i = 0; i <5; i++)
{
cells[0,i].PutValue(CellsHelper.ColumnIndexToName(i));
}
for (int row = 1; row <10; row++)
{
for (int column = 0; column <4; column++)
{
cells[row, column].PutValue(row * column);
}
}
ListObjectCollection tables = workbook.Worksheets[0].ListObjects;
int index = tables.Add(0, 0, 9, 4, true);
ListObject table = tables[0];
table.ShowTotals = true;
ListColumn listColumn = table.ListColumns[4];
listColumn.TotalsCalculation = Aspose.Cells.Tables.TotalsCalculation.Sum;
listColumn.Formula = "=[A]";
workbook.Save(@"Book1.xlsx");
[Visual Basic]
Dim workbook As Workbook = New Workbook()
Dim cells As Cells = workbook.Worksheets(0).Cells
For i As Int32 = 0 To 4
cells(0, i).PutValue(CellsHelper.ColumnIndexToName(i))
Next
For row As Int32 = 1 To 9
For column As Int32 = 0 To 3
cells(row, column).PutValue(row * column)
Next
Next
Dim tables As ListObjectCollection = workbook.Worksheets(0).ListObjects
Dim index As Int32 = tables.Add(0, 0, 9, 4, True)
Dim table As ListObject = tables(0)
table.ShowTotals = True
Dim listColumn as ListColumn = table.ListColumns(4);
listColumn.TotalsCalculation = Aspose.Cells.Tables.TotalsCalculation.Sum;
listColumn.Formula = "=[A]";
workbook.Save("Book1.xlsx")
[C#]
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
for (int i = 0; i <5; i++)
{
cells[0,i].PutValue(CellsHelper.ColumnIndexToName(i));
}
for (int row = 1; row <10; row++)
{
for (int column = 0; column <5; column++)
{
cells[row, column].PutValue(row * column);
}
}
ListObjectCollection tables = workbook.Worksheets[0].ListObjects;
int index = tables.Add(0, 0, 9, 4, true);
ListObject table = tables[0];
table.ShowTotals = true;
table.ListColumns[4].TotalsCalculation = Aspose.Cells.Tables.TotalsCalculation.Sum;
workbook.Save(@"Book1.xlsx");
[Visual Basic]
Dim workbook As Workbook = New Workbook()
Dim cells As Cells = workbook.Worksheets(0).Cells
For i As Int32 = 0 To 4
cells(0, i).PutValue(CellsHelper.ColumnIndexToName(i))
Next
For row As Int32 = 1 To 9
For column As Int32 = 0 To 4
cells(row, column).PutValue(row * column)
Next
Next
Dim tables As ListObjectCollection = workbook.Worksheets(0).ListObjects
Dim index As Int32 = tables.Add(0, 0, 9, 4, True)
Dim table As ListObject = tables(0)
table.ShowTotals = True
table.ListColumns(4).TotalsCalculation = Aspose.Cells.Tables.TotalsCalculation.Sum
workbook.Save("Book1.xlsx")
[C#]
Workbook workbook = new Workbook("Book1.xlsx");
ListObjectCollection tables = workbook.Worksheets[0].ListObjects;
int index = tables.Add(0, 0, 9, 4, true);
ListObject table = tables[0];
table.TableStyleType = TableStyleType.TableStyleDark2;
workbook.Save("TableStyle.xlsx");
[Visual Basic]
Dim workbook As Workbook = New Workbook("Book1.xlsx")
Dim tables As ListObjectCollection = workbook.Worksheets(0).ListObjects
Dim index As Int32 = tables.Add(0, 0, 9, 4, True)
Dim table As ListObject = tables(0)
table.TableStyleType = TableStyleType.TableStyleDark2;
workbook.Save("Book1.xlsx")
[C#]
Workbook workbook = new Workbook();
Style firstColumnStyle = workbook.CreateStyle();
firstColumnStyle.Pattern = BackgroundType.Solid;
firstColumnStyle.BackgroundColor = System.Drawing.Color.Red;
Style lastColumnStyle = workbook.CreateStyle();
lastColumnStyle.Font.IsBold = true;
lastColumnStyle.Pattern = BackgroundType.Solid;
lastColumnStyle.BackgroundColor = System.Drawing.Color.Red;
string tableStyleName = "Custom1";
TableStyleCollection tableStyles = workbook.Worksheets.TableStyles;
int index1 = tableStyles.AddTableStyle(tableStyleName);
TableStyle tableStyle = tableStyles[index1];
TableStyleElementCollection elements = tableStyle.TableStyleElements;
index1 = elements.Add(TableStyleElementType.FirstColumn);
TableStyleElement element = elements[index1];
element.SetElementStyle(firstColumnStyle);
index1 = elements.Add(TableStyleElementType.LastColumn);
element = elements[index1];
element.SetElementStyle(lastColumnStyle);
Cells cells = workbook.Worksheets[0].Cells;
for (int i = 0; i <5; i++)
{
cells[0, i].PutValue(CellsHelper.ColumnIndexToName(i));
}
for (int row = 1; row <10; row++)
{
for (int column = 0; column <5; column++)
{
cells[row, column].PutValue(row * column);
}
}
ListObjectCollection tables = workbook.Worksheets[0].ListObjects;
int index = tables.Add(0, 0, 9, 4, true);
ListObject table = tables[0];
table.ShowTableStyleFirstColumn = true;
table.ShowTableStyleLastColumn = true;
table.TableStyleName = tableStyleName;
workbook.Save(@"Book1.xlsx");
[Visual Basic]
Dim workbook As Workbook = New Workbook()
Dim firstColumnStyle As Style = workbook.CreateStyle()
firstColumnStyle.Pattern = BackgroundType.Solid
firstColumnStyle.BackgroundColor = System.Drawing.Color.Red
Dim lastColumnStyle As Style = workbook.CreateStyle()
lastColumnStyle.Font.IsBold = True
lastColumnStyle.Pattern = BackgroundType.Solid
lastColumnStyle.BackgroundColor = System.Drawing.Color.Red
Dim tableStyleName As String = "Custom1"
Dim tableStyles As TableStyleCollection = workbook.Worksheets.TableStyles
Dim index1 As Int32 = tableStyles.AddTableStyle(tableStyleName)
Dim tableStyle As TableStyle = tableStyles(index1)
Dim elements As TableStyleElementCollection = tableStyle.TableStyleElements
index1 = elements.Add(TableStyleElementType.FirstColumn)
Dim element As TableStyleElement = elements(index1)
element.SetElementStyle(firstColumnStyle)
index1 = elements.Add(TableStyleElementType.LastColumn)
element = elements(index1)
element.SetElementStyle(lastColumnStyle)
Dim cells As Cells = workbook.Worksheets(0).Cells
For i As Int32 = 0 To 4
cells(0, i).PutValue(CellsHelper.ColumnIndexToName(i))
Next
For row As Int32 = 1 To 9
For column As Int32 = 0 To 4
cells(row, column).PutValue(row * column)
Next
Next
Dim tables As ListObjectCollection = workbook.Worksheets(0).ListObjects
Dim index As Int32 = tables.Add(0, 0, 9, 4, True)
Dim table As ListObject = tables(0)
table.ShowTableStyleFirstColumn = True
table.ShowTableStyleLastColumn = True
table.TableStyleName = tableStyleName
workbook.Save("Book1.xlsx")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Init VBA project.
VbaProject vbaProject = workbook.VbaProject;
// Add a new module.
int index = vbaProject.Modules.Add(VbaModuleType.Class, "test");
// Get vba module
VbaModule vbaModule = vbaProject.Modules[index];
// Set codes
vbaModule.Codes = "Sub ShowMessage()\r\nMsgBox \"Welcome to Aspose!\"\r\nEnd Sub";
//Saving the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Init VBA project.
Dim vbaProject as VbaProject = workbook.VbaProject
'Add a new module.
Dim index as Integer = vbaProject.Modules.Add(VbaModuleType.Class, "test")
'Get vba module
Dim vbaModule as VbaModule = vbaProject.Modules(index)
'Set codes
vbaModule.Codes = "Sub ShowMessage()\r\nMsgBox \"Welcome to Aspose!\"\r\nEnd Sub"
'Saving the Excel file
workbook.Save("book1.xlsm")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Init VBA project.
VbaProject vbaProject = workbook.VbaProject;
// Add a new module.
vbaProject.Modules.Add(VbaModuleType.Class, "test");
//Saving the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Init VBA project.
Dim vbaProject as VbaProject = workbook.VbaProject
'Add a new module.
vbaProject.Modules.Add(VbaModuleType.Class, "test")
'Saving the Excel file
workbook.Save("book1.xlsm")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Init VBA project.
VbaProject vbaProject = workbook.VbaProject;
//Saving the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Init VBA project.
Dim vbaProject as VbaProject = workbook.VbaProject
'Saving the Excel file
workbook.Save("book1.xlsm")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Init VBA project.
VbaProject vbaProject = workbook.VbaProject;
// Add vba project reference
vbaProject.References.AddRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation");
//Saving the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Init VBA project.
Dim vbaProject as VbaProject = workbook.VbaProject
'Add vba project reference
vbaProject.References.AddRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation")
'Saving the Excel file
workbook.Save("book1.xlsm")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Init VBA project.
VbaProject vbaProject = workbook.VbaProject;
// Add vba project reference
vbaProject.References.AddRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation");
//Saving the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Init VBA project.
Dim vbaProject as VbaProject = workbook.VbaProject
'Add vba project reference
vbaProject.References.AddRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation")
'Saving the Excel file
workbook.Save("book1.xlsm")
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
cells[5, 0].Value = "grape";
cells[6, 0].Value = "blueberry";
cells[7, 0].Value = "kiwi";
cells[8, 0].Value = "cherry";
cells[0, 1].Value = "year";
cells[1, 1].Value = 2020;
cells[2, 1].Value = 2020;
cells[3, 1].Value = 2020;
cells[4, 1].Value = 2020;
cells[5, 1].Value = 2021;
cells[6, 1].Value = 2021;
cells[7, 1].Value = 2021;
cells[8, 1].Value = 2021;
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
cells[5, 2].Value = 90;
cells[6, 2].Value = 100;
cells[7, 2].Value = 110;
cells[8, 2].Value = 120;
PivotTableCollection pivots = sheet.PivotTables;
int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "year");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
pivot.RefreshData();
pivot.CalculateData();
SlicerCollection slicers = sheet.Slicers;
int slicerIndex = slicers.Add(pivot, "E12", "fruit");
Slicer slicer = slicers[slicerIndex];
slicer.StyleType = SlicerStyleType.SlicerStyleLight2;
//Get SlicerCache object of current slicer
SlicerCache slicerCache = slicer.SlicerCache;
//do your business
book.Save("out.xlsx");
[C#]
Console.WriteLine(slicerCache.List);
[C#]
//get SlicerCacheItem collection that contains the collection of all items in the slicer cache.
SlicerCacheItemCollection slicerCacheItems = slicerCache.SlicerCacheItems;
Console.WriteLine(slicerCacheItems.Count);
[C#]
//get the name of the slicer cache.
Console.WriteLine(slicerCache.Name);
[C#]
//get the name of this slicer cache.
Console.WriteLine(slicerCache.SourceName);
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
cells[5, 0].Value = "grape";
cells[6, 0].Value = "blueberry";
cells[7, 0].Value = "kiwi";
cells[8, 0].Value = "cherry";
cells[0, 1].Value = "year";
cells[1, 1].Value = 2020;
cells[2, 1].Value = 2020;
cells[3, 1].Value = 2020;
cells[4, 1].Value = 2020;
cells[5, 1].Value = 2021;
cells[6, 1].Value = 2021;
cells[7, 1].Value = 2021;
cells[8, 1].Value = 2021;
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
cells[5, 2].Value = 90;
cells[6, 2].Value = 100;
cells[7, 2].Value = 110;
cells[8, 2].Value = 120;
PivotTableCollection pivots = sheet.PivotTables;
int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "year");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
pivot.RefreshData();
pivot.CalculateData();
SlicerCollection slicers = sheet.Slicers;
int slicerIndex = slicers.Add(pivot, "E12", "fruit");
Slicer slicer = slicers[slicerIndex];
slicer.StyleType = SlicerStyleType.SlicerStyleLight2;
SlicerCacheItemCollection items = slicer.SlicerCache.SlicerCacheItems;
//do your business
book.Save("out.xlsx");
[Visual Basic]
Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets(0)
Dim cells As Cells = sheet.Cells
cells(0, 0).Value = "fruit"
cells(1, 0).Value = "grape"
cells(2, 0).Value = "blueberry"
cells(3, 0).Value = "kiwi"
cells(4, 0).Value = "cherry"
cells(5, 0).Value = "grape"
cells(6, 0).Value = "blueberry"
cells(7, 0).Value = "kiwi"
cells(8, 0).Value = "cherry"
cells(0, 1).Value = "year"
cells(1, 1).Value = 2020
cells(2, 1).Value = 2020
cells(3, 1).Value = 2020
cells(4, 1).Value = 2020
cells(5, 1).Value = 2021
cells(6, 1).Value = 2021
cells(7, 1).Value = 2021
cells(8, 1).Value = 2021
cells(0, 2).Value = "amount"
cells(1, 2).Value = 50
cells(2, 2).Value = 60
cells(3, 2).Value = 70
cells(4, 2).Value = 80
cells(5, 2).Value = 90
cells(6, 2).Value = 100
cells(7, 2).Value = 110
cells(8, 2).Value = 120
Dim pivots As PivotTableCollection = sheet.PivotTables
Dim pivotIndex As Int32 = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable")
Dim pivot As PivotTable = pivots(pivotIndex)
pivot.AddFieldToArea(PivotFieldType.Row, "fruit")
Pivot.AddFieldToArea(PivotFieldType.Column, "year")
Pivot.AddFieldToArea(PivotFieldType.Data, "amount")
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10
pivot.RefreshData()
pivot.CalculateData()
Dim slicers As SlicerCollection = sheet.Slicers
Dim slicerIndex As Int32 = slicers.Add(pivot, "E12", "fruit")
Dim slicer As Slicer = slicers(slicerIndex)
slicer.StyleType = SlicerStyleType.SlicerStyleLight2
Dim items As SlicerCacheItemCollection = slicer.SlicerCache.SlicerCacheItems
book.Save("out_vb.xlsx")
[C#]
SlicerCacheItem item = items[0];
[C#]
int count = items.Count;
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
cells[5, 0].Value = "grape";
cells[6, 0].Value = "blueberry";
cells[7, 0].Value = "kiwi";
cells[8, 0].Value = "cherry";
cells[0, 1].Value = "year";
cells[1, 1].Value = 2020;
cells[2, 1].Value = 2020;
cells[3, 1].Value = 2020;
cells[4, 1].Value = 2020;
cells[5, 1].Value = 2021;
cells[6, 1].Value = 2021;
cells[7, 1].Value = 2021;
cells[8, 1].Value = 2021;
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
cells[5, 2].Value = 90;
cells[6, 2].Value = 100;
cells[7, 2].Value = 110;
cells[8, 2].Value = 120;
PivotTableCollection pivots = sheet.PivotTables;
int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "year");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
pivot.RefreshData();
pivot.CalculateData();
SlicerCollection slicers = sheet.Slicers;
int slicerIndex = slicers.Add(pivot, "E12", "fruit");
Slicer slicer = slicers[slicerIndex];
slicer.StyleType = SlicerStyleType.SlicerStyleLight2;
SlicerCacheItemCollection items = slicer.SlicerCache.SlicerCacheItems;
SlicerCacheItem item = items[0];
item.Selected = false;
//do your business
book.Save("out.xlsx");
[Visual Basic]
Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets(0)
Dim cells As Cells = sheet.Cells
cells(0, 0).Value = "fruit"
cells(1, 0).Value = "grape"
cells(2, 0).Value = "blueberry"
cells(3, 0).Value = "kiwi"
cells(4, 0).Value = "cherry"
cells(5, 0).Value = "grape"
cells(6, 0).Value = "blueberry"
cells(7, 0).Value = "kiwi"
cells(8, 0).Value = "cherry"
cells(0, 1).Value = "year"
cells(1, 1).Value = 2020
cells(2, 1).Value = 2020
cells(3, 1).Value = 2020
cells(4, 1).Value = 2020
cells(5, 1).Value = 2021
cells(6, 1).Value = 2021
cells(7, 1).Value = 2021
cells(8, 1).Value = 2021
cells(0, 2).Value = "amount"
cells(1, 2).Value = 50
cells(2, 2).Value = 60
cells(3, 2).Value = 70
cells(4, 2).Value = 80
cells(5, 2).Value = 90
cells(6, 2).Value = 100
cells(7, 2).Value = 110
cells(8, 2).Value = 120
Dim pivots As PivotTableCollection = sheet.PivotTables
Dim pivotIndex As Int32 = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable")
Dim pivot As PivotTable = pivots(pivotIndex)
pivot.AddFieldToArea(PivotFieldType.Row, "fruit")
Pivot.AddFieldToArea(PivotFieldType.Column, "year")
Pivot.AddFieldToArea(PivotFieldType.Data, "amount")
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10
pivot.RefreshData()
pivot.CalculateData()
Dim slicers As SlicerCollection = sheet.Slicers
Dim slicerIndex As Int32 = slicers.Add(pivot, "E12", "fruit")
Dim slicer As Slicer = slicers(slicerIndex)
slicer.StyleType = SlicerStyleType.SlicerStyleLight2
Dim items As SlicerCacheItemCollection = slicer.SlicerCache.SlicerCacheItems
Dim item As SlicerCacheItem = items(0)
item.Selected = False
book.Save("out_vb.xlsx")
[C#]
slicer.AddPivotConnection(pivot);
[C#]
slicer.RemovePivotConnection(pivot);
[C#]
slicer.Title = "slicer title";
[C#]
slicer.AlternativeText = "AlternativeText test";
[C#]
slicer.IsPrintable = true;
[C#]
slicer.IsLocked = false;
[C#]
slicer.Placement = PlacementType.FreeFloating;
[C#]
slicer.LockedAspectRatio = true;
[C#]
slicer.LockedPosition = false;
[C#]
slicer.Refresh();
[C#]
SlicerCache slicerCache = slicer.SlicerCache;
[C#]
Worksheet currSheet = slicer.Parent;
[C#]
slicer.StyleType = SlicerStyleType.SlicerStyleLight2;
[C#]
slicer.Name = "slicer name";
[C#]
slicer.Caption = "slicer caption";
[C#]
slicer.CaptionVisible = true;
[C#]
slicer.NumberOfColumns = 1;
[C#]
slicer.LeftPixel = 2;
[C#]
slicer.TopPixel = 6;
[C#]
slicer.Width = 100;
[C#]
slicer.WidthPixel = 120;
[C#]
slicer.Height = 120;
[C#]
slicer.HeightPixel = 150;
[C#]
slicer.ColumnWidthPixel = 120;
[C#]
slicer.ColumnWidth = 80;
[C#]
slicer.RowHeightPixel = 30;
[C#]
slicer.RowHeight = 20;
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
cells[5, 0].Value = "grape";
cells[6, 0].Value = "blueberry";
cells[7, 0].Value = "kiwi";
cells[8, 0].Value = "cherry";
cells[0, 1].Value = "year";
cells[1, 1].Value = 2020;
cells[2, 1].Value = 2020;
cells[3, 1].Value = 2020;
cells[4, 1].Value = 2020;
cells[5, 1].Value = 2021;
cells[6, 1].Value = 2021;
cells[7, 1].Value = 2021;
cells[8, 1].Value = 2021;
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
cells[5, 2].Value = 90;
cells[6, 2].Value = 100;
cells[7, 2].Value = 110;
cells[8, 2].Value = 120;
PivotTableCollection pivots = sheet.PivotTables;
int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "year");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
pivot.RefreshData();
pivot.CalculateData();
SlicerCollection slicers = sheet.Slicers;
int tableIndex = sheet.ListObjects.Add("A1", "C9", true);
ListObject table = sheet.ListObjects[tableIndex];
//do your business
book.Save("out.xlsx");
[Visual Basic]
Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets(0)
Dim cells As Cells = sheet.Cells
cells(0, 0).Value = "fruit"
cells(1, 0).Value = "grape"
cells(2, 0).Value = "blueberry"
cells(3, 0).Value = "kiwi"
cells(4, 0).Value = "cherry"
cells(5, 0).Value = "grape"
cells(6, 0).Value = "blueberry"
cells(7, 0).Value = "kiwi"
cells(8, 0).Value = "cherry"
cells(0, 1).Value = "year"
cells(1, 1).Value = 2020
cells(2, 1).Value = 2020
cells(3, 1).Value = 2020
cells(4, 1).Value = 2020
cells(5, 1).Value = 2021
cells(6, 1).Value = 2021
cells(7, 1).Value = 2021
cells(8, 1).Value = 2021
cells(0, 2).Value = "amount"
cells(1, 2).Value = 50
cells(2, 2).Value = 60
cells(3, 2).Value = 70
cells(4, 2).Value = 80
cells(5, 2).Value = 90
cells(6, 2).Value = 100
cells(7, 2).Value = 110
cells(8, 2).Value = 120
Dim pivots As PivotTableCollection = sheet.PivotTables
Dim pivotIndex As Int32 = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable")
Dim pivot As PivotTable = pivots(pivotIndex)
pivot.AddFieldToArea(PivotFieldType.Row, "fruit")
Pivot.AddFieldToArea(PivotFieldType.Column, "year")
Pivot.AddFieldToArea(PivotFieldType.Data, "amount")
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10
pivot.RefreshData()
pivot.CalculateData()
Dim slicers As SlicerCollection = sheet.Slicers
Dim tableIndex As Int32 = sheet.ListObjects.Add("A1", "C9", True)
Dim table As ListObject = sheet.ListObjects(tableIndex)
book.Save("out_vb.xlsx")
[C#]
Slicer slicerByIndex = slicers[0];
[C#]
Slicer slicerByName = slicers["fruit"];
[C#]
Slicer delSlicer = slicers[0];
slicers.Remove(delSlicer);
[C#]
slicers.RemoveAt(1);
[C#]
slicers.Add(pivot, "E3", "fruit");
[C#]
slicers.Add(pivot, 20, 12, "fruit");
[C#]
slicers.Add(pivot, 20, 8, 0);
[C#]
slicers.Add(pivot, "E20", 0);
[C#]
slicers.Add(pivot, 3, 12, pivot.BaseFields[0]);
[C#]
slicers.Add(pivot, "I3", pivot.BaseFields[0]);
[C#]
slicers.Add(table, 1, "E38");
[C#]
slicers.Add(table, table.ListColumns[1], "I38");
[C#]
slicers.Add(table, table.ListColumns[1], 38, 12);
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
//Create date style
Style dateStyle = new CellsFactory().CreateStyle();
dateStyle.Custom = "m/d/yyyy";
cells[0, 1].Value = "date";
cells[1, 1].Value = new DateTime(2021, 2, 5);
cells[2, 1].Value = new DateTime(2022, 3, 8);
cells[3, 1].Value = new DateTime(2023, 4, 10);
cells[4, 1].Value = new DateTime(2024, 5, 16);
//Set date style
cells[1, 1].SetStyle(dateStyle);
cells[2, 1].SetStyle(dateStyle);
cells[3, 1].SetStyle(dateStyle);
cells[4, 1].SetStyle(dateStyle);
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
PivotTableCollection pivots = sheet.PivotTables;
//Add a PivotTable
int pivotIndex = pivots.Add("=Sheet1!A1:C5", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "date");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
//Refresh PivotTable data
pivot.RefreshData();
pivot.CalculateData();
//Add a new Timeline using PivotTable as data source
sheet.Timelines.Add(pivot, 10, 5, "date");
//Get Timeline object
Timeline timelineObj = sheet.Timelines[0];
//do your business
book.Save("out.xlsx");
[C#]
//Set the caption of the specified Timeline.
timelineObj.Caption = "timeline caption test";
[C#]
//Set the name of the specified Timeline.
timelineObj.Name = "timeline name test";
[C#]
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
cells[0, 0].Value = "fruit";
cells[1, 0].Value = "grape";
cells[2, 0].Value = "blueberry";
cells[3, 0].Value = "kiwi";
cells[4, 0].Value = "cherry";
//Create date style
Style dateStyle = new CellsFactory().CreateStyle();
dateStyle.Custom = "m/d/yyyy";
cells[0, 1].Value = "date";
cells[1, 1].Value = new DateTime(2021, 2, 5);
cells[2, 1].Value = new DateTime(2022, 3, 8);
cells[3, 1].Value = new DateTime(2023, 4, 10);
cells[4, 1].Value = new DateTime(2024, 5, 16);
//Set date style
cells[1, 1].SetStyle(dateStyle);
cells[2, 1].SetStyle(dateStyle);
cells[3, 1].SetStyle(dateStyle);
cells[4, 1].SetStyle(dateStyle);
cells[0, 2].Value = "amount";
cells[1, 2].Value = 50;
cells[2, 2].Value = 60;
cells[3, 2].Value = 70;
cells[4, 2].Value = 80;
PivotTableCollection pivots = sheet.PivotTables;
//Add a PivotTable
int pivotIndex = pivots.Add("=Sheet1!A1:C5", "A12", "TestPivotTable");
PivotTable pivot = pivots[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
pivot.AddFieldToArea(PivotFieldType.Column, "date");
pivot.AddFieldToArea(PivotFieldType.Data, "amount");
pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
//Refresh PivotTable data
pivot.RefreshData();
pivot.CalculateData();
//do your business
book.Save("out.xlsx");
[C#]
//Get the Timeline by index.
Timeline objByIndex = sheet.Timelines[0];
[C#]
//Get the Timeline by Timeline's name.
Timeline objByName = sheet.Timelines["date"];
[C#]
//Add a new Timeline using PivotTable as data source
sheet.Timelines.Add(pivot, 10, 5, "date");
[C#]
//Add a new Timeline using PivotTable as data source
sheet.Timelines.Add(pivot, "i15", "date");
[C#]
//Add a new Timeline using PivotTable as data source
sheet.Timelines.Add(pivot, 15, 5, 1);
[C#]
//Add a new Timeline using PivotTable as data source
sheet.Timelines.Add(pivot, "i5", 1);
[C#]
//Add a new Timeline using PivotTable as data source
sheet.Timelines.Add(pivot, 20, 5, pivot.BaseFields[1]);
[C#]
//Add a new Timeline using PivotTable as data source
sheet.Timelines.Add(pivot, "i10", pivot.BaseFields[1]);
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
//Add a page break at cell Y30
int Index = worksheet.HorizontalPageBreaks.Add("Y30");
//get the newly added horizontal page break
HorizontalPageBreak hPageBreak = worksheet.HorizontalPageBreaks[Index];
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Add a page break at cell Y30
Dim Index As Integer = worksheet.HorizontalPageBreaks.Add("Y30")
'get the newly added horizontal page break
Dim hPageBreak As HorizontalPageBreak = worksheet.HorizontalPageBreaks(Index)
[C#]
Workbook excel = new Workbook();
//Add a pagebreak at G5
excel.Worksheets[0].HorizontalPageBreaks.Add("G5");
excel.Worksheets[0].VerticalPageBreaks.Add("G5");
[VB]
Dim excel as Workbook = new Workbook()
'Add a pagebreak at G5
excel.Worksheets(0).HorizontalPageBreaks.Add("G5")
excel.Worksheets(0).VerticalPageBreaks.Add("G5")
[C#]
Workbook workbook = new Workbook();
WorksheetCollection sheets = workbook.Worksheets;
//Add a worksheet
sheets.Add();
Worksheet sheet = sheets[1];
PageSetup pageSetup = sheet.PageSetup;
pageSetup.PrintArea = "D1:K13";
//do your business
[Visual Basic]
Dim excel as Workbook = new Workbook()
Dim sheets as WorksheetCollection = excel.Worksheets
'Add a worksheet
sheets.Add()
Dim sheet as Worksheet = sheets(1)
Dim pageSetup as PageSetup = sheet.PageSetup
pageSetup.PrintArea = "D1:K13"
[C#]
pageSetup.PrintTitleColumns = "$A:$A";
[Visula Basic]
pageSetup.PrintTitleColumns = "$A:$A"
[C#]
pageSetup.PrintTitleRows = "$1:$1";
[Visula Basic]
pageSetup.PrintTitleRows = "$1:$1"
Script commands:
Script commands:
[C#]
Workbook excel = new Workbook();
//Add a pagebreak at G5
excel.Worksheets[0].HorizontalPageBreaks.Add("G5");
excel.Worksheets[0].VerticalPageBreaks.Add("G5");
[VB]
Dim excel as Workbook = new Workbook()
'Add a pagebreak at G5
excel.Worksheets(0).HorizontalPageBreaks.Add("G5")
excel.Worksheets(0).VerticalPageBreaks.Add("G5")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Allowing users to select locked cells of the worksheet
worksheet.Protection.AllowSelectingLockedCell = true;
//Allowing users to select unlocked cells of the worksheet
worksheet.Protection.AllowSelectingUnlockedCell = true;
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Allowing users to select locked cells of the worksheet
worksheet.Protection.AllowSelectingLockedCell = True
'Allowing users to select unlocked cells of the worksheet
worksheet.Protection.AllowSelectingUnlockedCell = True
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Getting the first query table in the worksheet if exists
//QueryTable qt = worksheet.QueryTables[0];
//Getting display address of the query table.
//string address = qt.ResultRange.Address;
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Getting the first query table in the worksheet
QueryTable qt = worksheet.QueryTables[0];
'Getting display address of the query table.
string address = qt.ResultRange.Address;
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get the first Worksheet Cells.
Cells cells = workbook.Worksheets[0].Cells;
// Create a range (A1:D3).
Range range = cells.CreateRange("A1", "D3");
// Set value to the range.
range.Value = "Hello";
//Save the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Get the first Worksheet Cells.
Dim cells as Cells = workbook.Worksheets[0].Cells
'Create a range (A1:D3).
Dim range as Range = cells.CreateRange("A1", "D3")
'Set value to the range.
range.Value = "Hello"
'Save the Excel file
workbook.Save("book1.xlsm")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get the first Worksheet Cells.
Cells cells = workbook.Worksheets[0].Cells;
cells["A1"].PutValue(1);
cells["A2"].PutValue(2);
Aspose.Cells.Range source = cells.CreateRange("A1:A2");
Aspose.Cells.Range target = cells.CreateRange("A3:A10");
//fill 3,4,5....10 to the range A3:A10
source.AutoFill(target);
//Save the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook("Book1.xlsx")
// Get the first Worksheet Cells.
Dim cells as Cells = workbook.Worksheets[0].Cells
cells("A1").PutValue(1)
cells("A2").PutValue(2)
Dim source as Aspose.Cells.Range = cells.CreateRange("A1:A2")
Dim target as Aspose.Cells.Range = cells.CreateRange("A3:A10")
'fill 3,4,5....10 to the range A3:A10
source.AutoFill(target)
'Save the Excel file
workbook.Save("book1.xlsm")
[C#]
Workbook workbook = new Workbook("template.xlsx");
Cells cells = workbook.Worksheets[0].Cells;
IEnumerator en = cells.CreateRange("B2:C3").GetEnumerator();
while (en.MoveNext())
{
Cell cell = (Cell)en.Current;
Console.WriteLine(cell.Name + ": " + cell.Value);
}
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get the first Worksheet Cells.
Cells cells = workbook.Worksheets[0].Cells;
Range range1 = cells.CreateRange("A1:A5");
Range range2 = cells.CreateRange("A3:A10");
//Get intersected range of the two ranges.
Range intersectRange = range1.Intersect(range2);
//Save the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Get the first Worksheet Cells.
Dim cells as Cells = workbook.Worksheets[0].Cells
Range range1 = cells.CreateRange("A1:A5")
Range range2 = cells.CreateRange("A3:A10")
'Get intersected range of the two ranges.
Range intersectRange = range1.Intersect(range2)
'Save the Excel file
workbook.Save("book1.xlsm")
range.Name = "Sheet1!MyRange";
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get the first Worksheet Cells.
Cells cells = workbook.Worksheets[0].Cells;
Range range1 = cells.CreateRange("A1:A5");
Range range2 = cells.CreateRange("A6:A10");
//Copy the range.
range1.Copy(range2);
//Save the Excel file
workbook.Save("book1.xlsm");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Get the first Worksheet Cells.
Dim cells as Cells = workbook.Worksheets[0].Cells
Range range1 = cells.CreateRange("A1:A5")
Range range2 = cells.CreateRange("A6:A10")
//Copy the range
range1.Copy(range2)
'Save the Excel file
workbook.Save("book1.xlsm")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
Style style = workbook.CreateStyle();
//Setting the background color to Blue
style.BackgroundColor = Color.Blue;
//Setting the foreground color to Red
style.ForegroundColor= Color.Red;
//setting Background Pattern
style.Pattern = BackgroundType.DiagonalStripe;
//New Style Flag
StyleFlag styleFlag = new StyleFlag();
//Set All Styles
styleFlag.All = true;
//Get first row
Row row = worksheet.Cells.Rows[0];
//Apply Style to first row
row.ApplyStyle(style, styleFlag);
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
Dim style As Style = workbook.CreateStyle()
'Setting the background color to Blue
style.BackgroundColor = Color.Blue
'Setting the foreground color to Red
style.ForegroundColor = Color.Red
'setting Background Pattern
style.Pattern = BackgroundType.DiagonalStripe
'New Style Flag
Dim styleFlag As New StyleFlag()
'Set All Styles
styleFlag.All = True
'Get first row
Dim row as Row = worksheet.Cells.Rows(0)
'Apply Style to first row
row.ApplyStyle(style, styleFlag)
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
Workbook workbook = new Workbook("template.xlsx");
Cells cells = workbook.Worksheets[0].Cells;
IEnumerator en = cells.Rows[1].GetEnumerator();
while (en.MoveNext())
{
Cell cell = (Cell)en.Current;
Console.WriteLine(cell.Name + ": " + cell.Value);
}
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Get first row
Row row = worksheet.Cells.Rows[0];
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Get first row
Dim row as Row = worksheet.Cells.Rows(0)
[C#]
Workbook workbook = new Workbook("template.xlsx");
Cells cells = workbook.Worksheets[0].Cells;
IEnumerator en = cells.Rows.GetEnumerator();
while (en.MoveNext())
{
Row row = (Row)en.Current;
Console.WriteLine(row.Index + ": " + row.Height);
}
//Open an Excel file
Workbook wb = new Workbook("Book1.xlsx");
PdfSaveOptions options = new PdfSaveOptions();
//Print only Page 3 and Page 4 in the output PDF
//Starting page index (0-based index)
options.PageIndex = 3;
//Number of pages to be printed
options.PageCount = 2;
//Save the PDF file
wb.Save("output.pdf", options);
//Open an Excel file
Workbook wb = new Workbook("Book1.xlsx");
PdfSaveOptions options = new PdfSaveOptions();
//Print only Page 3 and Page 4 in the output PDF
//Starting page index (0-based index)
options.PageIndex = 3;
//Number of pages to be printed
options.PageCount = 2;
//Save the PDF file
wb.Save("output.pdf", options);
Workbook wb = new Workbook("Book1.xlsx");
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
//ignore blank pages
pdfSaveOptions.PrintingPageType = PrintingPageType.IgnoreBlank;
wb.Save("output_ignore_blank_page.pdf", pdfSaveOptions);
//ignore blank pages and pages which only contains some style content like cell background
pdfSaveOptions.PrintingPageType = PrintingPageType.IgnoreStyle;
wb.Save("output_ignore_blank_and_style_page.pdf", pdfSaveOptions);
Workbook workbook = new Workbook("Book1.xlsx");
int activeSheetIndex = workbook.Worksheets.ActiveSheetIndex;
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
//set active sheet index to sheet set.
pdfSaveOptions.SheetSet = new SheetSet(new int[] { activeSheetIndex });
workbook.Save("output.pdf", pdfSaveOptions);
Workbook wb = new Workbook();
wb.Worksheets[0].Cells["A1"].Value = "Aspose";
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
PdfSecurityOptions pdfSecurityOptions = new PdfSecurityOptions();
//set owner password
pdfSecurityOptions.OwnerPassword = "YourOwnerPassword";
//set user password
pdfSecurityOptions.UserPassword = "YourUserPassword";
//set print permisson
pdfSecurityOptions.PrintPermission = true;
//set high resolution for print
pdfSecurityOptions.FullQualityPrintPermission = true;
pdfSaveOptions.SecurityOptions = pdfSecurityOptions;
wb.Save("output.pdf", pdfSaveOptions);
//load the source file with images.
Workbook wb = new Workbook("Book1.xlsx");
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
//set desired PPI as 96 and jpeg quality as 80.
pdfSaveOptions.SetImageResample(96, 80);
wb.Save("output.pdf", pdfSaveOptions);
//prepare a workbook with 3 pages.
Workbook wb = new Workbook();
wb.Worksheets[0].Cells["A1"].PutValue("Page1");
int index = wb.Worksheets.Add();
wb.Worksheets[index].Cells["A1"].PutValue("Page2");
index = wb.Worksheets.Add();
wb.Worksheets[index].Cells["A1"].PutValue("Page3");
wb.Worksheets[index].PageSetup.PaperSize = PaperSizeType.PaperA3;
//create a font for watermark, and specify bold, italic, color
RenderingFont font = new RenderingFont("Calibri", 68);
font.Italic = true;
font.Bold = true;
font.Color = Color.Blue;
//create a watermark from text and the specified font
RenderingWatermark watermark = new RenderingWatermark("Watermark", font);
//specify horizontal and vertical alignment
watermark.HAlignment = TextAlignmentType.Center;
watermark.VAlignment = TextAlignmentType.Center;
//specify rotation
watermark.Rotation = 30;
//specify opacity
watermark.Opacity = 0.6f;
//specify the scale to page(e.g. 100, 50) in percent.
watermark.ScaleToPagePercent = 50;
//spcify watermark for rendering to pdf.
PdfSaveOptions options = new PdfSaveOptions();
options.Watermark = watermark;
wb.Save("output_watermark.pdf", options);
[C#]
Workbook workbook = new Workbook();
WorkbookSettings settings = workbook.Settings;
//do your business
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim settings as WorkbookSettings = workbook.Settings
'do your business
// Hide the spreadsheet tabs.
workbook.Settings.ShowTabs = false;
[Visual Basic]
' Hide the spreadsheet tabs.
workbook.Settings.ShowTabs = False
[C#]
// Hide the horizontal scroll bar of the Excel file.
settings.IsHScrollBarVisible = false;
[Visual Basic]
' Hide the horizontal scroll bar of the Excel file.
settings.IsHScrollBarVisible = False
[C#]
// Hide the vertical scroll bar of the Excel file.
settings.IsVScrollBarVisible = false;
[Visual Basic]
' Hide the vertical scroll bar of the Excel file.
settings.IsVScrollBarVisible = False
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
//Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["A1"];
//Adding some value to the "A1" cell
cell.PutValue("Visit Aspose!");
//getting charactor
FontSetting charactor = cell.Characters(6, 7);
//Setting the font of selected characters to bold
charactor.Font.IsBold = true;
//Setting the font color of selected characters to blue
charactor.Font.Color = Color.Blue;
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Excel object
workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Accessing the "A1" cell from the worksheet
Dim cell As Aspose.Cells.Cell = worksheet.Cells("A1")
'Adding some value to the "A1" cell
cell.PutValue("Visit Aspose!")
'getting charactor
Dim charactor As FontSetting = cell.Characters(6, 7)
'Setting the font of selected characters to bold
charactor.Font.IsBold = True
'Setting the font color of selected characters to blue
charactor.Font.Color = Color.Blue
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Create WorkbookDesigner object.
WorkbookDesigner wd = new WorkbookDesigner();
//Open the template file (which contains smart markers).
wd.Workbook = new Workbook("SmartMarker_Designer.xls");
//Initialize your data from data source
//DataSet ds = new DataSet();
//...
//Set the datatable as the data source.
//wd.SetDataSource(dt);
//Process the smart markers to fill the data into the worksheets.
wd.Process(true);
//Save the excel file.
wd.Workbook.Save("outSmartMarker_Designer.xls");
[C#]
//Create a connection object, specify the provider info and set the data source.
OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=Northwind.mdb");
//Open the connection object.
con.Open();
//Create a command object and specify the SQL query.
OleDbCommand cmd = new OleDbCommand("Select * from [Order Details]", con);
//Create a data adapter object.
OleDbDataAdapter da = new OleDbDataAdapter();
//Specify the command.
da.SelectCommand = cmd;
//Create a dataset object.
DataSet ds = new DataSet();
//Fill the dataset with the table records.
da.Fill(ds, "Order Details");
//Create a datatable with respect to dataset table.
DataTable dt = ds.Tables["Order Details"];
//Create WorkbookDesigner object.
WorkbookDesigner wd = new WorkbookDesigner();
//Open the template file (which contains smart markers).
wd.Workbook = new Workbook("SmartMarker_Designer.xls");
//Set the datatable as the data source.
wd.SetDataSource(dt);
//Process the smart markers to fill the data into the worksheets.
wd.Process(true);
//Save the excel file.
wd.Workbook.Save("outSmartMarker_Designer.xls");
[Visual Basic]
'Create a connection object, specify the provider info and set the data source.
Dim con As OleDbConnection = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=Northwind.mdb")
'Open the connection object.
con.Open()
'Create a command object and specify the SQL query.
Dim cmd As OleDbCommand = New OleDbCommand("Select * from [Order Details]", con)
'Create a data adapter object.
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
'Specify the command.
da.SelectCommand = cmd
'Create a dataset object.
Dim ds As DataSet = New DataSet()
'Fill the dataset with the table records.
da.Fill(ds, "Order Details")
'Create a datatable with respect to dataset table.
Dim dt As DataTable = ds.Tables("Order Details")
'Create WorkbookDesigner object.
Dim wd As WorkbookDesigner = New WorkbookDesigner()
'Open the template file (which contains smart markers).
Dim workbook As Workbook = New Workbook("SmartMarker_Designer.xls")
wd.Workbook = workbook
'Set the datatable as the data source.
wd.SetDataSource(dt)
'Process the smart markers to fill the data into the worksheets.
wd.Process(True)
'Save the excel file.
wd.Workbook.Save("outSmartMarker_Designer.xls")
[C#]
//Instantiate a new Workbook object.
Workbook workbook = new Workbook("Book1.xls");
//Get the workbook datasorter object.
DataSorter sorter = workbook.DataSorter;
//Set the first order for datasorter object.
sorter.Order1 = Aspose.Cells.SortOrder.Descending;
//Define the first key.
sorter.Key1 = 0;
//Set the second order for datasorter object.
sorter.Order2 = Aspose.Cells.SortOrder.Ascending;
//Define the second key.
sorter.Key2 = 1;
//Create a cells area (range).
CellArea ca = new CellArea();
//Specify the start row index.
ca.StartRow = 0;
//Specify the start column index.
ca.StartColumn = 0;
//Specify the last row index.
ca.EndRow = 13;
//Specify the last column index.
ca.EndColumn = 1;
//Sort data in the specified data range (A1:B14)
sorter.Sort(workbook.Worksheets[0].Cells, ca);
//Save the excel file.
workbook.Save("outBook.xls");
[Visual Basic]
'Instantiate a new Workbook object.
Dim workbook As Workbook = New Workbook("Book1.xls")
'Get the workbook datasorter object.
Dim sorter As DataSorter = workbook.DataSorter
'Set the first order for datasorter object
sorter.Order1 = Aspose.Cells.SortOrder.Descending
'Define the first key.
sorter.Key1 = 0
'Set the second order for datasorter object.
sorter.Order2 = Aspose.Cells.SortOrder.Ascending
'Define the second key.
sorter.Key2 = 1
'Create a cells area (range).
Dim ca As CellArea = New CellArea
'Specify the start row index.
ca.StartRow = 0
'Specify the start column index.
ca.StartColumn = 0
'Specify the last row index.
ca.EndRow = 13
'Specify the last column index.
ca.EndColumn = 1
'Sort the data in the specified data range (A1:B14)
sorter.Sort(workbook.Worksheets(0).Cells, ca)
'Save the excel file.
workbook.Save("outBook.xls")
[C#]
Workbook workbook = new Workbook();
WorksheetCollection sheets = workbook.Worksheets;
Cell cell = sheets[0].Cells["A1"];
Style style = cell.GetStyle();
//Set top border style and color
Border border = style.Borders[BorderType.TopBorder];
border.LineStyle = CellBorderType.Medium;
border.Color = Color.Red;
cell.SetStyle(style);
[Visual Basic]
Dim workbook as Workbook = New Workbook()
Dim sheets as WorksheetCollection = workbook.Worksheets
Cell cell = sheets(0).Cells("A1");
Dim style as Style = cell.GetStyle()
'Set top border style and color
Dim border as Border = style.Borders(BorderType.TopBorder)
border.LineStyle = CellBorderType.Medium
border.Color = Color.Red
cell.SetStyle(style);
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
//Accessing the "A1" cell from the worksheet
Cell cell = worksheet.Cells["A1"];
//Adding some value to the "A1" cell
cell.PutValue("Visit Aspose!");
Style style = cell.GetStyle();
//Setting the line style of the top border
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the top border
style.Borders[BorderType.TopBorder].Color = Color.Black;
//Setting the line style of the bottom border
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the bottom border
style.Borders[BorderType.BottomBorder].Color = Color.Black;
//Setting the line style of the left border
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the left border
style.Borders[BorderType.LeftBorder].Color = Color.Black;
//Setting the line style of the right border
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the right border
style.Borders[BorderType.RightBorder].Color = Color.Black;
cell.SetStyle(style);
//Saving the Excel file
workbook.Save("book1.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Workbook object
workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Accessing the "A1" cell from the worksheet
Dim cell As Cell = worksheet.Cells("A1")
'Adding some value to the "A1" cell
cell.PutValue("Visit Aspose!")
Dim style as Style = cell.GetStyle()
'Setting the line style of the top border
style.Borders(BorderType.TopBorder).LineStyle = CellBorderType.Thick
'Setting the color of the top border
style.Borders(BorderType.TopBorder).Color = Color.Black
'Setting the line style of the bottom border
style.Borders(BorderType.BottomBorder).LineStyle = CellBorderType.Thick
'Setting the color of the bottom border
style.Borders(BorderType.BottomBorder).Color = Color.Black
'Setting the line style of the left border
style.Borders(BorderType.LeftBorder).LineStyle = CellBorderType.Thick
'Setting the color of the left border
style.Borders(BorderType.LeftBorder).Color = Color.Black
'Setting the line style of the right border
style.Borders(BorderType.RightBorder).LineStyle = CellBorderType.Thick
'Setting the color of the right border
style.Borders(BorderType.RightBorder).Color = Color.Black
cell.SetStyle(style)
'Saving the Excel file
workbook.Save("book1.xls")
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
//Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["A1"];
//Adding some value to the "A1" cell
cell.PutValue("Hello Aspose!");
Aspose.Cells.Font font = cell.GetStyle().Font;
//Setting the font name to "Times New Roman"
font.Name = "Times New Roman";
//Setting font size to 14
font.Size = 14;
//setting font color as Red
font.Color = System.Drawing.Color.Red;
//Saving the Excel file
workbook.Save(@"dest.xls");
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Accessing the "A1" cell from the worksheet
Dim cell As Aspose.Cells.Cell = worksheet.Cells("A1")
'Adding some value to the "A1" cell
cell.PutValue("Hello Aspose!")
Dim font As Aspose.Cells.Font = cell.GetStyle().Font
'Setting the font name to "Times New Roman"
font.Name = "Times New Roman"
'Setting font size to 14
font.Size = 14
'setting font color as Red
font.Color = System.Drawing.Color.Red
'Saving the Excel file
workbook.Save("dest.xls")
[C#]
Workbook workbook = new Workbook();
WorksheetCollection sheets = workbook.Worksheets;
Cell cell = sheets[0].Cells["A1"];
Style style = cell.GetStyle();
style.Font.Name = "Times New Roman";
style.Font.Color = Color.Blue;
cell.SetStyle(style);
0: Not rotated.
255: Top to Bottom.
-90: Downward.
90: Upward.
You can set 255 or value ranged from -90 to 90.
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
cells["A1"].PutValue("Hello World");
Style style = cells["A1"].GetStyle();
//Set ThemeColorType.Text2 color type with 40% lighten as the font color.
style.Font.ThemeColor = new ThemeColor(ThemeColorType.Text2, 0.4);
style.Pattern = BackgroundType.Solid;
//Set ThemeColorType.Background2 color type with 75% darken as the foreground color
style.ForegroundThemeColor = new ThemeColor(ThemeColorType.Background2, -0.75);
cells["A1"].SetStyle(style);
//Saving the Excel file
workbook.Save("book1.xlsx");
[Visual Basic]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
Dim cells As Cells = workbook.Worksheets(0).Cells
cells("A1").PutValue("Hello World")
'Get the cell style
Dim style As Style = cells("A1").GetStyle()
'Set ThemeColorType.Text2 color type with 40% lighten as the font color.
Style.Font.ThemeColor = New ThemeColor(ThemeColorType.Text2, 0.4)
Style.Pattern = BackgroundType.Solid
'Set ThemeColorType.Background2 color type with 75% darken as the foreground color
style.ForegroundThemeColor = New ThemeColor(ThemeColorType.Background2, -0.75)
'Set the cell style
cells("A1").SetStyle(style)
'Saving the Excel file
Workbook.Save("book1.xlsx")
[C#]
SystemTimeInterruptMonitor monitor = new SystemTimeInterruptMonitor(false);
LoadOptions lopts = new LoadOptions();
lopts.InterruptMonitor = monitor;
monitor.StartMonitor(1000); //time limit is 1 second
Workbook wb = new Workbook("Large.xlsx", lopts);
//if the time cost of loading the template file exceeds one second, interruption will be required and exception will be thrown here
//otherwise starts to monitor the save procedure
monitor.StartMonitor(1500); //time limit is 1.5 seconds
wb.Save("result.xlsx");
[C#]
ThreadInterruptMonitor monitor = new ThreadInterruptMonitor(false);
LoadOptions lopts = new LoadOptions();
lopts.InterruptMonitor = monitor;
monitor.StartMonitor(1000); //time limit is 1 second
Workbook wb = new Workbook("Large.xlsx", lopts);
//if the time cost of loading the template file exceeds one second, interruption will be required and exception will be thrown here
//otherwise finishes the monitor thread and starts to monitor the save procedure
monitor.FinishMonitor();
monitor.StartMonitor(1500); //time limit is 1.5 seconds
wb.Save("result.xlsx");
monitor.FinishMonitor();
range.Name = "Sheet1!MyRange";
[C#]
Workbook workbook = new Workbook();
ValidationCollection validations = workbook.Worksheets[0].Validations;
CellArea area = CellArea.CreateCellArea(0, 0, 1, 1);
Validation validation = validations[validations.Add(area)];
validation.Type = Aspose.Cells.ValidationType.WholeNumber;
validation.Operator = OperatorType.Between;
validation.Formula1 = "3";
validation.Formula2 = "1234";
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim validations as ValidationCollection = workbook.Worksheets(0).Validations
Dim area as CellArea = CellArea.CreateCellArea(0, 0, 1, 1);
Dim validation as Validation = validations(validations.Add(area))
validation.Type = ValidationType.WholeNumber
validation.Operator = OperatorType.Between
validation.Formula1 = "3"
validation.Formula2 = "1234"
[C#]
Workbook workbook = new Workbook();
ValidationCollection validations = workbook.Worksheets[0].Validations;
CellArea area = CellArea.CreateCellArea(0, 0, 1, 1);
Validation validation = validations[validations.Add(area)];
validation.Type = Aspose.Cells.ValidationType.List;
validation.Formula1 = "a,b,c,d";
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim validations as ValidationCollection = workbook.Worksheets(0).Validations
Dim area as CellArea = CellArea.CreateCellArea(0, 0, 1, 1);
Dim validation as Validation = validations(validations.Add(area))
validation.Type = ValidationType.List
validation.Formula1 = "a,b,c,d";
[C#]
//Open a designer file
string designerFile = "designer.xls";
Workbook workbook = new Workbook(designerFile);
//Set scroll bars
workbook.Settings.IsHScrollBarVisible = false;
workbook.Settings.IsVScrollBarVisible = false;
//Replace the placeholder string with new values
int newInt = 100;
workbook.Replace("OldInt", newInt);
string newString = "Hello!";
workbook.Replace("OldString", newString);
workbook.Save("result.xlsx");
[Visual Basic]
'Open a designer file
Dim designerFile as String = "\designer.xls"
Dim workbook as Workbook = new Workbook(designerFile)
'Set scroll bars
workbook.IsHScrollBarVisible = False
workbook.IsVScrollBarVisible = False
'Replace the placeholder string with new values
Dim newInt as Integer = 100
workbook.Replace("OldInt", newInt)
Dim newString as String = "Hello!"
workbook.Replace("OldString", newString)
workbook.Save("result.xlsx")
[C#]
Workbook workbook = new Workbook();
[Visual Basic]
Dim workbook as Workbook = new Workbook()
[C#]
Workbook workbook = new Workbook(FileFormatType.Xlsx);
[Visual Basic]
Dim workbook as Workbook = new Workbook(FileFormatType.Xlsx)
[C#]
Workbook workbook = new Workbook();
//......
workbook.Replace("AnOldValue", "NewValue");
[Visual Basic]
Dim workbook As Workbook = New Workbook()
'........
workbook.Replace("AnOldValue", "NewValue")
[C#]
Workbook workbook = new Workbook();
//......
int newValue = 100;
workbook.Replace("AnOldValue", newValue);
[Visual Basic]
Dim workbook As Workbook = New Workbook()
'.........
Dim NewValue As Integer = 100
workbook.Replace("AnOldValue", NewValue)
[C#]
Workbook workbook = new Workbook();
//......
double newValue = 100.0;
workbook.Replace("AnOldValue", newValue);
[Visual Basic]
Dim workbook As Workbook = New Workbook()
'.........
Dim NewValue As Double = 100.0
workbook.Replace("AnOldValue", NewValue)
[C#]
Workbook workbook = new Workbook();
//......
string[] newValues = new string[]{"Tom", "Alice", "Jerry"};
workbook.Replace("AnOldValue", newValues, true);
[Visual Basic]
Dim workbook As Workbook = New Workbook()
'.............
Dim NewValues() As String = New String() {"Tom", "Alice", "Jerry"}
workbook.Replace("AnOldValue", NewValues, True)
[C#]
Workbook workbook = new Workbook();
//......
int[] newValues = new int[]{1, 2, 3};
workbook.Replace("AnOldValue", newValues, true);
[Visual Basic]
Dim workbook As Workbook = New Workbook()
'...........
Dim NewValues() As Integer = New Integer() {1, 2, 3}
workbook.Replace("AnOldValue", NewValues, True)
[C#]
Workbook workbook = new Workbook();
//......
double[] newValues = new double[]{1.23, 2.56, 3.14159};
workbook.Replace("AnOldValue", newValues, true);
[Visual Basic]
Dim workbook As Workbook = New Workbook()
'...........
Dim NewValues() As Double = New Double() {1.23, 2.56, 3.14159}
workbook.Replace("AnOldValue", NewValues, True)
[C#]
Workbook workbook = new Workbook();
DataTable myDataTable = new DataTable("Customers");
// Adds data to myDataTable
//........
workbook.Replace("AnOldValue", myDataTable);
[Visual Basic]
Dim workbook As Workbook = New Workbook()
Dim myDataTable As DataTable = New DataTable("Customers")
' Adds data to myDataTable
'.............
workbook.Replace("AnOldValue", myDataTable)
The palette has 56 entries, each represented by an RGB value.
If you set a color which is not in the palette, it will not take effect.
So if you want to set a custom color, please change the palette at first.
The following is the standard color palette.
[C#]
Workbook workbook = new Workbook();
Style defaultStyle = workbook.DefaultStyle;
defaultStyle.Font.Name = "Tahoma";
workbook.DefaultStyle = defaultStyle;
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim defaultStyle as Style = workbook.DefaultStyle
defaultStyle.Font.Name = "Tahoma"
workbook.DefaultStyle = defaultStyle
Title
Subject
Author
Keywords
Comments
Template
Last Author
Revision Number
Application Name
Last Print Date
Creation Date
Last Save Time
Total Editing Time
Number of Pages
Number of Words
Number of Characters
Security
Category
Format
Manager
Company
Number of Bytes
Number of Lines
Number of Paragraphs
Number of Slides
Number of Notes
Number of Hidden Slides
Number of Multimedia Clips
[C#]
Workbook workbook = new Workbook();
DocumentProperty doc = workbook.BuiltInDocumentProperties["Author"];
doc.Value = "John Smith";
[Visual Basic]
Dim workbook as Workbook = New Workbook()
Dim doc as DocumentProperty = workbook.BuiltInDocumentProperties("Author")
doc.Value = "John Smith"
[C#]
Workbook excel = new Workbook();
excel.CustomDocumentProperties.Add("Checked by", "Jane");
[Visual Basic]
Dim excel as Workbook = New Workbook()
excel.CustomDocumentProperties.Add("Checked by", "Jane")
Workbook wb = new Workbook("Book1.xlsx");
wb.ImportXml("xml.xml", "Sheet1", 0, 0);
wb.Save("output.xlsx");
Workbook wb = new Workbook("Book1.xlsx");
//Make sure that the source xlsx file contains a XmlMap.
XmlMap xmlMap = wb.Worksheets.XmlMaps[0];
wb.ExportXml(xmlMap.Name, "output.xml");
[C#]
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Freeze panes at "AS40" with 10 rows and 10 columns
sheet.FreezePanes("AS40", 10, 10);
//Add a hyperlink in Cell A1
sheet.Hyperlinks.Add("A1", 1, 1, "http://www.aspose.com");
[Visual Basic]
Dim workbook as Workbook = new Workbook()
Dim sheet as Worksheet = workbook.Worksheets(0)
'Freeze panes at "AS40" with 10 rows and 10 columns
sheet.FreezePanes("AS40", 10, 10)
'Add a hyperlink in Cell A1
sheet.Hyperlinks.Add("A1", 1, 1, "http://www.aspose.com")
Row index and column index cannot all be zero. Number of rows and number of columns also cannot all be zero.
The first two parameters specify the froze position and the last two parameters specify the area frozen on the left top pane.
[C#]
//Instantiating a Workbook object
Workbook excel = new Workbook("template.xlsx");
//Accessing the first worksheet in the Excel file
Worksheet worksheet = excel.Worksheets[0];
//Protecting the worksheet with a password
worksheet.Protect(ProtectionType.All, "aspose", null);
//Saving the modified Excel file in default (that is Excel 20003) format
excel.Save("output.xls");
//Closing the file stream to free all resources
[Visual Basic]
'Creating a file stream containing the Excel file to be opened
Dim fstream As FileStream = New FileStream("book1.xls", FileMode.Open)
'Instantiating a Workbook object and Opening the Excel file through the file stream
Dim excel As Workbook = New Workbook(fstream)
'Accessing the first worksheet in the Excel file
Dim worksheet As Worksheet = excel.Worksheets(0)
'Protecting the worksheet with a password
worksheet.Protect(ProtectionType.All, "aspose", DBNull.Value.ToString())
'Saving the modified Excel file in default (that is Excel 20003) format
excel.Save("output.xls")
'Closing the file stream to free all resources
fstream.Close()
[C#]
Workbook workbook = new Workbook();
WorksheetCollection sheets = workbook.Worksheets;
//Add a worksheet
sheets.Add();
//Change the name of a worksheet
sheets[0].Name = "First Sheet";
//Set the active sheet to the second worksheet
sheets.ActiveSheetIndex = 1;
[Visual Basic]
Dim excel as Workbook = new Workbook()
Dim sheets as WorksheetCollection = excel.Worksheets
'Add a worksheet
sheets.Add()
'Change the name of a worksheet
sheets(0).Name = "First Sheet"
'Set the active sheet to the second worksheet
sheets.ActiveSheetIndex = 1
[C#]
Workbook workbook = new Workbook();
workbook.Worksheets.Add(SheetType.Chart);
Cells cells = workbook.Worksheets[0].Cells;
cells["c2"].PutValue(5000);
cells["c3"].PutValue(3000);
cells["c4"].PutValue(4000);
cells["c5"].PutValue(5000);
cells["c6"].PutValue(6000);
ChartCollection charts = workbook.Worksheets[1].Charts;
int chartIndex = charts.Add(ChartType.Column, 10,10,20,20);
Chart chart = charts[chartIndex];
chart.NSeries.Add("Sheet1!C2:C6", true);
[Visual Basic]
Dim workbook As Workbook = New Workbook()
workbook.Worksheets.Add(SheetType.Chart)
Dim cells As Cells = workbook.Worksheets(0).Cells
cells("c2").PutValue(5000)
cells("c3").PutValue(3000)
cells("c4").PutValue(4000)
cells("c5").PutValue(5000)
cells("c6").PutValue(6000)
Dim charts As ChartCollection = workbook.Worksheets(1).Charts
Dim chartIndex As Integer = charts.Add(ChartType.Column,10,10,20,20)
Dim chart As Chart = charts(chartIndex)
chart.NSeries.Add("Sheet1!C2:C6", True)
Title
Subject
Author
Keywords
Comments
Template
Last Author
Revision Number
Application Name
Last Print Date
Creation Date
Last Save Time
Total Editing Time
Number of Pages
Number of Words
Number of Characters
Security
Category
Format
Manager
Company
Number of Bytes
Number of Lines
Number of Paragraphs
Number of Slides
Number of Notes
Number of Hidden Slides
Number of Multimedia Clips
[C#]
Workbook workbook = new Workbook();
DocumentProperty doc = workbook.Worksheets.BuiltInDocumentProperties["Author"];
doc.Value = "John Smith";
[Visual Basic]
Dim workbook as Workbook = New Workbook()
Dim doc as DocumentProperty = workbook.Worksheets.BuiltInDocumentProperties("Author")
doc.Value = "John Smith"
[C#]
Workbook workbook = new Workbook();
workbook.Worksheets.CustomDocumentProperties.Add("Checked by", "Jane");
[Visual Basic]
Dim workbook as Workbook = New Workbook()
workbook.Worksheets.CustomDocumentProperties.Add("Checked by", "Jane")
Workbook wb = new Workbook();
XmlMapCollection xmlMapCollection = wb.Worksheets.XmlMaps;
//Add a XmlMap by a xsd file.
xmlMapCollection.Add("schema.xsd");
//Add a XmlMap by a xml file.
xmlMapCollection.Add("xml.xml");
wb.Save("twoXmlMaps.xlsx");