Forked from aspose-com-gists/Aspose.Cells for .NET Part2
Created
February 4, 2019 19:14
-
-
Save ahsaniqbalsidiqui/dbc1b0bfb63eda8a15ddbc773682ac76 to your computer and use it in GitHub Desktop.
This Gist contains code snippets from examples of Aspose.Cells for .NET.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This Gist contains code snippets from examples of Aspose.Cells for .NET. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 + "sampleBackGroundFile.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 + "outputsampleBackGroundFile.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Opening Excel95/5.0 XLS Files | |
// Instantiate LoadOptions specified by the LoadFormat. | |
LoadOptions loadOptionsExcel95 = new LoadOptions(LoadFormat.Auto); | |
// Create a Workbook object and opening the file from its path | |
Workbook wbExcel95 = new Workbook(sourceDir + "Excel95_5.0.xls", loadOptionsExcel95); | |
Console.WriteLine("Excel95/5.0 XLS opened successfully!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment