Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This Gist contains code snippets from examples of Aspose.Cells for .NET.
This Gist contains code snippets from examples of Aspose.Cells for .NET.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
LoadOptions options = new LoadOptions(LoadFormat.Xlsx);
options.CultureInfo = new CultureInfo("ja-JP");
Workbook workbook = new Workbook(sourceDir + "JapaneseDates.xlsx", options);
workbook.Save(outputDir + "JapaneseDates.pdf", SaveFormat.Pdf);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Create workbook object from source excel file
Workbook workbook = new Workbook(sourceDir + "sourcePivotTable.xlsx");
// Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Access first pivot table inside the worksheet
PivotTable pivotTable = worksheet.PivotTables[0];
// Access pivot table refresh by who
Console.WriteLine("Pivot table refresh by who = " + pivotTable.RefreshedByWho);
// Access pivot table refresh date
Console.WriteLine("Pivot table refresh date = " + pivotTable.RefreshDate);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
// Load excel file containing charts
Workbook workbook = new Workbook(sourceDir + "SampleChart.ods");
// Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Access first chart inside the worksheet
Chart chart = worksheet.Charts[0];
Console.WriteLine("Chart Subtitle: " + chart.SubTitle.Text);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
public class ImportCustomObjectsToMergedArea
{
public static void Run()
{
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook(sourceDir + "sampleMergedTemplate.xlsx");
List<Product> productList = new List<Product>();
//Creating collection of test items
for (int i = 0; i < 3; i++)
{
Product product = new Product
{
ProductId = i,
ProductName = "Test Product - " + i
};
productList.Add(product);
}
ImportTableOptions tableOptions = new ImportTableOptions();
tableOptions.CheckMergedCells = true;
tableOptions.IsFieldNameShown = false;
//Insert data to excel template
workbook.Worksheets[0].Cells.ImportCustomObjects((ICollection)productList, 1, 0, tableOptions);
workbook.Save(outputDir + "sampleMergedTemplate_out.xlsx", SaveFormat.Xlsx);
Console.WriteLine("ImportCustomObectsToMergedArea executed successfully.\r\n");
}
}
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
// Read File
string jsonInput = File.ReadAllText(dataDir + "Test.json");
// Set Styles
CellsFactory factory = new CellsFactory();
Style style = factory.CreateStyle();
style.HorizontalAlignment = TextAlignmentType.Center;
style.Font.Color = System.Drawing.Color.BlueViolet;
style.Font.IsBold = true;
// Set JsonLayoutOptions
JsonLayoutOptions options = new JsonLayoutOptions();
options.TitleStyle = style;
options.ArrayAsTable = true;
// Import JSON Data
JSONUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, options);
// Save Excel file
workbook.Save(dataDir + "ImportingFromJson.out.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Create a workbook object and load template file
Workbook workbook = new Workbook(sourceDir + "CellsNet46500.xlsx");
// Instantiate data sorter object
DataSorter sorter = workbook.DataSorter;
// Add key for second column for red color
sorter.AddKey(1, SortOnType.CellColor, SortOrder.Descending, Color.Red);
// Sort the data based on the key
sorter.Sort(workbook.Worksheets[0].Cells, CellArea.CreateCellArea("A2", "C6"));
// Save the output file
workbook.Save(outputDir + "outputSortData_CustomSortList.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
string filePath = dataDir + "Book1.xlsx";
// Create a Workbook object and opening the file from its path
Workbook wb = new Workbook(filePath);
// Instantiate Text File's Save Options
TxtSaveOptions options = new TxtSaveOptions();
// Set KeepSeparatorsForBlankRow to true show separators in blank rows
options.KeepSeparatorsForBlankRow = true;
// Save the file with the options
wb.Save(dataDir + "output.csv", options);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
var filename = sourceDir + "[20180220142533][ASPOSE_CELLS_TEST].csv";
//Load CSV file
var workbook = new Workbook(filename, new TxtLoadOptions() { Separator = ';', LoadFilter = new LoadFilter(LoadDataFilterOptions.CellData), CheckExcelRestriction = false, ConvertNumericData = false, ConvertDateTimeData = false });
Console.WriteLine(workbook.Worksheets[0].Name); // (20180220142533)(ASPOSE_CELLS_T
Console.WriteLine(workbook.Worksheets[0].Name.Length); // 31
Console.WriteLine("CSV file opened successfully!");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Get the Excel file into stream
FileStream stream = new FileStream(dataDir + "Book_Excel97_2003.xls", FileMode.Open);
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions1 = new LoadOptions(LoadFormat.Excel97To2003);
// Create a Workbook object and opening the file from the stream
Workbook wbExcel97 = new Workbook(stream, loadOptions1);
Console.WriteLine("Microsoft Excel 97 - 2003 workbook opened successfully!");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
var filename = sourceDir + "encryptedBook1.out.tmp";
Stream stream = File.Open(filename, FileMode.Open);
FileFormatInfo fileFormatInfo = FileFormatUtil.DetectFileFormat(stream, "1234"); // The password is 1234
Console.WriteLine("File Format: " + fileFormatInfo.FileFormatType);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string sourceDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Instantiate a Workbook object
// Open an Excel file
Workbook workbook = new Workbook(sourceDir + "HyperlinksSample.xlsx");
// Get the first (default) worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Create a range A2:B3
Range range = worksheet.Cells.CreateRange("A2", "B3");
// Get Hyperlinks in range
Hyperlink[] hyperlinks = range.Hyperlinks;
foreach (Hyperlink link in hyperlinks)
{
Console.WriteLine(link.Area + " : " + link.Address);
// To delete the link, use the Hyperlink.Delete() method.
link.Delete();
}
workbook.Save(outputDir + "HyperlinksSample_out.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
LoadOptions LoadOptions = new LoadOptions();
var objWB = new Aspose.Cells.Workbook(sourceDir + "Circular Formulas.xls", LoadOptions);
objWB.Settings.Iteration = true;
CalculationOptions copts = new CalculationOptions();
CircularMonitor cm = new CircularMonitor();
copts.CalculationMonitor = cm;
objWB.CalculateFormula(copts);
long lngCircularRef = cm.circulars.Count;
Console.WriteLine("Circular References found - " + lngCircularRef);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
public class CircularMonitor : AbstractCalculationMonitor
{
public ArrayList circulars = new ArrayList();
public ArrayList Circulars { get { return circulars; } }
public override bool OnCircular(IEnumerator circularCellsData)
{
CalculationCell cc = null;
ArrayList cur = new ArrayList();
while (circularCellsData.MoveNext())
{
cc = (CalculationCell)circularCellsData.Current;
cur.Add(cc.Worksheet.Name + "!" + CellsHelper.CellIndexToName(cc.CellRow, cc.CellColumn));
}
circulars.Add(cur);
return true;
}
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Create empty workbook
Workbook workbook = new Workbook();
// Register macro enabled add-in along with the function name
int id = workbook.Worksheets.RegisterAddInFunction(sourceDir + @"TESTUDF.xlam", "TEST_UDF", false);
// Register more functions in the file (if any)
workbook.Worksheets.RegisterAddInFunction(id, "TEST_UDF1"); //in this way you can add more functions that are in the same file
// Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Access first cell
var cell = worksheet.Cells["A1"];
// Set formula name present in the add-in
cell.Formula = "=TEST_UDF()";
// Save workbook to output XLSX format.
workbook.Save(outputDir + @"test_udf.xlsx", Aspose.Cells.SaveFormat.Xlsx);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Open the template file
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx");
// Save as Markdown
workbook.Save(outputDir + "Book1.md", SaveFormat.Markdown);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Load template file
Workbook wb = new Workbook(sourceDir + "samplePivotTable.xlsx");
// Get first pivot table in the worksheet
PivotTable pt = wb.Worksheets[1].PivotTables[0];
// Set pivot field
pt.ShowReportFilterPage(pt.PageFields[0]);
// Set position index for showing report filter pages
pt.ShowReportFilterPageByIndex(pt.PageFields[0].Position);
// Set the page field name
pt.ShowReportFilterPageByName(pt.PageFields[0].Name);
// Save the output file
wb.Save(outputDir + "outputSamplePivotTable.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Load template Excel file
Workbook wb = new Workbook(sourceDir + "sampleCrosssType.xlsx");
// Create file streams for saving the PDF and PNG files
using (FileStream outputStream = new FileStream(outputDir + "outputCrosssType.pdf", FileMode.Create))
using (FileStream outputStream2 = new FileStream(outputDir + "outputCrosssType.png", FileMode.Create))
{
// Initialize PDF save options
PdfSaveOptions saveOptions = new PdfSaveOptions();
// Set text cross type
saveOptions.TextCrossType = TextCrossType.StrictInCell;
// Save PDF file
wb.Save(outputStream, saveOptions);
// Initialize image or print options
ImageOrPrintOptions imageSaveOptions = new ImageOrPrintOptions();
// Set text cross type
imageSaveOptions.TextCrossType = TextCrossType.StrictInCell;
// Initialize sheet renderer object
SheetRender sheetRenderer = new SheetRender(wb.Worksheets[0], imageSaveOptions);
// Create bitmap image from sheet renderer
System.Drawing.Bitmap bitmap = sheetRenderer.ToImage(0);
// Save PNG image
bitmap.Save(outputStream2, ImageFormat.Png);
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Instantiate a new Workbook
Workbook wb = new Workbook();
// Get the first (default) worksheet
Worksheet _worksheet = wb.Worksheets[0];
// Create a range A1:B1
Range range = _worksheet.Cells.CreateRange(0, 0, 1, 2);
// Merge the cells
range.Merge();
// Insert value to the merged cell A1
_worksheet.Cells[0, 0].Value = "A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog....end";
// Create a style object
Aspose.Cells.Style style = _worksheet.Cells[0, 0].GetStyle();
// Set wrapping text on
style.IsTextWrapped = true;
// Apply the style to the cell
_worksheet.Cells[0, 0].SetStyle(style);
// Create an object for AutoFitterOptions
AutoFitterOptions options = new AutoFitterOptions();
// Set auto-fit for merged cells
options.AutoFitMergedCellsType = AutoFitMergedCellsType.EachLine;
// Autofit rows in the sheet(including the merged cells)
_worksheet.AutoFitRows(options);
// Save the Excel file
wb.Save(outputDir + "AutofitRowsforMergedCells.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
string outDir = RunExamples.Get_OutputDirectory();
//Load source Excel file
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Set the width of the cell in pixels
worksheet.Cells.SetViewColumnWidthPixel(7, 200);
workbook.Save(outDir + "SetColumnViewWidthInPixels_Out.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
string outDir = RunExamples.Get_OutputDirectory();
//Load source Excel file
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Set the width of the column in pixels
worksheet.Cells.SetColumnWidthPixel(7, 200);
workbook.Save(outDir + "SetColumnWidthInPixels_Out.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Setting Formatting options
InsertOptions insertOptions = new InsertOptions();
insertOptions.CopyFormatType = CopyFormatType.SameAsAbove;
// Inserting a row into the worksheet at 3rd position
worksheet.Cells.InsertRows(2, 1, insertOptions);
// Saving the modified Excel file
workbook.Save(dataDir + "InsertingARowWithFormatting.out.xls");
// Closing the file stream to free all resources
fstream.Close();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Open an existing file that contains a table/list object in it
Workbook workbook = new Workbook(dataDir + "book1.xlsx");
TableToRangeOptions options = new TableToRangeOptions();
options.LastRow = 5;
// Convert the first table/list object (from the first worksheet) to normal range
workbook.Worksheets[0].ListObjects[0].ConvertToRange(options);
// Save the file
workbook.Save(dataDir + "output.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Load sample Excel file
Workbook workbook = new Workbook(sourceDir + "WebExtensionsSample.xlsx");
WebExtensionTaskPaneCollection taskPanes = workbook.Worksheets.WebExtensionTaskPanes;
foreach (WebExtensionTaskPane taskPane in taskPanes)
{
Console.WriteLine("Width: " + taskPane.Width);
Console.WriteLine("IsVisible: " + taskPane.IsVisible);
Console.WriteLine("IsLocked: " + taskPane.IsLocked);
Console.WriteLine("DockState: " + taskPane.DockState);
Console.WriteLine("StoreName: " + taskPane.WebExtension.Reference.StoreName);
Console.WriteLine("StoreType: " + taskPane.WebExtension.Reference.StoreType);
Console.WriteLine("WebExtension.Id: " + taskPane.WebExtension.Id);
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string outDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook();
WebExtensionCollection extensions = workbook.Worksheets.WebExtensions;
WebExtensionTaskPaneCollection taskPanes = workbook.Worksheets.WebExtensionTaskPanes;
int extensionIndex = extensions.Add();
int taskPaneIndex = taskPanes.Add();
WebExtension extension = extensions[extensionIndex];
extension.Reference.Id = "wa104379955";
extension.Reference.StoreName = "en-US";
extension.Reference.StoreType = WebExtensionStoreType.OMEX;
WebExtensionTaskPane taskPane = taskPanes[taskPaneIndex];
taskPane.IsVisible = true;
taskPane.DockState = "right";
taskPane.WebExtension = extension;
workbook.Save(outDir + "AddWebExtension_Out.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string outDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook();
// Add Author
int authorIndex = workbook.Worksheets.ThreadedCommentAuthors.Add("Aspose Test", "", "");
ThreadedCommentAuthor author = workbook.Worksheets.ThreadedCommentAuthors[authorIndex];
// Add Threaded Comment
workbook.Worksheets[0].Comments.AddThreadedComment("A1", "Test Threaded Comment", author);
workbook.Save(outDir + "AddThreadedComments_out.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Load source Excel file
Workbook workbook = new Workbook(sourceDir + "BookWithSomeData.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Print number of cell in the Worksheet
Console.WriteLine("Number of Cells: " + worksheet.Cells.Count);
// In the number of cells is greater than 2147483647, use CountLarge
Console.WriteLine("Number of Cells (CountLarge): " + worksheet.Cells.CountLarge);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string outDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells[0, 2].Value = 1;
worksheet.Cells[1, 2].Value = 2;
worksheet.Cells[2, 2].Value = 3;
worksheet.Cells[2, 3].Value = 4;
worksheet.Cells.CreateRange(0, 2, 3, 1).Name = "NamedRange";
Range cut = worksheet.Cells.CreateRange("C:C");
worksheet.Cells.InsertCutCells(cut, 0, 1, ShiftType.Right);
workbook.Save(outDir + "CutAndPasteCells.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
string outDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook(sourceDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Get Threaded Comment
ThreadedComment comment = worksheet.Comments.GetThreadedComments("A1")[0];
comment.Notes = "Updated Comment";
workbook.Save(outDir + "EditThreadedComments.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
//Load source Excel file
Workbook workbook = new Workbook(sourceDir + "GraphicBackground.ods");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
ODSPageBackground background = worksheet.PageSetup.ODSPageBackground;
Console.WriteLine("Background Type: " + background.Type.ToString());
Console.WriteLine("Backgorund Position: " + background.GraphicPositionType.ToString());
//Save background image
Bitmap image = new Bitmap(new MemoryStream(background.GraphicData));
image.Save(outputDir + "background.jpg");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
Workbook workbook = new Workbook(sourceDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Get Threaded Comments
ThreadedCommentCollection threadedComments = worksheet.Comments.GetThreadedComments("A1");
foreach (ThreadedComment comment in threadedComments)
{
Console.WriteLine("Comment: " + comment.Notes);
Console.WriteLine("Author: " + comment.Author.Name);
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
string outDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook(sourceDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
CommentCollection comments = worksheet.Comments;
// Get Author of first comment in A1
ThreadedCommentAuthor author = worksheet.Comments.GetThreadedComments("A1")[0].Author;
// Remove Comments
comments.RemoveAt("A1");
ThreadedCommentAuthorCollection authors = workbook.Worksheets.ThreadedCommentAuthors;
// Remove Author of first comment in A1
authors.RemoveAt(authors.IndexOf(author));
workbook.Save(outDir + "ThreadedCommentsSample_Out.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Instantiating a Workbook object
Workbook workbook = new Workbook();
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells[0, 0].Value = 1;
worksheet.Cells[1, 0].Value = 2;
worksheet.Cells[2, 0].Value = 3;
worksheet.Cells[3, 0].Value = 4;
worksheet.Cells[4, 0].Value = 5;
worksheet.Cells[5, 0].Value = 6;
worksheet.Cells[0, 1].Value = 7;
worksheet.Cells[1, 1].Value = 8;
worksheet.Cells[2, 1].Value = 9;
worksheet.Cells[3, 1].Value = 10;
worksheet.Cells[4, 1].Value = 11;
worksheet.Cells[5, 1].Value = 12;
ODSPageBackground background = worksheet.PageSetup.ODSPageBackground;
background.Color = Color.Azure;
background.Type = ODSPageBackgroundType.Color;
workbook.Save(outputDir + "ColoredBackground.ods", SaveFormat.ODS);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Instantiating a Workbook object
Workbook workbook = new Workbook();
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells[0, 0].Value = 1;
worksheet.Cells[1, 0].Value = 2;
worksheet.Cells[2, 0].Value = 3;
worksheet.Cells[3, 0].Value = 4;
worksheet.Cells[4, 0].Value = 5;
worksheet.Cells[5, 0].Value = 6;
worksheet.Cells[0, 1].Value = 7;
worksheet.Cells[1, 1].Value = 8;
worksheet.Cells[2, 1].Value = 9;
worksheet.Cells[3, 1].Value = 10;
worksheet.Cells[4, 1].Value = 11;
worksheet.Cells[5, 1].Value = 12;
ODSPageBackground background = worksheet.PageSetup.ODSPageBackground;
background.Type = ODSPageBackgroundType.Graphic;
background.GraphicData = File.ReadAllBytes(sourceDir + "background.jpg");
background.GraphicType = ODSPageBackgroundGraphicType.Area;
workbook.Save(outputDir + "GraphicBackground.ods", SaveFormat.ODS);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Print message about XLS format.
Console.WriteLine("Maximum Rows and Columns supported by XLS format.");
// Create workbook in XLS format.
Workbook wb = new Workbook(FileFormatType.Excel97To2003);
// Print the maximum rows and columns supported by XLS format.
int maxRows = wb.Settings.MaxRow + 1;
int maxCols = wb.Settings.MaxColumn + 1;
Console.WriteLine("Maximum Rows: " + maxRows);
Console.WriteLine("Maximum Columns: " + maxCols);
Console.WriteLine();
// Print message about XLSX format.
Console.WriteLine("Maximum Rows and Columns supported by XLSX format.");
// Create workbook in XLSX format.
wb = new Workbook(FileFormatType.Xlsx);
// Print the maximum rows and columns supported by XLSX format.
maxRows = wb.Settings.MaxRow + 1;
maxCols = wb.Settings.MaxColumn + 1;
Console.WriteLine("Maximum Rows: " + maxRows);
Console.WriteLine("Maximum Columns: " + maxCols);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Load Excel file containing Dialog Sheet
Workbook wb = new Workbook("sampleFindIfWorksheetIsDialogSheet.xlsx");
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Find if the sheet type is dialog and print the message
if (ws.Type == SheetType.Dialog)
{
Console.WriteLine("Worksheet is a Dialog Sheet.");
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Create empty workbook.
Workbook wb = new Workbook();
// Write protect workbook with password.
wb.Settings.WriteProtection.Password = "1234";
// Specify author while write protecting workbook.
wb.Settings.WriteProtection.Author = "SimonAspose";
// Save the workbook in XLSX format.
wb.Save(outputDir + "outputSpecifyAuthorWhileWriteProtectingWorkbook.xlsx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.