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.
Workbook workbook = new Workbook("SourceExcel.xls");
workbook.Save("outputExcel.xlsx", SaveFormat.Xlsx);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Output directory
static string outputDir = RunExamples.Get_OutputDirectory();
//Create InterruptMonitor object
InterruptMonitor im = new InterruptMonitor();
//This function will create workbook and convert it to Pdf format
void CreateWorkbookAndConvertItToPdfFormat()
{
//Create a workbook object
Workbook wb = new Workbook();
//Assign it InterruptMonitor object
wb.InterruptMonitor = im;
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Access cell J1000000 and add some text inside it.
Cell cell = ws.Cells["J1000000"];
cell.PutValue("This is text.");
try
{
//Save the workbook to Pdf format
wb.Save(outputDir + "output_InterruptMonitor.pdf");
}
catch (Aspose.Cells.CellsException ex)
{
Console.WriteLine("Process Interrupted - Message: " + ex.Message);
}
}
//This function will interrupt the conversion process after 10s
void WaitForWhileAndThenInterrupt()
{
Thread.Sleep(1000 * 10);
im.Interrupt();
}
public void TestRun()
{
ThreadStart ts1 = new ThreadStart(this.CreateWorkbookAndConvertItToPdfFormat);
Thread t1 = new Thread(ts1);
t1.Start();
ThreadStart ts2 = new ThreadStart(this.WaitForWhileAndThenInterrupt);
Thread t2 = new Thread(ts2);
t2.Start();
t1.Join();
t2.Join();
}
public static void Run()
{
new StopConversionOrLoadingUsingInterruptMonitor().TestRun();
Console.WriteLine("StopConversionOrLoadingUsingInterruptMonitor executed successfully.");
}
// 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();
// Some data in the form of byte array.
// Please use correct XML and Schema instead.
byte[] btsData = new byte[] { 1, 2, 3 };
byte[] btsSchema = new byte[] { 1, 2, 3 };
// Create four custom xml parts.
wb.CustomXmlParts.Add(btsData, btsSchema);
wb.CustomXmlParts.Add(btsData, btsSchema);
wb.CustomXmlParts.Add(btsData, btsSchema);
wb.CustomXmlParts.Add(btsData, btsSchema);
// Assign ids to custom xml parts.
wb.CustomXmlParts[0].ID = "Fruit";
wb.CustomXmlParts[1].ID = "Color";
wb.CustomXmlParts[2].ID = "Sport";
wb.CustomXmlParts[3].ID = "Shape";
// Specify search custom xml part id.
String srchID = "Fruit";
srchID = "Color";
srchID = "Sport";
// Search custom xml part by the search id.
Aspose.Cells.Markup.CustomXmlPart cxp = wb.CustomXmlParts.SelectByID(srchID);
// Print the found or not found message on console.
if (cxp == null)
{
Console.WriteLine("Not Found: CustomXmlPart ID " + srchID);
}
else
{
Console.WriteLine("Found: CustomXmlPart ID " + srchID);
}
Console.WriteLine("AddCustomXMLPartsAndSelectThemByID executed 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);
// Instantiating a Workbook object
Workbook wb = new Workbook();
PictureCollection pics = wb.Worksheets[0].Pictures;
pics.Add(10, 0,12,1,(Stream)null);
SignatureLine signatureLine = new SignatureLine();
signatureLine.Id = Guid.NewGuid();
signatureLine.ProviderId = Guid.Empty;
signatureLine.Signer = "Aspose.Cells";
signatureLine.Title = "signed by Aspose.Cells";
wb.Worksheets[0].Pictures[0].SignatureLine = signatureLine;
X509Certificate2 certificate = new X509Certificate2(dataDir + "rsa2048.pfx", "123456");
Aspose.Cells.DigitalSignatures.DigitalSignature signature =
new Aspose.Cells.DigitalSignatures.DigitalSignature(certificate, "test Microsoft Office signature line", DateTime.UtcNow);
signature.Id = signatureLine.Id;
signature.ProviderId = signatureLine.ProviderId;
Aspose.Cells.DigitalSignatures.DigitalSignatureCollection dsCollection = new Aspose.Cells.DigitalSignatures.DigitalSignatureCollection();
dsCollection.Add(signature);
wb.SetDigitalSignature(dsCollection);
wb.Save(dataDir + "signatureLine.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();
// Instantiate a new Workbook
Workbook workbook = new Workbook();
// Get the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Add some text in cell A1
worksheet.Cells["A1"].PutValue("Here");
// Add a comment to A1 cell
var comment = worksheet.Comments[worksheet.Comments.Add("A1")];
// Set its vertical alignment setting
comment.CommentShape.TextVerticalAlignment = TextAlignmentType.Center;
// Set the Comment note
comment.Note = "This is my Comment Text. This is Test.";
Shape shape = worksheet.Comments["A1"].CommentShape;
shape.Fill.SolidFill.Color = Color.Black;
Font font = shape.Font;
font.Color = Color.White;
StyleFlag styleFlag = new StyleFlag();
styleFlag.FontColor = true;
shape.TextBody.Format(0, shape.Text.Length, font, styleFlag);
// Save the Excel file
workbook.Save(outputDir + "outputChangeCommentFontColor.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 your excel file inside a workbook obect
Workbook wb = new Workbook(sourceDir + "sampleChangeTextBoxOrShapeCharacterSpacing.xlsx");
// Access your text box which is also a shape object from shapes collection
Shape shape = wb.Worksheets[0].Shapes[0];
// Access the first font setting object via GetCharacters() method
FontSetting fs = (FontSetting)shape.GetCharacters()[0];
//Set the character spacing to point 4
fs.TextOptions.Spacing = 4;
// Save the workbook in xlsx format
wb.Save(outputDir + "outputChangeTextBoxOrShapeCharacterSpacing.xlsx", SaveFormat.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();
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
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
Workbook book = new Workbook(sourceDir + "sampleConvertWorksheetToImageByPage.xlsx");
Worksheet sheet = book.Worksheets[0];
Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
options.HorizontalResolution = 200;
options.VerticalResolution = 200;
options.ImageType = Drawing.ImageType.Tiff;
// Sheet2Image By Page conversion
SheetRender sr = new SheetRender(sheet, options);
for (int j = 0; j < sr.PageCount; j++)
{
sr.ToImage(j, outputDir + "outputConvertWorksheetToImageByPage_" + (j + 1) + ".tif");
}
// 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();
// Open a template excel file
Workbook book = new Workbook(sourceDir + "sampleConvertWorksheettoImageFile.xlsx");
// Get the first worksheet.
Worksheet sheet = book.Worksheets[0];
// Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.OnePagePerSheet = true;
// Specify the image format
imgOptions.ImageType = Drawing.ImageType.Jpeg;
// Render the sheet with respect to specified image/print options
SheetRender sr = new SheetRender(sheet, imgOptions);
// Render the image for the sheet
Bitmap bitmap = sr.ToImage(0);
// Save the image file
bitmap.Save(outputDir + "outputConvertWorksheettoImageFile.jpg");
// 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 workbook
var workbook = new Workbook();
// Put sample text in the first cell of first worksheet in the newly created workbook
workbook.Worksheets[0].Cells["A1"].Value = "DEMO TEXT ON SHEET1";
// Add second worksheet in the workbook
workbook.Worksheets.Add(SheetType.Worksheet);
// Set text in first cell of the second sheet
workbook.Worksheets[1].Cells["A1"].Value = "DEMO TEXT ON SHEET2";
// Set currently active sheet incex to 1 i.e. Sheet2
workbook.Worksheets.ActiveSheetIndex = 1;
// Save workbook to SVG. It shall render the active sheet only to SVG
workbook.Save(outputDir + "ConvertWorksheetToSVG_out.svg");
// 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();
// Create workbook object from source file
Workbook wb = new Workbook(sourceDir + "sampleCreateTransparentImage.xlsx");
// Apply different image or print options
var imgOption = new ImageOrPrintOptions();
imgOption.ImageType = Drawing.ImageType.Png;
imgOption.HorizontalResolution = 200;
imgOption.VerticalResolution = 200;
imgOption.OnePagePerSheet = true;
// Apply transparency to the output image
imgOption.Transparent = true;
// Create image after apply image or print options
var sr = new SheetRender(wb.Worksheets[0], imgOption);
sr.ToImage(0, outputDir + "outputCreateTransparentImage.png");
// 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();
// Open a template Excel file
Workbook workbook = new Workbook(sourceDir + "sampleExtractImagesFromWorksheets.xlsx");
// Get the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Get the first Picture in the first worksheet
Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[0];
// Set the output image file path
string picformat = pic.ImageType.ToString();
// Note: you may evaluate the image format before specifying the image path
// Define ImageOrPrintOptions
ImageOrPrintOptions printoption = new ImageOrPrintOptions();
// Specify the image format
printoption.ImageType = Drawing.ImageType.Jpeg;
// Save the image
pic.ToImage(outputDir + "outputExtractImagesFromWorksheets.jpg", printoption);
// 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();
// Instantiate and open an Excel file
Workbook book = new Workbook(sourceDir + "sampleGenerateThumbnailOfWorksheet.xlsx");
// Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
// Specify the image format
imgOptions.ImageType = Drawing.ImageType.Jpeg;
// Set the vertical and horizontal resolution
imgOptions.VerticalResolution = 200;
imgOptions.HorizontalResolution = 200;
// One page per sheet is enabled
imgOptions.OnePagePerSheet = true;
// Get the first worksheet
Worksheet sheet = book.Worksheets[0];
// Render the sheet with respect to specified image/print options
SheetRender sr = new SheetRender(sheet, imgOptions);
// Render the image for the sheet
Bitmap bmp = sr.ToImage(0);
// Create a bitmap
Bitmap thumb = new Bitmap(600, 600);
// Get the graphics for the bitmap
System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(thumb);
if (bmp != null)
{
// Draw the image
gr.DrawImage(bmp, 0, 0, 600, 600);
}
// Save the thumbnail
thumb.Save(outputDir + "outputGenerateThumbnailOfWorksheet.bmp");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// In order to save the chart image, create an instance of ImageOrPrintOptions
ImageOrPrintOptions anOption = new ImageOrPrintOptions();
// Set image format
anOption.ImageType = Drawing.ImageType.Png;
// Set resolution
anOption.HorizontalResolution = 200;
anOption.VerticalResolution = 200;
// Render chart to image
chart.ToImage(dataDir + "output_out.png", anOption);
// Save the workbook to see chart inside the Excel
workbook.Save(dataDir + "output_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();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Create workbook from source file
Workbook workbook = new Workbook(sourceDir + "sampleRefreshValueOfLinkedShapes.xlsx");
// Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Change the value of cell B4
Cell cell = worksheet.Cells["B4"];
cell.PutValue(100);
// Update the value of the Linked Picture which is linked to cell B4
worksheet.Shapes.UpdateSelectedValue();
// Save the workbook in PDF format
workbook.Save(outputDir + "outputRefreshValueOfLinkedShapes.pdf", SaveFormat.Pdf);
// 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();
// Create workbook object from source excel file
Workbook workbook = new Workbook(sourceDir + "sampleGenerateDatabarImage.xlsx");
// Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Access the cell which contains conditional formatting databar
Cell cell = worksheet.Cells["C1"];
// Create and get the conditional formatting of the worksheet
int idx = worksheet.ConditionalFormattings.Add();
FormatConditionCollection fcc = worksheet.ConditionalFormattings[idx];
fcc.AddCondition(FormatConditionType.DataBar);
fcc.AddArea(CellArea.CreateCellArea("C1", "C4"));
// Access the conditional formatting databar
DataBar dbar = fcc[0].DataBar;
// Create image or print options
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.ImageType = Drawing.ImageType.Png;
// Get the image bytes of the databar
byte[] imgBytes = dbar.ToImage(cell, opts);
// Write image bytes on the disk
File.WriteAllBytes(outputDir + "outputGenerateDatabarImage.png", imgBytes);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
string password = "1234";
string pfxPath = sourceDir + "sampleDigitallySignVbaProjectWithCertificate.pfx";
string comment = "Signing Digital Signature using Aspose.Cells";
// Set Digital Signature
DigitalSignature digitalSignature = new DigitalSignature(File.ReadAllBytes(pfxPath), password, comment, DateTime.Now);
// Create workbook object from excel file
Workbook workbook = new Workbook(sourceDir + "sampleDigitallySignVbaProjectWithCertificate.xlsm");
// Sign VBA Code Project with Digital Signature
workbook.VbaProject.Sign(digitalSignature);
// Save the workbook
workbook.Save(outputDir + "outputDigitallySignVbaProjectWithCertificate.xlsm");
// 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();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Create a workbook
Workbook wb = new Workbook(sourceDir + "sampleUpdateActiveXComboBoxControl.xlsx");
// Access first shape from first worksheet
Shape shape = wb.Worksheets[0].Shapes[0];
// Access ActiveX ComboBox Control and update its value
if (shape.ActiveXControl != null)
{
// Remove Shape ActiveX Control
shape.RemoveActiveXControl();
}
// Save the workbook
wb.Save(outputDir + "RemoveActiveXControl_our.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();
// Open the template file
Workbook book = new Workbook(sourceDir + "Book1.xlsx");
// Get the first worksheet
Worksheet sheet = book.Worksheets[0];
LoadOptions options = new LoadOptions();
options.LoadFilter = new LoadFilter(LoadDataFilterOptions.All);
// Specify your print area if you want
// Sheet.PageSetup.PrintArea = "A1:H8";
// To remove the white border around the image.
sheet.PageSetup.LeftMargin = 0;
sheet.PageSetup.RightMargin = 0;
sheet.PageSetup.BottomMargin = 0;
sheet.PageSetup.TopMargin = 0;
// Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageType = Drawing.ImageType.Emf;
// Set only one page would be rendered for the image
imgOptions.OnePagePerSheet = true;
imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;
// Create the SheetRender object based on the sheet with its
// ImageOrPrintOptions attributes
SheetRender sr = new SheetRender(sheet, imgOptions);
// Convert the image
sr.ToImage(0, outputDir + "outputRemoveWhitespaceAroundData.emf");
// 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();
// Instantiate a workbook with an Excel file.
Workbook workbook = new Workbook(sourceDir + "samplePrintingUsingWorkbookRender.xlsx");
string printerName = "doPDF 8";
// Apply different Image/Print options.
Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
options.ImageType = Drawing.ImageType.Tiff;
options.PrintingPage = PrintingPageType.Default;
// To print a whole workbook, iterate through the sheets and print them, or use the WorkbookRender class.
WorkbookRender wr = new WorkbookRender(workbook, options);
try
{
// Print the workbook.
wr.ToPrinter(printerName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// 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);
// Create workbook object.
Workbook wb = new Workbook();
// Set default font of the workbook to none
Style s = wb.DefaultStyle;
s.Font.Name = "";
wb.DefaultStyle = s;
// Access first worksheet.
Worksheet ws = wb.Worksheets[0];
// Access cell A4 and add some text inside it.
Cell cell = ws.Cells["A4"];
cell.PutValue("This text has some unknown or invalid font which does not exist.");
// Set the font of cell A4 which is unknown.
Style st = cell.GetStyle();
st.Font.Name = "UnknownNotExist";
st.Font.Size = 20;
st.IsTextWrapped = true;
cell.SetStyle(st);
// Set first column width and fourth column height
ws.Cells.SetColumnWidth(0, 80);
ws.Cells.SetRowHeight(3, 60);
// Create image or print options.
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.OnePagePerSheet = true;
opts.ImageType = Drawing.ImageType.Png;
// Render worksheet image with Courier New as default font.
opts.DefaultFont = "Courier New";
SheetRender sr = new SheetRender(ws, opts);
sr.ToImage(0, "out_courier_new_out.png");
// Render worksheet image again with Times New Roman as default font.
opts.DefaultFont = "Times New Roman";
sr = new SheetRender(ws, opts);
sr.ToImage(0, "times_new_roman_out.png");
// 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();
// Create workbook object from source file
Workbook workbook = new Workbook(sourceDir + "sampleWorksheetToImageDesiredSize.xlsx");
// Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Set image or print options we want one page per sheet. The image format is in png and desired dimensions are 400x400
Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions();
opts.OnePagePerSheet = true;
opts.ImageType = Drawing.ImageType.Png;
opts.SetDesiredSize(400, 400);
// Render sheet into image
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(worksheet, opts);
sr.ToImage(0, outputDir + "outputWorksheetToImageDesiredSize.png");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
Workbook wb = new Workbook(sourceDir + "SmartArt.xlsx");
foreach (Worksheet worksheet in wb.Worksheets)
{
foreach (Shape shape in worksheet.Shapes)
{
shape.AlternativeText = "ReplacedAlternativeText"; // This works fine just as the normal Shape objects do.
if (shape.IsSmartArt)
{
foreach (Shape smartart in shape.GetResultOfSmartArt().GetGroupedShapes())
{
smartart.Text = "ReplacedText"; // This doesn't update the text in Workbook which I save to the another file.
}
}
}
}
Aspose.Cells.OoxmlSaveOptions options = new Aspose.Cells.OoxmlSaveOptions();
options.UpdateSmartArt = true;
wb.Save(outputDir + "outputSmartArt.xlsx", 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();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
// Set the background image for the sheet.
sheet.BackgroundImage = File.ReadAllBytes(sourceDir + "background.jpg");
// Save the Excel file
workbook.Save(outputDir + "outputBackImageSheet.xlsx");
// Save the HTML file
workbook.Save(outputDir + "outputBackImageSheet.html", SaveFormat.Html);
// 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 an Excel file
Workbook wb = new Workbook(sourceDir + "sampleSetPixelFormatRenderedImage.xlsx");
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
// Set the ImageOrPrintOptions with desired pixel format (24 bits per pixel) and image format type
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.PixelFormat = PixelFormat.Format24bppRgb;
opts.ImageType = Drawing.ImageType.Tiff;
// Instantiate SheetRender object based on the first worksheet
SheetRender sr = new SheetRender(ws, opts);
// Save the image (first page of the sheet) with the specified options
sr.ToImage(0, outputDir + "outputSetPixelFormatRenderedImage.tiff");
// 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();
// Create workbook object
Workbook wb = new Workbook();
// Access first worksheet
Worksheet ws = wb.Worksheets[0];
// Add text box with these dimensions
TextBox tb = ws.Shapes.AddTextBox(2, 0, 2, 0, 100, 400);
// Set the text of the textbox
tb.Text = "This text has the following settings.\n\nText Effects > Shadow > Offset Bottom";
// Set all the text runs shadow to preset offset bottom
for (int i = 0; i < tb.TextBody.Count; i++)
{
tb.TextBody[i].TextOptions.Shadow.PresetType = PresetShadowType.OffsetBottom;
}
// Set the font color and size of the textbox
tb.Font.Color = Color.Red;
tb.Font.Size = 16;
// Save the output file
wb.Save(outputDir + "outputSettingTextEffectsShadowOfShapeOrTextbox.xlsx", SaveFormat.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();
// Open a template excel file
Workbook book = new Workbook(sourceDir + "sampleSpecificPagesToImages.xlsx");
// Get the first worksheet.
Worksheet sheet = book.Worksheets[0];
// Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
// Specify the image format
imgOptions.ImageType = Drawing.ImageType.Jpeg;
// Render the sheet with respect to specified image/print options
SheetRender sr = new SheetRender(sheet, imgOptions);
//Specify page index to be rendered
int idxPage = 3;
// Render the third image for the sheet
Bitmap bitmap = sr.ToImage(idxPage);
// Save the image file
bitmap.Save(outputDir + "outputSpecificPagesToImage_"+ (idxPage+1)+".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();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(sourceDir + "sampleUseWorkbookRenderForImageConversion.xlsx");
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.ImageType = Drawing.ImageType.Tiff;
WorkbookRender wr = new WorkbookRender(wb, opts);
wr.ToImage(outputDir + "outputUseWorkbookRenderForImageConversion.tiff");
// 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();
//Open template
Workbook book = new Workbook(sourceDir + "sampleWorksheetToAnImage.xlsx");
// Get the first worksheet
Worksheet sheet = book.Worksheets[0];
// Apply different Image and Print options
Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
// Set Horizontal Resolution
options.HorizontalResolution = 300;
// Set Vertical Resolution
options.VerticalResolution = 300;
// Set TiffCompression
options.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionLZW;
// Set Autofit options
options.IsCellAutoFit = false;
// Set Image Format
options.ImageType = Drawing.ImageType.Tiff;
// Set printing page type
options.PrintingPage = PrintingPageType.Default;
// Render the sheet with respect to specified image/print options
SheetRender sr = new SheetRender(sheet, options);
// Render/save the image for the sheet
int pageIndex = 3;
sr.ToImage(pageIndex, outputDir + @"outputWorksheetToAnImage_"+ (pageIndex + 1) + ".tiff");
// 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);
// Create workbook
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
// Set formula
Cell cell = cells[0, 0];
cell.SetArrayFormula("=MYFUNC()", 2, 2);
Style style = cell.GetStyle();
style.Number = 14;
cell.SetStyle(style);
// Set calculation options for formula
CalculationOptions calculationOptions = new CalculationOptions();
calculationOptions.CustomEngine = new CustomFunctionStaticValue();
workbook.CalculateFormula(calculationOptions);
// Save to xlsx by setting the calc mode to manual
workbook.Settings.CalcMode = CalcModeType.Manual;
workbook.Save(dataDir + "output_out.xlsx");
// Save to pdf
workbook.Save(dataDir + "output_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
public class CustomFunctionStaticValue : AbstractCalculationEngine
{
public override void Calculate(CalculationData data)
{
data.CalculatedValue = new object[][] {
new object[]{new DateTime(2015, 6, 12, 10, 6, 30), 2},
new object[]{3.0, "Test"}
};
}
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
public class CustomFunction : AbstractCalculationEngine
{
public override void Calculate(CalculationData data)
{
decimal total = 0M;
try
{
// Get value of first parameter
object firstParameter = data.GetParamValue(0);
Console.WriteLine(data.GetParamValue(0).GetType());
decimal firstParamB1 = 0;
if (firstParameter is ReferredArea)
{
ReferredArea ra = (ReferredArea)firstParameter;
firstParamB1 = System.Convert.ToDecimal(ra.GetValue(0, 0));
}
// Get value of second parameter
object secondParameter = data.GetParamValue(1);
Console.WriteLine(data.GetParamValue(1).GetType());
if (secondParameter is ReferredArea)
{
ReferredArea ra = (ReferredArea)secondParameter;
// get every item value of second parameter
foreach (object[] value in (Array)ra.GetValues())
{
total += System.Convert.ToDecimal(value[0]);
}
}
total = total / firstParamB1;
}
catch
{
}
// Result of the function
data.CalculatedValue = total;
}
}
// 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 the workbook
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Adding sample values to cells
worksheet.Cells["B1"].PutValue(5);
worksheet.Cells["C1"].PutValue(100);
worksheet.Cells["C2"].PutValue(150);
worksheet.Cells["C3"].PutValue(60);
worksheet.Cells["C4"].PutValue(32);
worksheet.Cells["C5"].PutValue(62);
// Adding custom formula to Cell A1
workbook.Worksheets[0].Cells["A1"].Formula = "=MyFunc(B1,C1:C5)";
// Set calculation options
CalculationOptions calculationOptions = new CalculationOptions();
calculationOptions.CustomEngine = new CustomFunction();
// Calcualting Formulas
workbook.CalculateFormula(calculationOptions);
// Assign resultant value to Cell A1
workbook.Worksheets[0].Cells["A1"].PutValue(workbook.Worksheets[0].Cells["A1"].Value);
// Save the file
workbook.Save(dataDir + "UsingAbstractCalculationEnginefeature_out.xls");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
Workbook workbook = new Workbook(sourceDir + "GetTextWidthSample.xlsx");
Console.WriteLine("Text width: " + CellsHelper.GetTextWidth(workbook.Worksheets[0].Cells["A1"].StringValue, workbook.DefaultStyle.Font, 1));
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
Workbook workbook = new Workbook(sourceDir + "SampleChangeTickLabelDirection.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Load the chart from source worksheet
Chart chart = worksheet.Charts[0];
chart.CategoryAxis.TickLabels.DirectionType = ChartTextDirectionType.Horizontal;
// Output the file
workbook.Save(outputDir + "outputChangeChartDataLableDirection.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 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
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a chart to the worksheet
int index = workbook.Worksheets.Add(SheetType.Chart);
Worksheet sheet = workbook.Worksheets[index];
sheet.Charts.AddFloatingChart(ChartType.Column, 0, 0, 1024, 960);
sheet.Charts[0].NSeries.Add("{1,2,3}", false);
// Add checkbox to the chart.
sheet.Charts[0].Shapes.AddShapeInChart(MsoDrawingType.CheckBox, PlacementType.Move, 400, 400, 1000, 600);
sheet.Charts[0].Shapes[0].Text = "CheckBox 1";
// Save the excel file.
workbook.Save(outputDir + "InsertCheckboxInChartSheet_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);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Adding sample values to cells
worksheet.Cells["A2"].PutValue("Category1");
worksheet.Cells["A3"].PutValue("Category2");
worksheet.Cells["A4"].PutValue("Category3");
worksheet.Cells["B1"].PutValue("Column1");
worksheet.Cells["B2"].PutValue(4);
worksheet.Cells["B3"].PutValue(20);
worksheet.Cells["B4"].PutValue(50);
worksheet.Cells["C1"].PutValue("Column2");
worksheet.Cells["C2"].PutValue(50);
worksheet.Cells["C3"].PutValue(100);
worksheet.Cells["C4"].PutValue(150);
// Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5);
// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
// Setting chart data source as the range "A1:C4"
chart.SetChartDataRange("A1:C4", true);
// Saving the Excel file
workbook.Save(dataDir + "output.xls");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// directories
string SourceDir = RunExamples.Get_SourceDirectory();
string outputDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook(SourceDir + "ValidationsSample.xlsx");
// Access first worksheet.
Worksheet worksheet = workbook.Worksheets[0];
// Accessing the Validations collection of the worksheet
Validation validation = worksheet.Validations[0];
// Create your cell area.
CellArea cellArea = CellArea.CreateCellArea("D5", "E7");
// Adding the cell area to Validation
validation.AddArea(cellArea, false, false);
// Save the output workbook.
workbook.Save(outputDir + "ValidationsSample_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();
// Create union range
UnionRange unionRange = workbook.Worksheets.CreateUnionRange("sheet1!A1:A10,sheet1!C1:C10", 0);
// Put value "ABCD" in the range
unionRange.Value = "ABCD";
// Save the output workbook.
workbook.Save(outputDir + "CreateUnionRange_out.xlsx");
// 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
// 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);
// Access your text box which is also a shape object from shapes collection
Shape shape = workbook.Worksheets[0].Shapes[0];
// Get all the connection points in this shape
var ConnectionPoints = shape.ConnectionPoints;
// Display all the shape points
foreach (var pt in ConnectionPoints)
{
System.Console.WriteLine(string.Format("X = {0}, Y = {1}", pt.X, pt.Y));
}
// 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
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions = new LoadOptions(LoadFormat.FODS);
// Create a Workbook object and opening the file from its path
Workbook workbook = new Workbook(sourceDir + "SampleFods.fods", loadOptions);
Console.WriteLine("FODS 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();
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions = new LoadOptions(LoadFormat.SXC);
// Create a Workbook object and opening the file from its path
Workbook workbook = new Workbook(sourceDir + "SampleSXC.sxc", loadOptions);
// Using the Sheet 1 in Workbook
Worksheet worksheet = workbook.Worksheets[0];
// Accessing a cell using its name
Cell cell = worksheet.Cells["C3"];
Console.WriteLine("Cell Name: " + cell.Name + " Value: " + cell.StringValue);
// 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();
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions = new LoadOptions(LoadFormat.TSV);
// Create a Workbook object and opening the file from its path
Workbook workbook = new Workbook(sourceDir + "SampleTSVFile.tsv", loadOptions);
// Using the Sheet 1 in Workbook
Worksheet worksheet = workbook.Worksheets[0];
// Accessing a cell using its name
Cell cell = worksheet.Cells["C3"];
Console.WriteLine("Cell Name: " + cell.Name + " Value: " + cell.StringValue);
// 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();
// Create a Workbook object and opening the file from its path
//Workbook workbook = new Workbook(sourceDir + "Book_CSV.csv", loadOptions);
Workbook workbook = new Workbook();
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[2, 2].Value = 4;
workbook.Save(outputDir + "SaveFODSFiles.fods", SaveFormat.SXC);
// 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
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Specify the file path
string filePath = dataDir + "Book1.xlsx";
// Load a spreadsheet to be converted
Workbook book = new Workbook(filePath);
// Create an instance of HtmlSaveOptions
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.Html);
// Set the ImageFormat to PNG
saveOptions.ImageOptions.ImageType = Drawing.ImageType.Png;
// Set SmoothingMode to AntiAlias
saveOptions.ImageOptions.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// Set TextRenderingHint to AntiAlias
saveOptions.ImageOptions.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
// Save spreadsheet to HTML while passing object of HtmlSaveOptions
book.Save( dataDir + "output.html", saveOptions);
// 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);
// Create a Stream object
FileStream fstream = new FileStream(dataDir + "EncryptedBook1.xlsx", FileMode.Open);
bool isPasswordValid = FileFormatUtil.VerifyPassword(fstream, "1234");
Console.WriteLine("Password is Valid: " + isPasswordValid);
// 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
//Load sample source file
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx");
HtmlSaveOptions options = new HtmlSaveOptions();
options.ExportHeadings = true;
// Save the workbook
workbook.Save(outputDir + "PrintHeadings_out.html", 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();
LoadOptions loadOptions = new LoadOptions(LoadFormat.CSV);
// Load CSV file
Workbook workbook = new Workbook(sourceDir + "SampleCsv.csv", loadOptions);
Cell lastCell = workbook.Worksheets[0].Cells.LastCell;
// Set ExportRangeToJsonOptions
ExportRangeToJsonOptions options = new ExportRangeToJsonOptions();
Range range = workbook.Worksheets[0].Cells.CreateRange(0, 0, lastCell.Row + 1, lastCell.Column + 1);
string data = JsonUtility.ExportRangeToJson(range, options);
// Print JSON
Console.WriteLine(data);
// 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.docx", SaveFormat.Docx);
// 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 + "AddTooltipToHtmlSample.xlsx");
HtmlSaveOptions options = new HtmlSaveOptions();
options.AddTooltipText = true;
// Save as Markdown
workbook.Save(outputDir + "AddTooltipToHtmlSample_out.html", options);
// 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
// Open the template file
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx");
// Save as Markdown
workbook.Save(outputDir + "Book1.pptx", SaveFormat.Pptx);
// 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();
// Read JSON file
string str = File.ReadAllText(sourceDir + "SampleJson.json");
// Create empty workbook
Workbook workbook = new Workbook();
// Get Cells
Cells cells = workbook.Worksheets[0].Cells;
// Set JsonLayoutOptions
JsonLayoutOptions importOptions = new JsonLayoutOptions();
importOptions.ConvertNumericOrDate = true;
importOptions.ArrayAsTable = true;
importOptions.IgnoreArrayTitle = true;
importOptions.IgnoreObjectTitle = true;
JsonUtility.ImportData(str, cells, 0, 0, importOptions);
// Save Workbook
workbook.Save(outputDir + @"SampleJson_out.csv");