-
-
Save PizzaShift/73abcc38fd4da99ce8d4bd53658c1593 to your computer and use it in GitHub Desktop.
This Gist contains CSharp code snippets for examples of Aspose.Cells for .NET.
This gist exceeds the recommended number of files (~10).
To access all files, please clone this gist.
This file contains hidden or 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
Aspose.Cells for .NET |
This file contains hidden or 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 sample Excel file containing the chart. | |
Workbook wb = new Workbook(sourceDir + "sampleCreateChartPDFWithDesiredPageSize.xlsx"); | |
//Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
//Access first chart inside the worksheet. | |
Chart ch = ws.Charts[0]; | |
//Create chart pdf with desired page size. | |
ch.ToPdf(outputDir + "outputCreateChartPDFWithDesiredPageSize.pdf", 7, 7, PageLayoutAlignmentType.Center, PageLayoutAlignmentType.Center); |
This file contains hidden or 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 sample Excel file containing chart. | |
Workbook wb = new Workbook(sourceDir + "sampleFindTypeOfXandYValuesOfPointsInChartSeries.xlsx"); | |
//Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
//Access first chart. | |
Chart ch = ws.Charts[0]; | |
//Calculate chart data. | |
ch.Calculate(); | |
//Access first chart point in the first series. | |
ChartPoint pnt = ch.NSeries[0].Points[0]; | |
//Print the types of X and Y values of chart point. | |
Console.WriteLine("X Value Type: " + pnt.XValueType); | |
Console.WriteLine("Y Value Type: " + pnt.YValueType); |
This file contains hidden or 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 the sample Excel file | |
Workbook wb = new Workbook("sampleHandleAutomaticUnitsOfChartAxisLikeMicrosoftExcel.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access first chart | |
Chart ch = ws.Charts[0]; | |
//Render chart to pdf | |
ch.ToPdf("outputHandleAutomaticUnitsOfChartAxisLikeMicrosoftExcel.pdf"); |
This file contains hidden or 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 the Excel file containing chart | |
Workbook wb = new Workbook("sampleReadAxisLabelsAfterCalculatingTheChart.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access the chart | |
Chart ch = ws.Charts[0]; | |
//Calculate the chart | |
ch.Calculate(); | |
//Read axis labels of category axis | |
ArrayList lstLabels = ch.CategoryAxis.AxisLabels; | |
//Print axis labels on console | |
Console.WriteLine("Category Axis Labels: "); | |
Console.WriteLine("---------------------"); | |
//Iterate axis labels and print them one by one | |
for (int i = 0; i < lstLabels.Count; i++) | |
{ | |
Console.WriteLine(lstLabels[i]); | |
} |
This file contains hidden or 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 sample Excel file containing cells with formatting. | |
Workbook wb = new Workbook(sourceDir + "sampleChangeCellsAlignmentAndKeepExistingFormatting.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Create cells range. | |
Range rng = ws.Cells.CreateRange("B2:D7"); | |
// Create style object. | |
Style st = wb.CreateStyle(); | |
// Set the horizontal and vertical alignment to center. | |
st.HorizontalAlignment = TextAlignmentType.Center; | |
st.VerticalAlignment = TextAlignmentType.Center; | |
// Create style flag object. | |
StyleFlag flag = new StyleFlag(); | |
// Set style flag alignments true. It is most crucial statement. | |
// Because if it will be false, no changes will take place. | |
flag.Alignments = true; | |
// Apply style to range of cells. | |
rng.ApplyStyle(st, flag); | |
// Save the workbook in XLSX format. | |
wb.Save(outputDir + "outputChangeCellsAlignmentAndKeepExistingFormatting.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 wb = new Workbook(); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Create range A1:B3. | |
Console.WriteLine("Creating Range A1:B3\n"); | |
Range rng = ws.Cells.CreateRange("A1:B3"); | |
// Print range address and cell count. | |
Console.WriteLine("Range Address: " + rng.Address); | |
Console.WriteLine("Cell Count: " + rng.CellCount); | |
// Formatting console output. | |
Console.WriteLine("----------------------"); | |
Console.WriteLine(""); | |
// Create range A1. | |
Console.WriteLine("Creating Range A1\n"); | |
rng = ws.Cells.CreateRange("A1"); | |
// Print range offset, entire column and entire row. | |
Console.WriteLine("Offset: " + rng.GetOffset(2, 2).Address); | |
Console.WriteLine("Entire Column: " + rng.EntireColumn.Address); | |
Console.WriteLine("Entire Row: " + rng.EntireRow.Address); | |
// Formatting console output. | |
Console.WriteLine("----------------------"); | |
Console.WriteLine(""); |
This file contains hidden or 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 workbook | |
Workbook wb = new Workbook(); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access cell A1 | |
Cell cell = ws.Cells["A1"]; | |
//Put some text in cell, it does not have Single Quote at the beginning | |
cell.PutValue("Text"); | |
//Access style of cell A1 | |
Style st = cell.GetStyle(); | |
//Print the value of Style.QuotePrefix of cell A1 | |
Console.WriteLine("Quote Prefix of Cell A1: " + st.QuotePrefix); | |
//Put some text in cell, it has Single Quote at the beginning | |
cell.PutValue("'Text"); | |
//Access style of cell A1 | |
st = cell.GetStyle(); | |
//Print the value of Style.QuotePrefix of cell A1 | |
Console.WriteLine("Quote Prefix of Cell A1: " + st.QuotePrefix); | |
//Print information about StyleFlag.QuotePrefix property | |
Console.WriteLine(); | |
Console.WriteLine("When StyleFlag.QuotePrefix is False, it means, do not update the value of Cell.Style.QuotePrefix."); | |
Console.WriteLine("Similarly, when StyleFlag.QuotePrefix is True, it means, update the value of Cell.Style.QuotePrefix."); | |
Console.WriteLine(); | |
//Create an empty style | |
st = wb.CreateStyle(); | |
//Create style flag - set StyleFlag.QuotePrefix as false | |
//It means, we do not want to update the Style.QuotePrefix property of cell A1's style. | |
StyleFlag flag = new StyleFlag(); | |
flag.QuotePrefix = false; | |
//Create a range consisting of single cell A1 | |
Range rng = ws.Cells.CreateRange("A1"); | |
//Apply the style to the range | |
rng.ApplyStyle(st, flag); | |
//Access the style of cell A1 | |
st = cell.GetStyle(); | |
//Print the value of Style.QuotePrefix of cell A1 | |
//It will print True, because we have not updated the Style.QuotePrefix property of cell A1's style. | |
Console.WriteLine("Quote Prefix of Cell A1: " + st.QuotePrefix); | |
//Create an empty style | |
st = wb.CreateStyle(); | |
//Create style flag - set StyleFlag.QuotePrefix as true | |
//It means, we want to update the Style.QuotePrefix property of cell A1's style. | |
flag = new StyleFlag(); | |
flag.QuotePrefix = true; | |
//Apply the style to the range | |
rng.ApplyStyle(st, flag); | |
//Access the style of cell A1 | |
st = cell.GetStyle(); | |
//Print the value of Style.QuotePrefix of cell A1 | |
//It will print False, because we have updated the Style.QuotePrefix property of cell A1's style. | |
Console.WriteLine("Quote Prefix of Cell A1: " + st.QuotePrefix); |
This file contains hidden or 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 | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace Aspose.Cells.Examples.CSharp.Data | |
{ | |
class SpecifyFormulaFieldsWhileImportingDataToWorksheet | |
{ | |
//Output directory | |
static string outputDir = RunExamples.Get_OutputDirectory(); | |
//User-defined class to hold data items | |
class DataItems | |
{ | |
public int Number1 { get; set; } | |
public int Number2 { get; set; } | |
public string Formula1 { get; set; } | |
public string Formula2 { get; set; } | |
} | |
public static void Run() | |
{ | |
//List to hold data items | |
List<DataItems> dis = new List<DataItems>(); | |
//Define 1st data item and add it in list | |
DataItems di = new DataItems(); | |
di.Number1 = 2002; | |
di.Number2 = 3502; | |
di.Formula1 = "=SUM(A2,B2)"; | |
di.Formula2 = "=HYPERLINK(\"https://www.aspose.com\",\"Aspose Website\")"; | |
dis.Add(di); | |
//Define 2nd data item and add it in list | |
di = new DataItems(); | |
di.Number1 = 2003; | |
di.Number2 = 3503; | |
di.Formula1 = "=SUM(A3,B3)"; | |
di.Formula2 = "=HYPERLINK(\"https://www.aspose.com\",\"Aspose Website\")"; | |
dis.Add(di); | |
//Define 3rd data item and add it in list | |
di = new DataItems(); | |
di.Number1 = 2004; | |
di.Number2 = 3504; | |
di.Formula1 = "=SUM(A4,B4)"; | |
di.Formula2 = "=HYPERLINK(\"https://www.aspose.com\",\"Aspose Website\")"; | |
dis.Add(di); | |
//Define 4th data item and add it in list | |
di = new DataItems(); | |
di.Number1 = 2005; | |
di.Number2 = 3505; | |
di.Formula1 = "=SUM(A5,B5)"; | |
di.Formula2 = "=HYPERLINK(\"https://www.aspose.com\",\"Aspose Website\")"; | |
dis.Add(di); | |
//Create workbook object | |
Workbook wb = new Workbook(); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Specify import table options | |
ImportTableOptions opts = new ImportTableOptions(); | |
//Specify which field is formula field, here the last two fields are formula fields | |
opts.IsFormulas = new bool[] { false, false, true, true }; | |
//Import custom objects | |
ws.Cells.ImportCustomObjects(dis, 0, 0, opts); | |
//Calculate formula | |
wb.CalculateFormula(); | |
//Autofit columns | |
ws.AutoFitColumns(); | |
//Save the output Excel file | |
wb.Save(outputDir + "outputSpecifyFormulaFieldsWhileImportingDataToWorksheet.xlsx"); | |
Console.WriteLine("SpecifyFormulaFieldsWhileImportingDataToWorksheet executed successfully."); | |
} | |
} | |
} |
This file contains hidden or 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 workbook object. | |
Workbook wb = new Workbook(); | |
//Access built-in document property collection. | |
Aspose.Cells.Properties.BuiltInDocumentPropertyCollection bdpc = wb.BuiltInDocumentProperties; | |
//Set the language of the Excel file. | |
bdpc.Language = "German, French"; | |
//Save the workbook in xlsx format. | |
wb.Save(outputDir + "outputSpecifyLanguageOfExcelFileUsingBuiltInDocumentProperties.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 the sample Excel file | |
Workbook wb = new Workbook("sampleAccessAndModifyLabelOfOleObject.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access first Ole Object | |
Aspose.Cells.Drawing.OleObject oleObject = ws.OleObjects[0]; | |
//Display the Label of the Ole Object | |
Console.WriteLine("Ole Object Label - Before: " + oleObject.Label); | |
//Modify the Label of the Ole Object | |
oleObject.Label = "Aspose APIs"; | |
//Save workbook to memory stream | |
MemoryStream ms = new MemoryStream(); | |
wb.Save(ms, SaveFormat.Xlsx); | |
//Set the workbook reference to null | |
wb = null; | |
//Load workbook from memory stream | |
wb = new Workbook(ms); | |
//Access first worksheet | |
ws = wb.Worksheets[0]; | |
//Access first Ole Object | |
oleObject = ws.OleObjects[0]; | |
//Display the Label of the Ole Object that has been modified earlier | |
Console.WriteLine("Ole Object Label - After: " + oleObject.Label); |
This file contains hidden or 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 sample Excel file containing gear type smart art shape. | |
Workbook wb = new Workbook("sampleExtractTextFromGearTypeSmartArtShape.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Access first shape. | |
Aspose.Cells.Drawing.Shape sh = ws.Shapes[0]; | |
// Get the result of gear type smart art shape in the form of group shape. | |
Aspose.Cells.Drawing.GroupShape gs = sh.GetResultOfSmartArt(); | |
// Get the list of individual shapes consisting of group shape. | |
Aspose.Cells.Drawing.Shape[] shps = gs.GetGroupedShapes(); | |
// Extract the text of gear type shapes and print them on console. | |
for (int i = 0; i < shps.Length; i++) | |
{ | |
Aspose.Cells.Drawing.Shape s = shps[i]; | |
if (s.Type == Aspose.Cells.Drawing.AutoShapeType.Gear9 || s.Type == Aspose.Cells.Drawing.AutoShapeType.Gear6) | |
{ | |
Console.WriteLine("Gear Type Shape Text: " + s.Text); | |
} | |
}//for |
This file contains hidden or 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 sample Excel file. | |
Workbook wb = new Workbook(sourceDir + "sampleRotateTextWithShapeInsideWorksheet.xlsx"); | |
//Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
//Access cell B4 and add message inside it. | |
Cell b4 = ws.Cells["B4"]; | |
b4.PutValue("Text is not rotating with shape because RotateTextWithShape is false."); | |
//Access first shape. | |
Shape sh = ws.Shapes[0]; | |
//Access shape text alignment. | |
Aspose.Cells.Drawing.Texts.ShapeTextAlignment shapeTextAlignment = sh.TextBody.TextAlignment; | |
//Do not rotate text with shape by setting RotateTextWithShape as false. | |
shapeTextAlignment.RotateTextWithShape = false; | |
//Save the output Excel file. | |
wb.Save(outputDir + "outputRotateTextWithShapeInsideWorksheet.xlsx"); |
This file contains hidden or 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 the sample Excel file | |
Workbook wb = new Workbook("sampleSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
foreach (Shape sh in ws.Shapes) | |
{ | |
//Access the text alignment | |
Aspose.Cells.Drawing.Texts.ShapeTextAlignment txtAlign = sh.TextBody.TextAlignment; | |
//Set auto margin false | |
txtAlign.IsAutoMargin = false; | |
//Set the top, left, bottom and right margins | |
txtAlign.TopMarginPt = 10; | |
txtAlign.LeftMarginPt = 10; | |
txtAlign.BottomMarginPt = 10; | |
txtAlign.RightMarginPt = 10; | |
} | |
//Save the output Excel file | |
wb.Save("outputSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx"); |
This file contains hidden or 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 wb = new Workbook(); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Add textbox inside the worksheet. | |
int idx = ws.TextBoxes.Add(5, 5, 50, 200); | |
Aspose.Cells.Drawing.TextBox tb = ws.TextBoxes[idx]; | |
// Set the text of the textbox. | |
tb.Text = "こんにちは世界"; | |
// Specify the Far East and Latin name of the font. | |
tb.TextOptions.LatinName = "Comic Sans MS"; | |
tb.TextOptions.FarEastName = "KaiTi"; | |
// Save the output Excel file. | |
wb.Save("outputSpecifyFarEastAndLatinNameOfFontInTextOptionsOfShape.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiating a WorkbookDesigner object | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
// Open a designer spreadsheet containing smart markers | |
designer.Workbook = new Workbook(designerFile); | |
// Set the data source for the designer spreadsheet | |
designer.SetDataSource(dataset); | |
// Process the smart markers | |
designer.Process(); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// 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=" + dataDir + "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(dataDir+ "TestSmartMarkers.xlsx"); | |
// 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(dataDir+ "output.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Get the image data. | |
byte[] imageData = File.ReadAllBytes(dataDir+ @"aspose-logo.jpg"); | |
// Create a datatable. | |
DataTable t = new DataTable("Table1"); | |
// Add a column to save pictures. | |
DataColumn dc = t.Columns.Add("Picture"); | |
// Set its data type. | |
dc.DataType = typeof(object); | |
// Add a new new record to it. | |
DataRow row = t.NewRow(); | |
row[0] = imageData; | |
t.Rows.Add(row); | |
// Add another record (having picture) to it. | |
imageData = File.ReadAllBytes(dataDir+ @"image2.jpg"); | |
row = t.NewRow(); | |
row[0] = imageData; | |
t.Rows.Add(row); | |
// Create WorkbookDesigner object. | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
// Open the template Excel file. | |
designer.Workbook = new Workbook(dataDir+ @"TestSmartMarkers.xlsx"); | |
// Set the datasource. | |
designer.SetDataSource(t); | |
// Process the markers. | |
designer.Process(); | |
// Save the Excel file. | |
designer.Workbook.Save(dataDir+ @"out_SmartBook.out.xls"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// ****** Program ****** | |
// Initialize WorkbookDesigner object | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
// Load the template file | |
designer.Workbook = new Workbook(dataDir + "SM_NestedObjects.xlsx"); | |
// Instantiate the List based on the class | |
System.Collections.Generic.ICollection<Individual> list = new System.Collections.Generic.List<Individual>(); | |
// Create an object for the Individual class | |
Individual p1 = new Individual("Damian", 30); | |
// Create the relevant Wife class for the Individual | |
p1.Wife = new Wife("Dalya", 28); | |
// Create another object for the Individual class | |
Individual p2 = new Individual("Mack", 31); | |
// Create the relevant Wife class for the Individual | |
p2.Wife = new Wife("Maaria", 29); | |
// Add the objects to the list | |
list.Add(p1); | |
list.Add(p2); | |
// Specify the DataSource | |
designer.SetDataSource("Individual", list); | |
// Process the markers | |
designer.Process(false); | |
// Save the Excel file. | |
designer.Workbook.Save(dataDir+ "out_SM_NestedObjects.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create Students DataTable | |
DataTable dtStudent = new DataTable("Student"); | |
// Define a field in it | |
DataColumn dcName = new DataColumn("Name", typeof(string)); | |
dtStudent.Columns.Add(dcName); | |
// Add three rows to it | |
DataRow drName1 = dtStudent.NewRow(); | |
DataRow drName2 = dtStudent.NewRow(); | |
DataRow drName3 = dtStudent.NewRow(); | |
drName1["Name"] = "John"; | |
drName2["Name"] = "Jack"; | |
drName3["Name"] = "James"; | |
dtStudent.Rows.Add(drName1); | |
dtStudent.Rows.Add(drName2); | |
dtStudent.Rows.Add(drName3); | |
string filePath = dataDir + "TestSmartMarkers.xlsx"; | |
// Create a workbook from Smart Markers template file | |
Workbook workbook = new Workbook(filePath); | |
// Instantiate a new WorkbookDesigner | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
// Specify the Workbook | |
designer.Workbook = workbook; | |
// Set the Data Source | |
designer.SetDataSource(dtStudent); | |
// Process the smart markers | |
designer.Process(); | |
dataDir = dataDir + "TestSmartMarkers_out.xlsx"; | |
// Save the Excel file | |
workbook.Save(dataDir, SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook excel = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = excel.Worksheets[0]; | |
// Restricting users to delete columns of the worksheet | |
worksheet.Protection.AllowDeletingColumn = false; | |
// Restricting users to delete row of the worksheet | |
worksheet.Protection.AllowDeletingRow = false; | |
// Restricting users to edit contents of the worksheet | |
worksheet.Protection.AllowEditingContent = false; | |
// Restricting users to edit objects of the worksheet | |
worksheet.Protection.AllowEditingObject = false; | |
// Restricting users to edit scenarios of the worksheet | |
worksheet.Protection.AllowEditingScenario = false; | |
// Restricting users to filter | |
worksheet.Protection.AllowFiltering = false; | |
// Allowing users to format cells of the worksheet | |
worksheet.Protection.AllowFormattingCell = true; | |
// Allowing users to format rows of the worksheet | |
worksheet.Protection.AllowFormattingRow = true; | |
// Allowing users to insert columns in the worksheet | |
worksheet.Protection.AllowFormattingColumn = true; | |
// Allowing users to insert hyperlinks in the worksheet | |
worksheet.Protection.AllowInsertingHyperlink = true; | |
// Allowing users to insert rows in the worksheet | |
worksheet.Protection.AllowInsertingRow = true; | |
// 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; | |
// Allowing users to sort | |
worksheet.Protection.AllowSorting = true; | |
// Allowing users to use pivot tables in the worksheet | |
worksheet.Protection.AllowUsingPivotTable = true; | |
// Saving the modified Excel file | |
excel.Save(dataDir + "output.xls", SaveFormat.Excel97To2003); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load your source excel file containing the external link | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access the first external link | |
ExternalLink externalLink = wb.Worksheets.ExternalLinks[0]; | |
//Print the data source of external link, it will print existing remote path | |
Console.WriteLine("External Link Data Source: " + externalLink.DataSource); | |
// Remove remote path and print new data source assign the new data source to external link and print again | |
string newDataSource = Path.GetFileName(externalLink.DataSource); | |
externalLink.DataSource = newDataSource; | |
Console.WriteLine("External Link Data Source After Removing Remote Path: " + externalLink.DataSource); | |
// Change the absolute path of the workbook, it will also change the external link path | |
wb.AbsolutePath = "C:\\Files\\Extra\\"; | |
// Now print the data source again | |
Console.WriteLine("External Link Data Source After Changing Workbook.AbsolutePath to Local Path: " + externalLink.DataSource); | |
// Change the absolute path of the workbook to some remote path, it will again affect the external link path | |
wb.AbsolutePath = "http://www.aspose.com/WebFiles/ExcelFiles/"; | |
// Now print the data source again | |
Console.WriteLine("External Link Data Source After Changing Workbook.AbsolutePath to Remote Path: " + externalLink.DataSource); |
This file contains hidden or 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 an object of the Workbook class | |
Workbook workbook = new Workbook(); | |
// Access first worksheet from the collection | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Add the TextBox to the worksheet | |
int idx = sheet.TextBoxes.Add(10, 10, 10, 10); | |
// Access newly created TextBox using its index & name it | |
TextBox tb1 = sheet.TextBoxes[idx]; | |
tb1.Name = "MyTextBox"; | |
// Set text for the TextBox | |
tb1.Text = "This is MyTextBox"; | |
// Access the same TextBox via its name | |
TextBox tb2 = sheet.TextBoxes["MyTextBox"]; | |
// Display the text of the TextBox accessed via name | |
Console.WriteLine(tb2.Text); | |
Console.WriteLine("Press any key to continue..."); | |
Console.ReadKey(); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook wb = new Workbook(); | |
// Access first worksheet | |
Worksheet sheet = wb.Worksheets[0]; | |
// Add Toggle Button ActiveX Control inside the Shape Collection | |
Shape s = sheet.Shapes.AddActiveXControl(ControlType.ToggleButton, 4, 0, 4, 0, 100, 30); | |
// Access the ActiveX control object and set its linked cell property | |
ActiveXControl c = s.ActiveXControl; | |
c.LinkedCell = "A1"; | |
// Save the worbook in xlsx format | |
wb.Save(dataDir + "AddActiveXControls_out.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet (default worksheet) in the workbook | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Get the cells | |
Cells cells = worksheet.Cells; | |
// Set the columns widths (A, B and C) | |
worksheet.Cells.SetColumnWidth(0, 24); | |
worksheet.Cells.SetColumnWidth(1, 24); | |
worksheet.Cells.SetColumnWidth(2, 24); | |
// Input date into the cells | |
cells["A1"].PutValue("KPIs"); | |
cells["A2"].PutValue("Total Turnover (Sales at List)"); | |
cells["A3"].PutValue("Total Gross Margin %"); | |
cells["A4"].PutValue("Total Net Margin %"); | |
cells["B1"].PutValue("UA Contract Size Group 4"); | |
cells["B2"].PutValue(19551794); | |
cells["B3"].PutValue(11.8070745566204); | |
cells["B4"].PutValue(11.858589818569); | |
cells["C1"].PutValue("UA Contract Size Group 3"); | |
cells["C2"].PutValue(8150131.66666667); | |
cells["C3"].PutValue(10.3168384396244); | |
cells["C4"].PutValue(11.3326931937091); | |
// Get the conditional icon's image data | |
byte[] imagedata = ConditionalFormattingIcon.GetIconImageData(IconSetType.TrafficLights31, 0); | |
// Create a stream based on the image data | |
MemoryStream stream = new MemoryStream(imagedata); | |
// Add the picture to the cell based on the stream | |
worksheet.Pictures.Add(1, 1, stream); | |
// Get the conditional icon's image data | |
byte[] imagedata1 = ConditionalFormattingIcon.GetIconImageData(IconSetType.Arrows3, 2); | |
// Create a stream based on the image data | |
MemoryStream stream1 = new MemoryStream(imagedata1); | |
// Add the picture to the cell based on the stream | |
worksheet.Pictures.Add(1, 2, stream1); | |
// Get the conditional icon's image data | |
byte[] imagedata2 = ConditionalFormattingIcon.GetIconImageData(IconSetType.Symbols3, 0); | |
// Create a stream based on the image data | |
MemoryStream stream2 = new MemoryStream(imagedata2); | |
// Add the picture to the cell based on the stream | |
worksheet.Pictures.Add(2, 1, stream2); | |
// Get the conditional icon's image data | |
byte[] imagedata3 = ConditionalFormattingIcon.GetIconImageData(IconSetType.Stars3, 0); | |
// Create a stream based on the image data | |
MemoryStream stream3 = new MemoryStream(imagedata3); | |
// Add the picture to the cell based on the stream | |
worksheet.Pictures.Add(2, 2, stream3); | |
// Get the conditional icon's image data | |
byte[] imagedata4 = ConditionalFormattingIcon.GetIconImageData(IconSetType.Boxes5, 1); | |
// Create a stream based on the image data | |
MemoryStream stream4 = new MemoryStream(imagedata4); | |
// Add the picture to the cell based on the stream | |
worksheet.Pictures.Add(3, 1, stream4); | |
// Get the conditional icon's image data | |
byte[] imagedata5 = ConditionalFormattingIcon.GetIconImageData(IconSetType.Flags3, 1); | |
// Create a stream based on the image data | |
MemoryStream stream5 = new MemoryStream(imagedata5); | |
// Add the picture to the cell based on the stream | |
worksheet.Pictures.Add(3, 2, stream5); | |
dataDir = dataDir + "outfile_cond_icons1.out.xlsx"; | |
// Save the Excel file | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new workbook | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Insert a string value to a cell | |
worksheet.Cells["C2"].PutValue("Image Hyperlink"); | |
// Set the 4th row height | |
worksheet.Cells.SetRowHeight(3, 100); | |
// Set the C column width | |
worksheet.Cells.SetColumnWidth(2, 21); | |
// Add a picture to the C4 cell | |
int index = worksheet.Pictures.Add(3, 2, 4, 3, dataDir+ "aspose-logo.jpg"); | |
// Get the picture object | |
Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[index]; | |
// Set the placement type | |
pic.Placement = PlacementType.FreeFloating; | |
// Add an image hyperlink | |
Aspose.Cells.Hyperlink hlink = pic.AddHyperlink("http:// Www.aspose.com/"); | |
// Specify the screen tip | |
hlink.ScreenTip = "Click to go to Aspose site"; | |
dataDir = dataDir + "ImageHyperlink.out.xls"; | |
// Save the Excel file | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
public class AddingAnonymousCustomObject | |
{ | |
public static void Run() | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Open a designer workbook | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
// Get worksheet Cells collection | |
Cells cells = designer.Workbook.Worksheets[0].Cells; | |
// Set Cell Values | |
cells["A1"].PutValue("Name"); | |
cells["B1"].PutValue("Age"); | |
// Set markers | |
cells["A2"].PutValue("&=Person.Name"); | |
cells["B2"].PutValue("&=Person.Age"); | |
// Create Array list | |
ArrayList list = new ArrayList(); | |
// Add custom objects to the list | |
list.Add(new Person("Simon", 30)); | |
list.Add(new Person("Johnson", 33)); | |
// Add designer's datasource | |
designer.SetDataSource("Person", list); | |
// Process designer | |
designer.Process(false); | |
dataDir = dataDir + "result.out.xls"; | |
// Save the resultant file | |
designer.Workbook.Save(dataDir); | |
Console.WriteLine("\nProcess completed successfully.\nFile saved at " + dataDir); | |
} | |
} | |
} | |
public class Person | |
{ | |
public String Name; | |
public int Age; | |
internal Person(string name,int age) | |
{ | |
this.Name = name; | |
this.Age = age; | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(FileFormatType.Xlsx); | |
// Add simple property without any type | |
workbook.ContentTypeProperties.Add("MK31", "Simple Data"); | |
// Add date time property with type | |
workbook.ContentTypeProperties.Add("MK32", "04-Mar-2015", "DateTime"); | |
// Save the workbook | |
workbook.Save(dataDir + "AddingCustomPropertiesVisible_out.xlsx"); |
This file contains hidden or 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 | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string outputPath = dataDir + "Output.out.xlsm"; | |
Workbook workbook = new Workbook(); | |
VbaProject vbaProj = workbook.VbaProject; | |
vbaProj.References.AddRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation"); | |
vbaProj.References.AddRegisteredReference("Office", "*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE14\\MSO.DLL#Microsoft Office 14.0 Object Library"); | |
workbook.Save(outputPath); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new workbook | |
Workbook workbook = new Workbook(); | |
// Get the cells in the first(default) worksheet | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Get the A1 cell | |
Aspose.Cells.Cell p = cells["A1"]; | |
// Enter a value | |
p.PutValue("Preface"); | |
// Get the A10 cell | |
Aspose.Cells.Cell A = cells["A10"]; | |
// Enter a value. | |
A.PutValue("page1"); | |
// Get the H15 cell | |
Aspose.Cells.Cell D = cells["H15"]; | |
// Enter a value | |
D.PutValue("page1(H15)"); | |
// Add a new worksheet to the workbook | |
workbook.Worksheets.Add(); | |
// Get the cells in the second sheet | |
cells = workbook.Worksheets[1].Cells; | |
// Get the B10 cell in the second sheet | |
Aspose.Cells.Cell B = cells["B10"]; | |
// Enter a value | |
B.PutValue("page2"); | |
// Add a new worksheet to the workbook | |
workbook.Worksheets.Add(); | |
// Get the cells in the third sheet | |
cells = workbook.Worksheets[2].Cells; | |
// Get the C10 cell in the third sheet | |
Aspose.Cells.Cell C = cells["C10"]; | |
// Enter a value | |
C.PutValue("page3"); | |
// Create a main PDF Bookmark entry object | |
Aspose.Cells.Rendering.PdfBookmarkEntry pbeRoot = new Aspose.Cells.Rendering.PdfBookmarkEntry(); | |
// Specify its text | |
pbeRoot.Text = "Sections"; | |
// Set the destination cell/location | |
pbeRoot.Destination = p; | |
// Set its sub entry array list | |
pbeRoot.SubEntry = new ArrayList(); | |
// Create a sub PDF Bookmark entry object | |
Aspose.Cells.Rendering.PdfBookmarkEntry subPbe1 = new Aspose.Cells.Rendering.PdfBookmarkEntry(); | |
// Specify its text | |
subPbe1.Text = "Section 1"; | |
// Set its destination cell | |
subPbe1.Destination = A; | |
// Define/Create a sub Bookmark entry object of "Section A" | |
Aspose.Cells.Rendering.PdfBookmarkEntry ssubPbe = new Aspose.Cells.Rendering.PdfBookmarkEntry(); | |
// Specify its text | |
ssubPbe.Text = "Section 1.1"; | |
// Set its destination | |
ssubPbe.Destination = D; | |
// Create/Set its sub entry array list object | |
subPbe1.SubEntry = new ArrayList(); | |
// Add the object to "Section 1" | |
subPbe1.SubEntry.Add(ssubPbe); | |
// Add the object to the main PDF root object | |
pbeRoot.SubEntry.Add(subPbe1); | |
// Create a sub PDF Bookmark entry object | |
Aspose.Cells.Rendering.PdfBookmarkEntry subPbe2 = new Aspose.Cells.Rendering.PdfBookmarkEntry(); | |
// Specify its text | |
subPbe2.Text = "Section 2"; | |
// Set its destination | |
subPbe2.Destination = B; | |
// Add the object to the main PDF root object | |
pbeRoot.SubEntry.Add(subPbe2); | |
// Create a sub PDF Bookmark entry object | |
Aspose.Cells.Rendering.PdfBookmarkEntry subPbe3 = new Aspose.Cells.Rendering.PdfBookmarkEntry(); | |
// Specify its text | |
subPbe3.Text = "Section 3"; | |
// Set its destination | |
subPbe3.Destination = C; | |
// Add the object to the main PDF root object | |
pbeRoot.SubEntry.Add(subPbe3); | |
// Create an instance of PdfSaveOptions | |
Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions(); | |
// Set the PDF Bookmark root object | |
pdfSaveOptions.Bookmark = pbeRoot; | |
dataDir = dataDir+ "PDFBookmarks_test.out.pdf"; | |
// Save the pdf file | |
workbook.Save(dataDir, pdfSaveOptions); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a Workbook | |
Workbook workbook = new Workbook(); | |
// Get a reference of comments collection with the first sheet | |
CommentCollection comments = workbook.Worksheets[0].Comments; | |
// Add a comment to cell A1 | |
int commentIndex = comments.Add(0, 0); | |
Comment comment = comments[commentIndex]; | |
comment.Note = "First note."; | |
comment.Font.Name = "Times New Roman"; | |
// Load an image into stream | |
Bitmap bmp = new Bitmap(dataDir + "image2.jpg"); | |
MemoryStream ms = new MemoryStream(); | |
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); | |
// Set image data to the shape associated with the comment | |
comment.CommentShape.Fill.ImageData = ms.ToArray(); | |
dataDir = dataDir + "commentwithpicture1.out.xlsx"; | |
// Save the workbook | |
workbook.Save(dataDir, Aspose.Cells.SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook wb = new Workbook(); | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Add Word Art Text with Built-in Styles | |
ws.Shapes.AddWordArt(PresetWordArtStyle.WordArtStyle1, "Aspose File Format APIs", 00, 0, 0, 0, 100, 800); | |
ws.Shapes.AddWordArt(PresetWordArtStyle.WordArtStyle2, "Aspose File Format APIs", 10, 0, 0, 0, 100, 800); | |
ws.Shapes.AddWordArt(PresetWordArtStyle.WordArtStyle3, "Aspose File Format APIs", 20, 0, 0, 0, 100, 800); | |
ws.Shapes.AddWordArt(PresetWordArtStyle.WordArtStyle4, "Aspose File Format APIs", 30, 0, 0, 0, 100, 800); | |
ws.Shapes.AddWordArt(PresetWordArtStyle.WordArtStyle5, "Aspose File Format APIs", 40, 0, 0, 0, 100, 800); | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook | |
Workbook workbook = new Workbook(); | |
// Get the first default sheet | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Add Watermark | |
Aspose.Cells.Drawing.Shape wordart = sheet.Shapes.AddTextEffect(MsoPresetTextEffect.TextEffect1, | |
"CONFIDENTIAL", "Arial Black", 50, false, true | |
, 18, 8, 1, 1, 130, 800); | |
// Get the fill format of the word art | |
FillFormat wordArtFormat = wordart.Fill; | |
// Set the transparency | |
wordArtFormat.Transparency = 0.9; | |
// Make the line invisible | |
LineFormat lineFormat = wordart.Line; | |
dataDir = dataDir + "Watermark_Test.out.xls"; | |
// Save the file | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook wb = new Workbook(); | |
// Add xml map found inside the sample.xml inside the workbook | |
wb.Worksheets.XmlMaps.Add(dataDir + "sample.xml"); | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// 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); | |
// Adds condition. | |
int conditionIndex = 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(dataDir+ "output.out.xls", SaveFormat.Auto); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// 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 = new CellArea(); | |
ca.StartRow = 2; | |
ca.EndRow = 2; | |
ca.StartColumn = 1; | |
ca.EndColumn = 1; | |
fcs.AddArea(ca); | |
// Adds condition. | |
int conditionIndex = fcs.AddCondition(FormatConditionType.Expression); | |
// Sets the background color. | |
FormatCondition fc = fcs[conditionIndex]; | |
fc.Formula1 = "=IF(SUM(B1:B2)>100,TRUE,FALSE)"; | |
fc.Style.BackgroundColor = Color.Red; | |
sheet.Cells["B3"].Formula = "=SUM(B1:B2)"; | |
sheet.Cells["C4"].PutValue("If Sum of B1:B2 is greater than 100, B3 will have RED background"); | |
// Saving the Excel file | |
workbook.Save(dataDir+ "output.out.xls", SaveFormat.Auto); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// 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("Hello"); | |
// Setting the font Subscript | |
Style style = cell.GetStyle(); | |
style.Font.IsSubscript = true; | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir+ "Subscript.out.xls", SaveFormat.Auto); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// 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("Hello"); | |
// Setting the font Superscript | |
Style style = cell.GetStyle(); | |
style.Font.IsSuperscript = true; | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir+ "Superscript.out.xls", SaveFormat.Auto); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
if (!System.IO.Directory.Exists(dataDir)) | |
{ | |
System.IO.Directory.CreateDirectory(dataDir); | |
} | |
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(); | |
Aspose.Cells.Worksheet sheet = workbook.Worksheets[0]; | |
int moduleIdx = workbook.VbaProject.Modules.Add(sheet); | |
Aspose.Cells.Vba.VbaModule module = workbook.VbaProject.Modules[moduleIdx]; | |
module.Codes = | |
"Sub ShowMessage()" + "\r\n" + | |
" MsgBox \"Welcome to Aspose!\"" + "\r\n" + | |
"End Sub"; | |
Aspose.Cells.Drawing.Button button = sheet.Shapes.AddButton(2, 0, 2, 0, 28, 80); | |
button.Placement = Aspose.Cells.Drawing.PlacementType.FreeFloating; | |
button.Font.Name = "Tahoma"; | |
button.Font.IsBold = true; | |
button.Font.Color = System.Drawing.Color.Blue; | |
button.Text = "Aspose"; | |
button.MacroName = sheet.Name + ".ShowMessage"; | |
dataDir = dataDir + "Output.out.xlsm"; | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Program test = new MyTest(); | |
// Test.testSign(); | |
// Test.testvalidateSign(); | |
Console.ReadLine(); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// 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.AutoFitMergedCells = true; | |
// Autofit rows in the sheet(including the merged cells) | |
_worksheet.AutoFitRows(options); | |
dataDir = dataDir + "AutoFitMergedCells.out.xlsx"; | |
// Save the Excel file | |
wb.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Sample Html containing large number with digits greater than 15 | |
string html = "<html><body><p>1234567890123456</p></body></html>"; | |
// Convert Html to byte array | |
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(html); | |
// Set Html load options and keep precision true | |
HTMLLoadOptions loadOptions = new Aspose.Cells.HTMLLoadOptions(LoadFormat.Html); | |
loadOptions.KeepPrecision = true; | |
// Convert byte array into stream | |
MemoryStream stream = new MemoryStream(byteArray); | |
// Create workbook from stream with Html load options | |
Workbook workbook = new Workbook(stream, loadOptions); | |
// Access first worksheet | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Auto fit the sheet columns | |
sheet.AutoFitColumns(); | |
dataDir = dataDir + "AvoidExponentialNotationOfHTML.xlsx"; | |
// Save the workbook | |
workbook.Save(dataDir, SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string inputPath = dataDir + "Sample1.xlsx"; | |
string outputPath = dataDir + "Output.out.html"; | |
Workbook workbook = new Workbook(dataDir + "Sample1.xlsx"); | |
HtmlSaveOptions opts = new HtmlSaveOptions(); | |
opts.LinkTargetType = HtmlLinkTargetType.Self; | |
workbook.Save(outputPath, opts); | |
Console.WriteLine("File saved: {0}", outputPath); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook | |
var wb = new Workbook(); | |
// Get the first worksheet | |
var sheet = wb.Worksheets[0]; | |
// Add a comment to A1 cell | |
var comment = sheet.Comments[sheet.Comments.Add("A1")]; | |
// Set its vertical alignment setting | |
comment.CommentShape.TextVerticalAlignment = TextAlignmentType.Center; | |
// Set its horizontal alignment setting | |
comment.CommentShape.TextHorizontalAlignment = TextAlignmentType.Right; | |
// Set the Text Direction - Right-to-Left | |
comment.CommentShape.TextDirection = TextDirectionType.RightToLeft; | |
// Set the Comment note | |
comment.Note = "This is my Comment Text. This is test"; | |
dataDir = dataDir + "OutCommentShape.out.xlsx"; | |
// Save the Excel file | |
wb.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the template file. | |
Workbook workbook = new Workbook(dataDir + "Sample.xlsx"); | |
// Access the first worksheet | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Access the first chart inside the sheet | |
Chart chart = sheet.Charts[0]; | |
// Set text of second legend entry fill to none | |
chart.Legend.LegendEntries[1].IsTextNoFill = true; | |
// Save the workbook in xlsx format | |
workbook.Save(dataDir + "ChartLegendEntry_out.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "Sample1.xlsx"); | |
Console.WriteLine("VBA Project is Signed: " + workbook.VbaProject.IsSigned); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Define the first source | |
// Open the first excel file. | |
Workbook SourceBook1 = new Workbook(dataDir+ "SampleChart.xlsx"); | |
// Define the second source book. | |
// Open the second excel file. | |
Workbook SourceBook2 = new Workbook(dataDir+ "SampleImage.xlsx"); | |
// Combining the two workbooks | |
SourceBook1.Combine(SourceBook2); | |
dataDir = dataDir + "Combined.out.xlsx"; | |
// Save the target book file. | |
SourceBook1.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filePath = dataDir+ "SampleInput.xlsx"; | |
Workbook workbook = new Workbook(filePath); | |
Workbook destWorkbook = new Workbook(); | |
Worksheet destSheet = destWorkbook.Worksheets[0]; | |
int TotalRowCount = 0; | |
for (int i = 0; i < workbook.Worksheets.Count; i++) | |
{ | |
Worksheet sourceSheet = workbook.Worksheets[i]; | |
Range sourceRange = sourceSheet.Cells.MaxDisplayRange; | |
Range destRange = destSheet.Cells.CreateRange(sourceRange.FirstRow + TotalRowCount, sourceRange.FirstColumn, | |
sourceRange.RowCount, sourceRange.ColumnCount); | |
destRange.Copy(sourceRange); | |
TotalRowCount = sourceRange.RowCount + TotalRowCount; | |
} | |
dataDir = dataDir + "Output.out.xlsx"; | |
destWorkbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the existing excel file which contains the column chart. | |
Workbook workbook = new Workbook(dataDir+ "ColumnChart.xlsx"); | |
// Get the designer chart (first chart) in the first worksheet of the workbook. | |
Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; | |
// Convert the chart to an image file. | |
chart.ToImage(dataDir+ "ColumnChart.out.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the existing excel file which contains the pie chart. | |
Workbook workbook = new Workbook(dataDir+ "PieChart.xlsx"); | |
// Get the designer chart (first chart) in the first worksheet of the workbook. | |
Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; | |
// Convert the chart to an image file. | |
chart.ToImage(dataDir+ "PieChart.out.emf", System.Drawing.Imaging.ImageFormat.Emf); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook book = new Workbook(dataDir+ "TestData.xlsx"); | |
Worksheet sheet = book.Worksheets[0]; | |
Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions(); | |
options.HorizontalResolution = 200; | |
options.VerticalResolution = 200; | |
options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff; | |
// Sheet2Image By Page conversion | |
SheetRender sr = new SheetRender(sheet, options); | |
for (int j = 0; j < sr.PageCount; j++) | |
{ | |
sr.ToImage(j, dataDir+ "test" + sheet.Name + " Page" + (j + 1) + ".out.tif"); | |
} | |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open a template excel file | |
Workbook book = new Workbook(dataDir+ "Testbook.xlsx"); | |
// Get the first worksheet. | |
Worksheet sheet = book.Worksheets[0]; | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Specify the image format | |
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.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(dataDir+ "SheetImage.out.jpg"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
try | |
{ | |
// Get the template excel file path. | |
string designerFile = dataDir + "SampleInput.xlsx"; | |
// Specify the pdf file path. | |
string pdfFile = dataDir + "Output.out.pdf"; | |
// Open the template excel file | |
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(designerFile); | |
// Save the pdf file. | |
wb.Save(pdfFile, SaveFormat.Pdf); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
Console.ReadLine(); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first Worksheet Cells. | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Fill some sample data into the cells. | |
for (int i = 0; i < 50; i++) | |
{ | |
for (int j = 0; j < 10; j++) | |
{ | |
cells[i, j].PutValue(i.ToString() + "," + j.ToString()); | |
} | |
} | |
// Create a range (A1:D3). | |
Range range = cells.CreateRange("A1", "D3"); | |
// Create a style object. | |
Style style; | |
style = workbook.CreateStyle(); | |
// Specify the font attribute. | |
style.Font.Name = "Calibri"; | |
// Specify the shading color. | |
style.ForegroundColor = Color.Yellow; | |
style.Pattern = BackgroundType.Solid; | |
// Specify the border attributes. | |
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.TopBorder].Color = Color.Blue; | |
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.BottomBorder].Color = Color.Blue; | |
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.LeftBorder].Color = Color.Blue; | |
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.RightBorder].Color = Color.Blue; | |
// Create the styleflag object. | |
StyleFlag flag1 = new StyleFlag(); | |
// Implement font attribute | |
flag1.FontName = true; | |
// Implement the shading / fill color. | |
flag1.CellShading = true; | |
// Implment border attributes. | |
flag1.Borders = true; | |
// Set the Range style. | |
range.ApplyStyle(style, flag1); | |
// Create a second range (C10:F12). | |
Range range2 = cells.CreateRange("C10", "F12"); | |
// Copy the range data only. | |
range2.CopyData(range); | |
dataDir = dataDir + "CopyRangeData.out.xlsx"; | |
// Save the excel file. | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first Worksheet Cells. | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Fill some sample data into the cells. | |
for (int i = 0; i < 50; i++) | |
{ | |
for (int j = 0; j < 10; j++) | |
{ | |
cells[i, j].PutValue(i.ToString() + "," + j.ToString()); | |
} | |
} | |
// Create a range (A1:D3). | |
Range range = cells.CreateRange("A1", "D3"); | |
// Create a style object. | |
Style style; | |
style = workbook.CreateStyle(); | |
// Specify the font attribute. | |
style.Font.Name = "Calibri"; | |
// Specify the shading color. | |
style.ForegroundColor = Color.Yellow; | |
style.Pattern = BackgroundType.Solid; | |
// Specify the border attributes. | |
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.TopBorder].Color = Color.Blue; | |
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.BottomBorder].Color = Color.Blue; | |
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.LeftBorder].Color = Color.Blue; | |
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.RightBorder].Color = Color.Blue; | |
// Create the styleflag object. | |
StyleFlag flag1 = new StyleFlag(); | |
// Implement font attribute | |
flag1.FontName = true; | |
// Implement the shading / fill color. | |
flag1.CellShading = true; | |
// Implment border attributes. | |
flag1.Borders = true; | |
// Set the Range style. | |
range.ApplyStyle(style, flag1); | |
// Create a second range (C10:F12). | |
Range range2 = cells.CreateRange("C10", "F12"); | |
// Copy the range data with formatting. | |
range2.Copy(range); | |
dataDir = dataDir + "CopyRange.out.xlsx"; | |
// Save the excel file. | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first Worksheet Cells. | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Fill some sample data into the cells. | |
for (int i = 0; i < 50; i++) | |
{ | |
for (int j = 0; j < 10; j++) | |
{ | |
cells[i, j].PutValue(i.ToString() + "," + j.ToString()); | |
} | |
} | |
// Create a range (A1:D3). | |
Range range = cells.CreateRange("A1", "D3"); | |
// Create a style object. | |
Style style; | |
style = workbook.CreateStyle(); | |
// Specify the font attribute. | |
style.Font.Name = "Calibri"; | |
// Specify the shading color. | |
style.ForegroundColor = Color.Yellow; | |
style.Pattern = BackgroundType.Solid; | |
// Specify the border attributes. | |
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.TopBorder].Color = Color.Blue; | |
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.BottomBorder].Color = Color.Blue; | |
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.LeftBorder].Color = Color.Blue; | |
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; | |
style.Borders[BorderType.RightBorder].Color = Color.Blue; | |
// Create the styleflag object. | |
StyleFlag flag1 = new StyleFlag(); | |
// Implement font attribute | |
flag1.FontName = true; | |
// Implement the shading / fill color. | |
flag1.CellShading = true; | |
// Implment border attributes. | |
flag1.Borders = true; | |
// Set the Range style. | |
range.ApplyStyle(style, flag1); | |
// Create a second range (C10:E13). | |
Range range2 = cells.CreateRange("C10", "E13"); | |
// Copy the range style only. | |
range2.CopyStyle(range); | |
dataDir = dataDir + "copyrangestyle.out.xls"; | |
// Save the excel file. | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook | |
// Open an existing excel file | |
Workbook workbook = new Workbook(dataDir+ "aspose-sample.xlsx"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Get the Cells collection | |
Cells cells = worksheet.Cells; | |
// Copy the first column to the third column | |
cells.CopyColumn(cells, 0, 2); | |
// Save the excel file | |
workbook.Save(dataDir+ "outaspose-sample.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook class by loading the existing spreadsheet | |
Workbook workbook = new Workbook(dataDir + "aspose-sample.xlsx"); | |
// Get the cells collection of worksheet by name Columns | |
Cells cells = workbook.Worksheets["Columns"].Cells; | |
// Copy the first 3 columns 7th column | |
cells.CopyColumns(cells, 0, 6, 3); | |
// Save the result on disc | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook class by loading the existing spreadsheet | |
Workbook workbook = new Workbook(dataDir + "aspose-sample.xlsx"); | |
// Get the cells collection of worksheet by name Rows | |
Cells cells = workbook.Worksheets["Rows"].Cells; | |
// Copy the first 3 rows to 7th row | |
cells.CopyRows(cells, 0, 6, 3); | |
// Save the result on disc | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new workbook | |
// Open an existing excel file | |
Workbook workbook = new Workbook(dataDir+ "aspose-sample.xlsx"); | |
// Get the first worksheet cells | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Apply formulas to the cells | |
for (int i = 0; i < 5; i++) | |
{ | |
cells[0, i].Formula = "=Input!" + cells[0, i].Name; | |
} | |
// Copy the first row to next 10 rows | |
cells.CopyRows(cells, 0, 1, 10); | |
// Save the excel file | |
workbook.Save(dataDir + "outaspose-sample.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook | |
// Open an existing excel file | |
Workbook workbook = new Workbook(dataDir+ "aspose-sample.xlsx"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Get the Cells collection | |
Cells cells = worksheet.Cells; | |
//Copy the first column to next 10 columns | |
for (int i = 1; i <= 10; i++) | |
{ | |
cells.CopyColumn(cells, 0, i); | |
} | |
// Save the excel file | |
workbook.Save(dataDir+ "outaspose-sample.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new workbook | |
// Open an existing excel file | |
Workbook workbook = new Workbook(dataDir+ "aspose-sample.xlsx"); | |
// Get the first worksheet cells | |
Cells cells = workbook.Worksheets[0].Cells; | |
//Copy the first row to next 10 rows | |
for (int i = 1; i <= 10; i++) | |
{ | |
cells.CopyRow(cells, 0, i); | |
} | |
// Save the excel file | |
workbook.Save(dataDir + "outaspose-sample.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook object | |
// Open the template file | |
Workbook workbook = new Workbook(dataDir+ "aspose-sample.xlsx"); | |
// Get the Chart from the "Chart" worksheet. | |
Aspose.Cells.Charts.Chart source = workbook.Worksheets["Sheet2"].Charts[0]; | |
Aspose.Cells.Drawing.ChartShape cshape = source.ChartObject; | |
// Copy the Chart to the Result Worksheet | |
workbook.Worksheets["Sheet3"].Shapes.AddCopy(cshape, 20, 0, 2, 0); | |
// Save the Worksheet | |
workbook.Save(dataDir+ "Shapes.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook object | |
// Open the template file | |
Workbook workbook = new Workbook(dataDir+ "aspose-sample.xlsx"); | |
// Get the Shapes from the "Control" worksheet. | |
Aspose.Cells.Drawing.ShapeCollection shape = workbook.Worksheets["Sheet3"].Shapes; | |
// Copy the Textbox to the Result Worksheet | |
workbook.Worksheets["Sheet1"].Shapes.AddCopy(shape[0], 5, 0, 2, 0); | |
// Copy the Oval Shape to the Result Worksheet | |
workbook.Worksheets["Sheet1"].Shapes.AddCopy(shape[1], 10, 0, 2, 0); | |
// Save the Worksheet | |
workbook.Save(dataDir+ "Controls.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook object | |
// Open the template file | |
Workbook workbook = new Workbook(dataDir+ "aspose-sample.xlsx"); | |
// Get the Picture from the "Picture" worksheet. | |
Aspose.Cells.Drawing.Picture source = workbook.Worksheets["Sheet1"].Pictures[0]; | |
// Save Picture to Memory Stream | |
MemoryStream ms = new MemoryStream(source.Data); | |
// Copy the picture to the Result Worksheet | |
workbook.Worksheets["Sheet2"].Pictures.Add(source.UpperLeftRow, source.UpperLeftColumn, ms, source.WidthScale, source.HeightScale); | |
// Save the Worksheet | |
workbook.Save(dataDir+ "Shapes.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate the Workbook | |
// Load an Excel file | |
Workbook workbook = new Workbook(dataDir+ "aspose-sample.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
if (worksheet.Scenarios.Count > 0) | |
{ | |
// Remove the existing first scenario from the sheet | |
worksheet.Scenarios.RemoveAt(0); | |
// Create a scenario | |
int i = worksheet.Scenarios.Add("MyScenario"); | |
// Get the scenario | |
Scenario scenario = worksheet.Scenarios[i]; | |
// Add comment to it | |
scenario.Comment = "Test sceanrio is created."; | |
// Get the input cells for the scenario | |
ScenarioInputCellCollection sic = scenario.InputCells; | |
// Add the scenario on B4 (as changing cell) with default value | |
sic.Add(3, 1, "1100000"); | |
dataDir = dataDir + "outBk_scenarios1.out.xlsx"; | |
// Save the Excel file. | |
workbook.Save(dataDir); | |
Console.WriteLine("\nProcess completed successfully.\nFile saved at " + dataDir); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating an Workbook object | |
// Opening the excel file | |
Workbook workbook = new Workbook(dataDir+ "pivotTable_test.xlsx"); | |
// Adding a new sheet | |
Worksheet sheet3 = workbook.Worksheets[workbook.Worksheets.Add(SheetType.Chart)]; | |
// Naming the sheet | |
sheet3.Name = "PivotChart"; | |
// Adding a column chart | |
int index = sheet3.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 0, 5, 28, 16); | |
// Setting the pivot chart data source | |
sheet3.Charts[index].PivotSource = "PivotTable!PivotTable1"; | |
sheet3.Charts[index].HidePivotFieldButtons = false; | |
// Saving the Excel file | |
workbook.Save(dataDir+ "pivotChart_test_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating an Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the first worksheet | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Name the sheet | |
sheet.Name = "Data"; | |
Cells cells = sheet.Cells; | |
// Setting the values to the cells | |
Cell cell = cells["A1"]; | |
cell.PutValue("Employee"); | |
cell = cells["B1"]; | |
cell.PutValue("Quarter"); | |
cell = cells["C1"]; | |
cell.PutValue("Product"); | |
cell = cells["D1"]; | |
cell.PutValue("Continent"); | |
cell = cells["E1"]; | |
cell.PutValue("Country"); | |
cell = cells["F1"]; | |
cell.PutValue("Sale"); | |
cell = cells["A2"]; | |
cell.PutValue("David"); | |
cell = cells["A3"]; | |
cell.PutValue("David"); | |
cell = cells["A4"]; | |
cell.PutValue("David"); | |
cell = cells["A5"]; | |
cell.PutValue("David"); | |
cell = cells["A6"]; | |
cell.PutValue("James"); | |
cell = cells["A7"]; | |
cell.PutValue("James"); | |
cell = cells["A8"]; | |
cell.PutValue("James"); | |
cell = cells["A9"]; | |
cell.PutValue("James"); | |
cell = cells["A10"]; | |
cell.PutValue("James"); | |
cell = cells["A11"]; | |
cell.PutValue("Miya"); | |
cell = cells["A12"]; | |
cell.PutValue("Miya"); | |
cell = cells["A13"]; | |
cell.PutValue("Miya"); | |
cell = cells["A14"]; | |
cell.PutValue("Miya"); | |
cell = cells["A15"]; | |
cell.PutValue("Miya"); | |
cell = cells["A16"]; | |
cell.PutValue("Miya"); | |
cell = cells["A17"]; | |
cell.PutValue("Miya"); | |
cell = cells["A18"]; | |
cell.PutValue("Elvis"); | |
cell = cells["A19"]; | |
cell.PutValue("Elvis"); | |
cell = cells["A20"]; | |
cell.PutValue("Elvis"); | |
cell = cells["A21"]; | |
cell.PutValue("Elvis"); | |
cell = cells["A22"]; | |
cell.PutValue("Elvis"); | |
cell = cells["A23"]; | |
cell.PutValue("Elvis"); | |
cell = cells["A24"]; | |
cell.PutValue("Elvis"); | |
cell = cells["A25"]; | |
cell.PutValue("Jean"); | |
cell = cells["A26"]; | |
cell.PutValue("Jean"); | |
cell = cells["A27"]; | |
cell.PutValue("Jean"); | |
cell = cells["A28"]; | |
cell.PutValue("Ada"); | |
cell = cells["A29"]; | |
cell.PutValue("Ada"); | |
cell = cells["A30"]; | |
cell.PutValue("Ada"); | |
cell = cells["B2"]; | |
cell.PutValue("1"); | |
cell = cells["B3"]; | |
cell.PutValue("2"); | |
cell = cells["B4"]; | |
cell.PutValue("3"); | |
cell = cells["B5"]; | |
cell.PutValue("4"); | |
cell = cells["B6"]; | |
cell.PutValue("1"); | |
cell = cells["B7"]; | |
cell.PutValue("2"); | |
cell = cells["B8"]; | |
cell.PutValue("3"); | |
cell = cells["B9"]; | |
cell.PutValue("4"); | |
cell = cells["B10"]; | |
cell.PutValue("4"); | |
cell = cells["B11"]; | |
cell.PutValue("1"); | |
cell = cells["B12"]; | |
cell.PutValue("1"); | |
cell = cells["B13"]; | |
cell.PutValue("2"); | |
cell = cells["B14"]; | |
cell.PutValue("2"); | |
cell = cells["B15"]; | |
cell.PutValue("3"); | |
cell = cells["B16"]; | |
cell.PutValue("4"); | |
cell = cells["B17"]; | |
cell.PutValue("4"); | |
cell = cells["B18"]; | |
cell.PutValue("1"); | |
cell = cells["B19"]; | |
cell.PutValue("1"); | |
cell = cells["B20"]; | |
cell.PutValue("2"); | |
cell = cells["B21"]; | |
cell.PutValue("3"); | |
cell = cells["B22"]; | |
cell.PutValue("3"); | |
cell = cells["B23"]; | |
cell.PutValue("4"); | |
cell = cells["B24"]; | |
cell.PutValue("4"); | |
cell = cells["B25"]; | |
cell.PutValue("1"); | |
cell = cells["B26"]; | |
cell.PutValue("2"); | |
cell = cells["B27"]; | |
cell.PutValue("3"); | |
cell = cells["B28"]; | |
cell.PutValue("1"); | |
cell = cells["B29"]; | |
cell.PutValue("2"); | |
cell = cells["B30"]; | |
cell.PutValue("3"); | |
cell = cells["C2"]; | |
cell.PutValue("Maxilaku"); | |
cell = cells["C3"]; | |
cell.PutValue("Maxilaku"); | |
cell = cells["C4"]; | |
cell.PutValue("Chai"); | |
cell = cells["C5"]; | |
cell.PutValue("Maxilaku"); | |
cell = cells["C6"]; | |
cell.PutValue("Chang"); | |
cell = cells["C7"]; | |
cell.PutValue("Chang"); | |
cell = cells["C8"]; | |
cell.PutValue("Chang"); | |
cell = cells["C9"]; | |
cell.PutValue("Chang"); | |
cell = cells["C10"]; | |
cell.PutValue("Chang"); | |
cell = cells["C11"]; | |
cell.PutValue("Geitost"); | |
cell = cells["C12"]; | |
cell.PutValue("Chai"); | |
cell = cells["C13"]; | |
cell.PutValue("Geitost"); | |
cell = cells["C14"]; | |
cell.PutValue("Geitost"); | |
cell = cells["C15"]; | |
cell.PutValue("Maxilaku"); | |
cell = cells["C16"]; | |
cell.PutValue("Geitost"); | |
cell = cells["C17"]; | |
cell.PutValue("Geitost"); | |
cell = cells["C18"]; | |
cell.PutValue("Ikuru"); | |
cell = cells["C19"]; | |
cell.PutValue("Ikuru"); | |
cell = cells["C20"]; | |
cell.PutValue("Ikuru"); | |
cell = cells["C21"]; | |
cell.PutValue("Ikuru"); | |
cell = cells["C22"]; | |
cell.PutValue("Ipoh Coffee"); | |
cell = cells["C23"]; | |
cell.PutValue("Ipoh Coffee"); | |
cell = cells["C24"]; | |
cell.PutValue("Ipoh Coffee"); | |
cell = cells["C25"]; | |
cell.PutValue("Chocolade"); | |
cell = cells["C26"]; | |
cell.PutValue("Chocolade"); | |
cell = cells["C27"]; | |
cell.PutValue("Chocolade"); | |
cell = cells["C28"]; | |
cell.PutValue("Chocolade"); | |
cell = cells["C29"]; | |
cell.PutValue("Chocolade"); | |
cell = cells["C30"]; | |
cell.PutValue("Chocolade"); | |
cell = cells["D2"]; | |
cell.PutValue("Asia"); | |
cell = cells["D3"]; | |
cell.PutValue("Asia"); | |
cell = cells["D4"]; | |
cell.PutValue("Asia"); | |
cell = cells["D5"]; | |
cell.PutValue("Asia"); | |
cell = cells["D6"]; | |
cell.PutValue("Europe"); | |
cell = cells["D7"]; | |
cell.PutValue("Europe"); | |
cell = cells["D8"]; | |
cell.PutValue("Europe"); | |
cell = cells["D9"]; | |
cell.PutValue("Europe"); | |
cell = cells["D10"]; | |
cell.PutValue("Europe"); | |
cell = cells["D11"]; | |
cell.PutValue("America"); | |
cell = cells["D12"]; | |
cell.PutValue("America"); | |
cell = cells["D13"]; | |
cell.PutValue("America"); | |
cell = cells["D14"]; | |
cell.PutValue("America"); | |
cell = cells["D15"]; | |
cell.PutValue("America"); | |
cell = cells["D16"]; | |
cell.PutValue("America"); | |
cell = cells["D17"]; | |
cell.PutValue("America"); | |
cell = cells["D18"]; | |
cell.PutValue("Europe"); | |
cell = cells["D19"]; | |
cell.PutValue("Europe"); | |
cell = cells["D20"]; | |
cell.PutValue("Europe"); | |
cell = cells["D21"]; | |
cell.PutValue("Oceania"); | |
cell = cells["D22"]; | |
cell.PutValue("Oceania"); | |
cell = cells["D23"]; | |
cell.PutValue("Oceania"); | |
cell = cells["D24"]; | |
cell.PutValue("Oceania"); | |
cell = cells["D25"]; | |
cell.PutValue("Africa"); | |
cell = cells["D26"]; | |
cell.PutValue("Africa"); | |
cell = cells["D27"]; | |
cell.PutValue("Africa"); | |
cell = cells["D28"]; | |
cell.PutValue("Africa"); | |
cell = cells["D29"]; | |
cell.PutValue("Africa"); | |
cell = cells["D30"]; | |
cell.PutValue("Africa"); | |
cell = cells["E2"]; | |
cell.PutValue("China"); | |
cell = cells["E3"]; | |
cell.PutValue("India"); | |
cell = cells["E4"]; | |
cell.PutValue("Korea"); | |
cell = cells["E5"]; | |
cell.PutValue("India"); | |
cell = cells["E6"]; | |
cell.PutValue("France"); | |
cell = cells["E7"]; | |
cell.PutValue("France"); | |
cell = cells["E8"]; | |
cell.PutValue("Germany"); | |
cell = cells["E9"]; | |
cell.PutValue("Italy"); | |
cell = cells["E10"]; | |
cell.PutValue("France"); | |
cell = cells["E11"]; | |
cell.PutValue("U.S."); | |
cell = cells["E12"]; | |
cell.PutValue("U.S."); | |
cell = cells["E13"]; | |
cell.PutValue("Brazil"); | |
cell = cells["E14"]; | |
cell.PutValue("U.S."); | |
cell = cells["E15"]; | |
cell.PutValue("U.S."); | |
cell = cells["E16"]; | |
cell.PutValue("Canada"); | |
cell = cells["E17"]; | |
cell.PutValue("U.S."); | |
cell = cells["E18"]; | |
cell.PutValue("Italy"); | |
cell = cells["E19"]; | |
cell.PutValue("France"); | |
cell = cells["E20"]; | |
cell.PutValue("Italy"); | |
cell = cells["E21"]; | |
cell.PutValue("New Zealand"); | |
cell = cells["E22"]; | |
cell.PutValue("Australia"); | |
cell = cells["E23"]; | |
cell.PutValue("Australia"); | |
cell = cells["E24"]; | |
cell.PutValue("New Zealand"); | |
cell = cells["E25"]; | |
cell.PutValue("S.Africa"); | |
cell = cells["E26"]; | |
cell.PutValue("S.Africa"); | |
cell = cells["E27"]; | |
cell.PutValue("S.Africa"); | |
cell = cells["E28"]; | |
cell.PutValue("Egypt"); | |
cell = cells["E29"]; | |
cell.PutValue("Egypt"); | |
cell = cells["E30"]; | |
cell.PutValue("Egypt"); | |
cell = cells["F2"]; | |
cell.PutValue(2000); | |
cell = cells["F3"]; | |
cell.PutValue(500); | |
cell = cells["F4"]; | |
cell.PutValue(1200); | |
cell = cells["F5"]; | |
cell.PutValue(1500); | |
cell = cells["F6"]; | |
cell.PutValue(500); | |
cell = cells["F7"]; | |
cell.PutValue(1500); | |
cell = cells["F8"]; | |
cell.PutValue(800); | |
cell = cells["F9"]; | |
cell.PutValue(900); | |
cell = cells["F10"]; | |
cell.PutValue(500); | |
cell = cells["F11"]; | |
cell.PutValue(1600); | |
cell = cells["F12"]; | |
cell.PutValue(600); | |
cell = cells["F13"]; | |
cell.PutValue(2000); | |
cell = cells["F14"]; | |
cell.PutValue(500); | |
cell = cells["F15"]; | |
cell.PutValue(900); | |
cell = cells["F16"]; | |
cell.PutValue(700); | |
cell = cells["F17"]; | |
cell.PutValue(1400); | |
cell = cells["F18"]; | |
cell.PutValue(1350); | |
cell = cells["F19"]; | |
cell.PutValue(300); | |
cell = cells["F20"]; | |
cell.PutValue(500); | |
cell = cells["F21"]; | |
cell.PutValue(1000); | |
cell = cells["F22"]; | |
cell.PutValue(1500); | |
cell = cells["F23"]; | |
cell.PutValue(1500); | |
cell = cells["F24"]; | |
cell.PutValue(1600); | |
cell = cells["F25"]; | |
cell.PutValue(1000); | |
cell = cells["F26"]; | |
cell.PutValue(1200); | |
cell = cells["F27"]; | |
cell.PutValue(1300); | |
cell = cells["F28"]; | |
cell.PutValue(1500); | |
cell = cells["F29"]; | |
cell.PutValue(1400); | |
cell = cells["F30"]; | |
cell.PutValue(1000); | |
// Adding a new sheet | |
Worksheet sheet2 = workbook.Worksheets[workbook.Worksheets.Add()]; | |
// Naming the sheet | |
sheet2.Name = "PivotTable"; | |
// Getting the pivottables collection in the sheet | |
Aspose.Cells.Pivot.PivotTableCollection pivotTables = sheet2.PivotTables; | |
// Adding a PivotTable to the worksheet | |
int index = pivotTables.Add("=Data!A1:F30", "B3", "PivotTable1"); | |
// Accessing the instance of the newly added PivotTable | |
Aspose.Cells.Pivot.PivotTable pivotTable = pivotTables[index]; | |
// Showing the grand totals | |
pivotTable.RowGrand = true; | |
pivotTable.ColumnGrand = true; | |
// Setting the PivotTable report is automatically formatted | |
pivotTable.IsAutoFormat = true; | |
// Setting the PivotTable autoformat type. | |
pivotTable.AutoFormatType = Aspose.Cells.Pivot.PivotTableAutoFormatType.Report6; | |
// Draging the first field to the row area. | |
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, 0); | |
// Draging the third field to the row area. | |
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, 2); | |
// Draging the second field to the row area. | |
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, 1); | |
// Draging the fourth field to the column area. | |
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Column, 3); | |
// Draging the fifth field to the data area. | |
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, 5); | |
// Setting the number format of the first data field | |
pivotTable.DataFields[0].NumberFormat = "$#,##0.00"; | |
// Saving the Excel file | |
workbook.Save(dataDir+ "pivotTable_test.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook. | |
Workbook wb = new Workbook(); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Add text box inside the sheet. | |
ws.Shapes.AddTextBox(2, 0, 2, 0, 80, 400); | |
// Access first shape which is a text box and set is text. | |
Shape shape = ws.Shapes[0]; | |
shape.Text = "Sign up for your free phone number.\nCall and text online for free.\nCall your friends and family."; | |
// Acccess the first paragraph and set its horizontal alignment to left. | |
TextParagraph p = shape.TextBody.TextParagraphs[0]; | |
p.AlignmentType = TextAlignmentType.Left; | |
// Acccess the second paragraph and set its horizontal alignment to center. | |
p = shape.TextBody.TextParagraphs[1]; | |
p.AlignmentType = TextAlignmentType.Center; | |
// Acccess the third paragraph and set its horizontal alignment to right. | |
p = shape.TextBody.TextParagraphs[2]; | |
p.AlignmentType = TextAlignmentType.Right; | |
// Save the workbook in xlsx format. | |
wb.Save(dataDir + "output_out.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source file | |
Workbook wb = new Workbook(dataDir+ "aspose-sample.xlsx"); | |
// Apply different image or print options | |
var imgOption = new ImageOrPrintOptions(); | |
imgOption.ImageFormat = ImageFormat.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); | |
dataDir = dataDir+ "output.png"; | |
sr.ToImage(0, dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook wb = new Workbook(dataDir+ "aspose-sample.xlsx"); | |
FileInfo fi = new FileInfo(dataDir+ "CustomUI.xml"); | |
StreamReader sr = fi.OpenText(); | |
wb.RibbonXml = sr.ReadToEnd(); | |
sr.Close(); |
This file contains hidden or 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 | |
// Defines a custom class derived from GlobalizationSettings class | |
class CustomSettings : GlobalizationSettings | |
{ | |
// Overrides the GetTotalName method | |
public override string GetTotalName(ConsolidationFunction functionType) | |
{ | |
// Checks the function type used to add the subtotals | |
switch (functionType) | |
{ | |
// Returns custom value based on the function type used to add the subtotals | |
case ConsolidationFunction.Average: | |
return "AVG"; | |
// Handle other cases as per requirement | |
default: | |
return base.GetTotalName(functionType); | |
} | |
} | |
// Overrides the GetGrandTotalName method | |
public override string GetGrandTotalName(ConsolidationFunction functionType) | |
{ | |
// Checks the function type used to add the subtotals | |
switch (functionType) | |
{ | |
// Returns custom value based on the function type used to add the subtotals | |
case ConsolidationFunction.Average: | |
return "GRD AVG"; | |
// Handle other cases as per requirement | |
default: | |
return base.GetGrandTotalName(functionType); | |
} | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Loads an existing spreadsheet containing some data | |
Workbook book = new Workbook(dataDir + "sample.xlsx"); | |
// Assigns the GlobalizationSettings property of the WorkbookSettings class to the class created in first step | |
book.Settings.GlobalizationSettings = new CustomSettings(); | |
// Accesses the 1st worksheet from the collection which contains data resides in the cell range A2:B9 | |
Worksheet sheet = book.Worksheets[0]; | |
// Adds Subtotal of type Average to the worksheet | |
sheet.Cells.Subtotal(CellArea.CreateCellArea("A2", "B9"), 0, ConsolidationFunction.Average, new int[] { 1 }); | |
// Calculates Formulas | |
book.CalculateFormula(); | |
// Auto fits all columns | |
sheet.AutoFitColumns(); | |
// Saves the workbook on disc | |
book.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook object from the template file | |
Workbook workbook = new Workbook(); | |
// Access the first worksheet. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Put the sample values used in a pie chart | |
worksheet.Cells["C3"].PutValue("India"); | |
worksheet.Cells["C4"].PutValue("China"); | |
worksheet.Cells["C5"].PutValue("United States"); | |
worksheet.Cells["C6"].PutValue("Russia"); | |
worksheet.Cells["C7"].PutValue("United Kingdom"); | |
worksheet.Cells["C8"].PutValue("Others"); | |
// Put the sample values used in a pie chart | |
worksheet.Cells["D2"].PutValue("% of world population"); | |
worksheet.Cells["D3"].PutValue(25); | |
worksheet.Cells["D4"].PutValue(30); | |
worksheet.Cells["D5"].PutValue(10); | |
worksheet.Cells["D6"].PutValue(13); | |
worksheet.Cells["D7"].PutValue(9); | |
worksheet.Cells["D8"].PutValue(13); | |
// Create a pie chart with desired length and width | |
int pieIdx = worksheet.Charts.Add(ChartType.Pie, 1, 6, 15, 14); | |
// Access the pie chart | |
Chart pie = worksheet.Charts[pieIdx]; | |
// Set the pie chart series | |
pie.NSeries.Add("D3:D8", true); | |
// Set the category data | |
pie.NSeries.CategoryData = "=Sheet1!$C$3:$C$8"; | |
// Set the chart title that is linked to cell D2 | |
pie.Title.LinkedSource = "D2"; | |
// Set the legend position at the bottom. | |
pie.Legend.Position = LegendPositionType.Bottom; | |
// Set the chart title's font name and color | |
pie.Title.Font.Name = "Calibri"; | |
pie.Title.Font.Size = 18; | |
// Access the chart series | |
Series srs = pie.NSeries[0]; | |
// Color the indvidual points with custom colors | |
srs.Points[0].Area.ForegroundColor = System.Drawing.Color.FromArgb(0, 246, 22, 219); | |
srs.Points[1].Area.ForegroundColor = System.Drawing.Color.FromArgb(0, 51, 34, 84); | |
srs.Points[2].Area.ForegroundColor = System.Drawing.Color.FromArgb(0, 46, 74, 44); | |
srs.Points[3].Area.ForegroundColor = System.Drawing.Color.FromArgb(0, 19, 99, 44); | |
srs.Points[4].Area.ForegroundColor = System.Drawing.Color.FromArgb(0, 208, 223, 7); | |
srs.Points[5].Area.ForegroundColor = System.Drawing.Color.FromArgb(0, 222, 69, 8); | |
// Autofit all columns | |
worksheet.AutoFitColumns(); | |
dataDir = dataDir+ "output.out.xlsx"; | |
// Save the workbook | |
workbook.Save(dataDir, SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// Defines a custom class inherited by GlobalizationSettings class | |
class CustomSettings : GlobalizationSettings | |
{ | |
// Overrides the GetOtherName method | |
public override string GetOtherName() | |
{ | |
// Gets the culture identifier for the current system | |
int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID; | |
switch (lcid) | |
{ | |
// Handles case for English | |
case 1033: | |
return "Other"; | |
// Handles case for French | |
case 1036: | |
return "Autre"; | |
// Handles case for German | |
case 1031: | |
return "Andere"; | |
// Handle other cases | |
default: | |
return base.GetOtherName(); | |
} | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Loads an existing spreadsheet containing a pie chart | |
Workbook book = new Workbook(dataDir + "sample.xlsx"); | |
// Assigns the GlobalizationSettings property of the WorkbookSettings class to the class created in first step | |
book.Settings.GlobalizationSettings = new CustomSettings(); | |
// Accesses the 1st worksheet from the collection which contains pie chart | |
Worksheet sheet = book.Worksheets[0]; | |
// Accesses the 1st chart from the collection | |
Chart chart = sheet.Charts[0]; | |
// Refreshes the chart | |
chart.Calculate(); | |
// Renders the chart to image | |
chart.ToImage(dataDir + "output_out.png", new ImageOrPrintOptions()); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate the workbook from sample Excel file | |
Workbook workbook = new Workbook(dataDir+ "sample.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access Cell C1 | |
// Cell C1 has the Decimal Validation applied on it. | |
// It can take only the values Between 10 and 20 | |
Cell cell = worksheet.Cells["C1"]; | |
// Enter 3 inside this cell | |
// Since it is not between 10 and 20, it should fail the validation | |
cell.PutValue(3); | |
// Check if number 3 satisfies the Data Validation rule applied on this cell | |
Console.WriteLine("Is 3 a Valid Value for this Cell: " + cell.GetValidationValue()); | |
// Enter 15 inside this cell | |
// Since it is between 10 and 20, it should succeed the validation | |
cell.PutValue(15); | |
// Check if number 15 satisfies the Data Validation rule applied on this cell | |
Console.WriteLine("Is 15 a Valid Value for this Cell: " + cell.GetValidationValue()); | |
// Enter 30 inside this cell | |
// Since it is not between 10 and 20, it should fail the validation again | |
cell.PutValue(30); | |
// Check if number 30 satisfies the Data Validation rule applied on this cell | |
Console.WriteLine("Is 30 a Valid Value for this Cell: " + cell.GetValidationValue()); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an existing excel file. | |
Workbook wb = new Workbook(dataDir+ "SampleInput.xlsx"); | |
// Create a Worksheets object with reference to | |
// The sheets of the Workbook. | |
WorksheetCollection sheets = wb.Worksheets; | |
// Get first Worksheet from WorksheetCollection | |
Worksheet sheet = sheets[0]; | |
// Delete the Blank Rows from the worksheet | |
sheet.Cells.DeleteBlankRows(); | |
// Save the excel file. | |
wb.Save(dataDir+ "mybook.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an existing excel file. | |
Workbook wb = new Workbook(dataDir+ "SampleInput.xlsx"); | |
// Create a Worksheets object with reference to | |
// The sheets of the Workbook. | |
WorksheetCollection sheets = wb.Worksheets; | |
// Get first Worksheet from WorksheetCollection | |
Worksheet sheet = sheets[0]; | |
// Delete the Blank Rows from the worksheet | |
sheet.Cells.DeleteBlankRows(); | |
// Save the excel file. | |
wb.Save(dataDir+ "mybook.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Sample Html containing redundant spaces after <br> tag | |
string html = "<html> <body> <table> <tr> <td> <br> This is sample data <br> This is sample data<br> This is sample data</td> </tr> </table> </body> </html>"; | |
// Convert Html to byte array | |
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(html); | |
// Set Html load options and keep precision true | |
HTMLLoadOptions loadOptions = new Aspose.Cells.HTMLLoadOptions(LoadFormat.Html); | |
loadOptions.DeleteRedundantSpaces = true; | |
// Convert byte array into stream | |
MemoryStream stream = new MemoryStream(byteArray); | |
// Create workbook from stream with Html load options | |
Workbook workbook = new Workbook(stream, loadOptions); | |
// Access first worksheet | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Auto fit the sheet columns | |
sheet.AutoFitColumns(); | |
dataDir = dataDir + "DeleteRedundantSpaces_out.xlsx"; | |
// Save the workbook | |
workbook.Save(dataDir, SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook | |
// Open an existing excel file | |
Workbook wkBook = new Workbook(dataDir+ "SampleInput.xlsx"); | |
// Get a worksheet in the workbook | |
Worksheet wkSheet = wkBook.Worksheets["Sheet2"]; | |
// Clear its contents | |
wkSheet.Cells.Clear(); | |
// Create an arraylist object | |
ArrayList al = new ArrayList(); | |
// Get the merged cells list to put it into the arraylist object | |
al = wkSheet.Cells.MergedCells; | |
// Define cellarea | |
CellArea ca; | |
// Define some variables | |
int frow, fcol, erow, ecol, trows, tcols; | |
// Loop through the arraylist and get each cellarea | |
// To unmerge it | |
for (int i = 0; i < al.Count; i++) | |
{ | |
ca = new CellArea(); | |
ca = (CellArea)al[i]; | |
frow = ca.StartRow; | |
fcol = ca.StartColumn; | |
erow = ca.EndRow; | |
ecol = ca.EndColumn; | |
trows = erow - frow + 1; | |
tcols = ecol - fcol + 1; | |
wkSheet.Cells.UnMerge(frow, fcol, trows, tcols); | |
} | |
dataDir = dataDir+ "MergeTrial.out.xlsx"; | |
// Save the excel file | |
wkBook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open a template file | |
Workbook workbook = new Workbook(dataDir+ "sample.xlsx"); | |
// Disable the compatibility checker | |
workbook.Settings.CheckCompatibility = false; | |
dataDir = dataDir + "Output_BK_CompCheck.out.xlsx"; | |
// Saving the Excel file | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook and opening a template spreadsheet | |
Workbook workbook = new Workbook(dataDir+ "Book1.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Instantiate the error checking options | |
ErrorCheckOptionCollection opts = sheet.ErrorCheckOptions; | |
int index = opts.Add(); | |
ErrorCheckOption opt = opts[index]; | |
// Disable the numbers stored as text option | |
opt.SetErrorCheck(ErrorCheckType.TextNumber, false); | |
// Set the range | |
opt.AddRange(CellArea.CreateCellArea(0, 0, 1000, 50)); | |
dataDir = dataDir + "out_test.out.xlsx"; | |
// Save the Excel file | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filePath = dataDir+ "aspose-sample.xlsx"; | |
// Create workbook from source file. | |
Workbook workbook = new Workbook(filePath); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Set the print area with your desired range | |
worksheet.PageSetup.PrintArea = "E12:H16"; | |
// Set all margins as 0 | |
worksheet.PageSetup.LeftMargin = 0; | |
worksheet.PageSetup.RightMargin = 0; | |
worksheet.PageSetup.TopMargin = 0; | |
worksheet.PageSetup.BottomMargin = 0; | |
// Set OnePagePerSheet option as true | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
options.OnePagePerSheet = true; | |
options.ImageFormat = ImageFormat.Jpeg; | |
// Take the image of your worksheet | |
SheetRender sr = new SheetRender(worksheet, options); | |
dataDir = dataDir+ "output.out.jpg"; | |
sr.ToImage(0, dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create your workbook | |
Workbook wb = new Workbook(); | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Fill worksheet with some integer values | |
for (int r = 0; r < 10; r++) | |
{ | |
for (int c = 0; c < 10; c++) | |
{ | |
ws.Cells[r, c].PutValue(r * 1); | |
} | |
} | |
// Save your workbook in HTML format and export gridlines | |
HtmlSaveOptions opts = new HtmlSaveOptions(); | |
opts.ExportGridLines = true; | |
wb.Save(dataDir + "ExportToHTMLWithGridLines_out.html", opts); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filePath = dataDir+ "aspose-sample.xlsx"; | |
// Load the source workbook | |
Workbook workbook = new Workbook(filePath); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Specify export table options | |
ExportTableOptions exportOptions = new ExportTableOptions(); | |
exportOptions.PlotVisibleRows = true; | |
exportOptions.ExportColumnName = true; | |
// Export the data from worksheet with export options | |
DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, 10, 4, exportOptions); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiating a Workbook object. | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Export all XML data from all XML Maps from the Workbook. | |
for (int i = 0; i < workbook.Worksheets.XmlMaps.Count; i++) | |
{ | |
// Access the XML Map. | |
XmlMap map = workbook.Worksheets.XmlMaps[i]; | |
// Exports its XML Data to file. | |
workbook.ExportXml(map.Name, dataDir + map.Name + ".xml"); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open a template Excel file | |
Workbook workbook = new Workbook(dataDir+ "book1.xls"); | |
// 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 fileName = dataDir+ "aspose-logo.out.Jpg"; | |
string picformat = pic.ImageFormat.ToString(); | |
// Note: you may evaluate the image format before specifying the image path | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions printoption = new ImageOrPrintOptions(); | |
// Specify the image format | |
printoption.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; | |
// Save the image | |
pic.ToImage(fileName, printoption); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the template file. | |
Workbook workbook = new Workbook(dataDir + "oleFile.xlsx"); | |
// Get the OleObject Collection in the first worksheet. | |
Aspose.Cells.Drawing.OleObjectCollection oles = workbook.Worksheets[0].OleObjects; | |
// Loop through all the oleobjects and extract each object in the worksheet. | |
for (int i = 0; i < oles.Count; i++) | |
{ | |
Aspose.Cells.Drawing.OleObject ole = oles[i]; | |
// Specify the output filename. | |
string fileName = dataDir+ "outOle" + i + "."; | |
// Specify each file format based on the oleobject format type. | |
switch (ole.FileFormatType) | |
{ | |
case FileFormatType.Doc: | |
fileName += "doc"; | |
break; | |
case FileFormatType.Excel97To2003: | |
fileName += "Xlsx"; | |
break; | |
case FileFormatType.Ppt: | |
fileName += "Ppt"; | |
break; | |
case FileFormatType.Pdf: | |
fileName += "Pdf"; | |
break; | |
case FileFormatType.Unknown: | |
fileName += "Jpg"; | |
break; | |
default: | |
//........ | |
break; | |
} | |
// Save the oleobject as a new excel file if the object type is xls. | |
if (ole.FileFormatType == FileFormatType.Xlsx) | |
{ | |
MemoryStream ms = new MemoryStream(); | |
if (ole.ObjectData != null) | |
{ | |
ms.Write(ole.ObjectData, 0, ole.ObjectData.Length); | |
Workbook oleBook = new Workbook(ms); | |
oleBook.Settings.IsHidden = false; | |
oleBook.Save(dataDir + "outOle" + i + ".out.xlsx"); | |
} | |
} | |
// Create the files based on the oleobject format types. | |
else | |
{ | |
if (ole.ObjectData != null) | |
{ | |
FileStream fs = File.Create(fileName); | |
fs.Write(ole.ObjectData, 0, ole.ObjectData.Length); | |
fs.Close(); | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Set the load options, we only want to load shapes and do not want to load data | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx); | |
loadOptions.LoadFilter = new LoadFilter(LoadDataFilterOptions.Shape); | |
// Create workbook object from sample excel file using load options | |
Workbook book = new Workbook( dataDir + "sample.xlsx", loadOptions); | |
// Save the output in pdf format | |
book.Save(dataDir + "FilterDataWhileLoadingWorkbook_out.pdf", SaveFormat.Pdf); |
This file contains hidden or 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 | |
public class CustomLoadFilter : LoadFilter | |
{ | |
public override void StartSheet(Worksheet sheet) | |
{ | |
if (sheet.Name == "NoCharts") | |
{ | |
//Load everything and filter charts. | |
this.LoadDataFilterOptions = LoadDataFilterOptions.All & ~LoadDataFilterOptions.Chart; | |
} | |
if (sheet.Name == "NoShapes") | |
{ | |
//Load everything and filter shapes. | |
this.LoadDataFilterOptions = LoadDataFilterOptions.All & ~LoadDataFilterOptions.Shape; | |
} | |
if (sheet.Name == "NoConditionalFormatting)") | |
{ | |
//Load everything and filter conditional formatting. | |
this.LoadDataFilterOptions = LoadDataFilterOptions.All & ~LoadDataFilterOptions.ConditionalFormatting; | |
} | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Filter worksheets using CustomLoadFilter class. | |
LoadOptions loadOpts = new LoadOptions(); | |
loadOpts.LoadFilter = new CustomLoadFilter(); | |
// Load the workbook with filter defined in CustomLoadFilter class. | |
Workbook workbook = new Workbook(dataDir + "sampleCustomFilter.xlsx", loadOpts); | |
// Take the image of all worksheets one by one. | |
for (int i = 0; i < workbook.Worksheets.Count; i++) | |
{ | |
// Access worksheet at index i. | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Create an instance of ImageOrPrintOptions. | |
// Render entire worksheet to image. | |
ImageOrPrintOptions imageOpts = new ImageOrPrintOptions(); | |
imageOpts.OnePagePerSheet = true; | |
imageOpts.ImageFormat = ImageFormat.Png; | |
// Convert worksheet to image. | |
SheetRender render = new SheetRender(worksheet, imageOpts); | |
render.ToImage(0, dataDir + worksheet.Name + ".png"); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Filter charts from the workbook. | |
LoadOptions lOptions = new LoadOptions(); | |
lOptions.LoadFilter = new LoadFilter(LoadDataFilterOptions.All & ~LoadDataFilterOptions.Chart); | |
// Load the workbook with above filter. | |
Workbook workbook = new Workbook(dataDir + "sampleFilterCharts.xlsx", lOptions); | |
// Save worksheet to a single PDF page. | |
PdfSaveOptions pOptions = new PdfSaveOptions(); | |
pOptions.OnePagePerSheet = true; | |
// Save the workbook in PDF format. | |
workbook.Save(dataDir + "sampleFilterCharts.pdf", pOptions); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filePath = dataDir+ "TestBook.xlsx"; | |
Workbook workbook = new Workbook(filePath); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the style of cell A1 | |
Style style = worksheet.Cells["A1"].GetStyle(); | |
// Specify the style for searching | |
FindOptions options = new FindOptions(); | |
options.Style = style; | |
Cell nextCell = null; | |
do | |
{ | |
// Find the cell that has a style of cell A1 | |
nextCell = worksheet.Cells.Find(null, nextCell, options); | |
if (nextCell == null) | |
break; | |
// Change the text of the cell | |
nextCell.PutValue("Found"); | |
} while (true); | |
dataDir = dataDir + "output.out.xlsx"; | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
//Load source excel file containing Bar of Pie chart | |
Workbook wb = new Workbook(dataDir + "PieBars.xlsx"); | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Access first chart which is Bar of Pie chart and calculate it | |
Chart ch = ws.Charts[0]; | |
ch.Calculate(); | |
// Access the chart series | |
Series srs = ch.NSeries[0]; | |
/* | |
* Print the data points of the chart series and | |
* check its IsInSecondaryPlot property to determine | |
* if data point is inside the bar or pie | |
*/ | |
for (int i = 0; i < srs.Points.Count; i++) | |
{ | |
//Access chart point | |
ChartPoint cp = srs.Points[i]; | |
//Skip null values | |
if (cp.YValue == null) | |
continue; | |
/* | |
* Print the chart point value and see if it is inside bar or pie. | |
* If the IsInSecondaryPlot is true, then the data point is inside bar | |
* otherwise it is inside the pie. | |
*/ | |
Console.WriteLine("Value: " + cp.YValue); | |
Console.WriteLine("IsInSecondaryPlot: " + cp.IsInSecondaryPlot); | |
Console.WriteLine(); | |
} |
This file contains hidden or 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 workbook | |
Workbook wb = new Workbook(); | |
// Create worksheet | |
Worksheet sheet = wb.Worksheets[0]; | |
// Access cell A1 and A2 | |
Cell a1 = sheet.Cells["A1"]; | |
Cell a2 = sheet.Cells["A2"]; | |
// Add sample in A1 and sample with quote prefix in A2 | |
a1.PutValue("sample"); | |
a2.PutValue("'sample"); | |
// Print their string values, A1 and A2 both are same | |
Console.WriteLine("String value of A1: " + a1.StringValue); | |
Console.WriteLine("String value of A2: " + a2.StringValue); | |
// Access styles of A1 and A2 | |
Style s1 = a1.GetStyle(); | |
Style s2 = a2.GetStyle(); | |
Console.WriteLine(); | |
// Check if A1 and A2 has a quote prefix | |
Console.WriteLine("A1 has a quote prefix: " + s1.QuotePrefix); | |
Console.WriteLine("A2 has a quote prefix: " + s2.QuotePrefix); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load workbook object | |
Workbook workbook = new Workbook(dataDir + "sample.xlsm"); | |
// Check all the connections inside the workbook | |
for (int i = 0; i < workbook.DataConnections.Count; i++) | |
{ | |
Aspose.Cells.ExternalConnections.ExternalConnection externalConnection = workbook.DataConnections[i]; | |
Console.WriteLine("connection: " + externalConnection.Name); | |
PrintTables(workbook, externalConnection); | |
Console.WriteLine(); | |
} | |
Console.WriteLine("Press any key to continue..."); | |
Console.ReadKey(); |
This file contains hidden or 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 | |
public static void PrintTables(Workbook workbook, Aspose.Cells.ExternalConnections.ExternalConnection ec) | |
{ | |
// Iterate all the worksheets | |
for (int j = 0; j < workbook.Worksheets.Count; j++) | |
{ | |
Worksheet worksheet = workbook.Worksheets[j]; | |
// Check all the query tables in a worksheet | |
for (int k = 0; k < worksheet.QueryTables.Count; k++) | |
{ | |
Aspose.Cells.QueryTable qt = worksheet.QueryTables[k]; | |
// Check if query table is related to this external connection | |
if (ec.Id == qt.ConnectionId | |
&& qt.ConnectionId >= 0) | |
{ | |
// Print the query table name and print its refersto range | |
Console.WriteLine("querytable " + qt.Name); | |
string n = qt.Name.Replace('+', '_').Replace('=', '_'); | |
Name name = workbook.Worksheets.Names["'" + worksheet.Name + "'!" + n]; | |
if (name != null) | |
{ | |
Range range = name.GetRange(); | |
if (range != null) | |
{ | |
Console.WriteLine("refersto: " + range.RefersTo); | |
} | |
} | |
} | |
} | |
// Iterate all the list objects in this worksheet | |
for (int k = 0; k < worksheet.ListObjects.Count; k++) | |
{ | |
ListObject table = worksheet.ListObjects[k]; | |
// Check the data source type if it is query table | |
if (table.DataSourceType == Aspose.Cells.Tables.TableDataSourceType.QueryTable) | |
{ | |
// Access the query table related to list object | |
QueryTable qt = table.QueryTable; | |
// Check if query table is related to this external connection | |
if (ec.Id == qt.ConnectionId | |
&& qt.ConnectionId >= 0) | |
{ | |
// Print the query table name and print its refersto range | |
Console.WriteLine("querytable " + qt.Name); | |
Console.WriteLine("Table " + table.DisplayName); | |
Console.WriteLine("refersto: " + worksheet.Name + "!" + CellsHelper.CellIndexToName(table.StartRow, table.StartColumn) + ":" + CellsHelper.CellIndexToName(table.EndRow, table.EndColumn)); | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create and initialize an instance of Workbook | |
Workbook book = new Workbook(dataDir + "TestBook.xlsx"); | |
// Create and initialize an instance of PdfSaveOptions | |
PdfSaveOptions saveOptions = new PdfSaveOptions(SaveFormat.Pdf); | |
// Set AllColumnsInOnePagePerSheet to true | |
saveOptions.AllColumnsInOnePagePerSheet = true; | |
// Save Workbook to PDF fromart by passing the object of PdfSaveOptions | |
dataDir = dataDir+ "output.out.pdf"; | |
book.Save(dataDir, saveOptions); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filePath = dataDir + "pivotTable_test.xlsx"; | |
// Create workbook object from source file containing pivot table | |
Workbook workbook = new Workbook(filePath); | |
// Access the worksheet by its name | |
Worksheet worksheet = workbook.Worksheets["PivotTable"]; | |
// Access the pivot table | |
// PivotTable pivotTable = worksheet.PivotTables[0]; | |
// Create a style object with background color light blue | |
Style style = workbook.CreateStyle(); | |
style.Pattern = BackgroundType.Solid; | |
style.BackgroundColor = Color.LightBlue; | |
// Format entire pivot table with light blue color | |
// worksheet.FormatAll(style); | |
// Create another style object with yellow color | |
style = workbook.CreateStyle(); | |
style.Pattern = BackgroundType.Solid; | |
style.BackgroundColor = Color.Yellow; | |
// Format the cells of the first row of the pivot table with yellow color | |
for (int col = 0; col < 5; col++) | |
{ | |
// worksheet.Format(1, col, style); | |
} | |
dataDir = dataDir + "output.out.xlsx"; | |
// Save the workbook object | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
/// <summary> | |
/// AsposeFormatWorksheet | |
/// Use Aspose.Cells to perform the task | |
/// </summary> | |
class FormatWorksheetCells | |
{ | |
/// <summary> | |
/// The main entry point for the application. | |
/// </summary> | |
[STAThread] | |
public static void Run() | |
{ | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filename = dataDir + "FormatWorksheet.xls"; | |
CreateSalesReport(filename); | |
} | |
private static void CreateSalesReport(string filename) | |
{ | |
/* | |
* Uncomment the code below when you have purchased license | |
* for Aspose.Cells. You need to deploy the license in the | |
* same folder as your executable, alternatively you can add | |
* the license file as an embedded resource to your project. | |
*/ | |
Aspose.Cells.License cellsLicense = new | |
Aspose.Cells.License(); | |
cellsLicense.SetLicense("Aspose.Cells.lic"); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
/* | |
* Note: Since Excel color palette has 56 colors on it. | |
* The colors are indexed 0-55. | |
* Please check: http:// Www.aspose.com/Products/Aspose.Cells/Api/Aspose.Cells.Workbook.ChangePalette.html | |
* If a color is not present on the palette, we have to add it | |
* To the palette, so that we may use. | |
* Add a few custom colors to the palette. | |
*/ | |
workbook.ChangePalette(Color.FromArgb(155, 204, 255), 55); | |
workbook.ChangePalette(Color.FromArgb(0, 51, 105), 54); | |
workbook.ChangePalette(Color.FromArgb(250, 250, 200), 53); | |
workbook.ChangePalette(Color.FromArgb(124, 199, 72), 52); | |
CreateReportData(workbook); | |
CreateCellsFormatting(workbook); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Name the worksheet. | |
worksheet.Name = "Sales Report"; | |
// Save the excel file. | |
workbook.Save(filename); | |
} | |
private static void CreateReportData(Workbook workbook) | |
{ | |
// Obtain the cells of the first worksheet. | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Input the title on B1 cell. | |
cells["B1"].PutValue("Western Product Sales 2006"); | |
// Insert some column headings in the second row. | |
Cell cell = cells["B2"]; | |
cell.PutValue("January"); | |
cell = cells["C2"]; | |
cell.PutValue("February"); | |
cell = cells["D2"]; | |
cell.PutValue("March"); | |
cell = cells["E2"]; | |
cell.PutValue("April"); | |
cell = cells["F2"]; | |
cell.PutValue("May"); | |
cell = cells["G2"]; | |
cell.PutValue("June"); | |
cell = cells["H2"]; | |
cell.PutValue("July"); | |
cell = cells["I2"]; | |
cell.PutValue("August"); | |
cell = cells["J2"]; | |
cell.PutValue("September"); | |
cell = cells["K2"]; | |
cell.PutValue("October"); | |
cell = cells["L2"]; | |
cell.PutValue("November"); | |
cell = cells["M2"]; | |
cell.PutValue("December"); | |
cell = cells["N2"]; | |
cell.PutValue("Total"); | |
// Insert product names. | |
cells["A3"].PutValue("Biscuits"); | |
cells["A4"].PutValue("Coffee"); | |
cells["A5"].PutValue("Tofu"); | |
cells["A6"].PutValue("Ikura"); | |
cells["A7"].PutValue("Choclade"); | |
cells["A8"].PutValue("Maxilaku"); | |
cells["A9"].PutValue("Scones"); | |
cells["A10"].PutValue("Sauce"); | |
cells["A11"].PutValue("Syrup"); | |
cells["A12"].PutValue("Spegesild"); | |
cells["A13"].PutValue("Filo Mix"); | |
cells["A14"].PutValue("Pears"); | |
cells["A15"].PutValue("Konbu"); | |
cells["A16"].PutValue("Kaviar"); | |
cells["A17"].PutValue("Zaanse"); | |
cells["A18"].PutValue("Cabrales"); | |
cells["A19"].PutValue("Gnocchi"); | |
cells["A20"].PutValue("Wimmers"); | |
cells["A21"].PutValue("Breads"); | |
cells["A22"].PutValue("Lager"); | |
cells["A23"].PutValue("Gravad"); | |
cells["A24"].PutValue("Telino"); | |
cells["A25"].PutValue("Pavlova"); | |
cells["A26"].PutValue("Total"); | |
// Input porduct sales data (B3:M25). | |
cells["B3"].PutValue(5000); | |
cells["C3"].PutValue(4500); | |
cells["D3"].PutValue(6010); | |
cells["E3"].PutValue(7230); | |
cells["F3"].PutValue(5400); | |
cells["G3"].PutValue(5030); | |
cells["H3"].PutValue(3000); | |
cells["I3"].PutValue(6000); | |
cells["J3"].PutValue(9000); | |
cells["K3"].PutValue(3300); | |
cells["L3"].PutValue(2500); | |
cells["M3"].PutValue(5510); | |
cells["B4"].PutValue(4000); | |
cells["C4"].PutValue(2500); | |
cells["D4"].PutValue(6000); | |
cells["E4"].PutValue(5300); | |
cells["F4"].PutValue(7400); | |
cells["G4"].PutValue(7030); | |
cells["H4"].PutValue(4000); | |
cells["I4"].PutValue(4000); | |
cells["J4"].PutValue(5500); | |
cells["K4"].PutValue(4500); | |
cells["L4"].PutValue(2500); | |
cells["M4"].PutValue(2510); | |
cells["B5"].PutValue(2000); | |
cells["C5"].PutValue(1500); | |
cells["D5"].PutValue(3000); | |
cells["E5"].PutValue(2500); | |
cells["F5"].PutValue(3400); | |
cells["G5"].PutValue(4030); | |
cells["H5"].PutValue(2000); | |
cells["I5"].PutValue(2000); | |
cells["J5"].PutValue(1500); | |
cells["K5"].PutValue(2200); | |
cells["L5"].PutValue(2100); | |
cells["M5"].PutValue(2310); | |
cells["B6"].PutValue(1000); | |
cells["C6"].PutValue(1300); | |
cells["D6"].PutValue(2000); | |
cells["E6"].PutValue(2600); | |
cells["F6"].PutValue(5400); | |
cells["G6"].PutValue(2030); | |
cells["H6"].PutValue(2100); | |
cells["I6"].PutValue(4000); | |
cells["J6"].PutValue(6500); | |
cells["K6"].PutValue(5600); | |
cells["L6"].PutValue(3300); | |
cells["M6"].PutValue(5110); | |
cells["B7"].PutValue(3000); | |
cells["C7"].PutValue(3500); | |
cells["D7"].PutValue(1000); | |
cells["E7"].PutValue(4500); | |
cells["F7"].PutValue(5400); | |
cells["G7"].PutValue(2030); | |
cells["H7"].PutValue(3000); | |
cells["I7"].PutValue(3000); | |
cells["J7"].PutValue(4500); | |
cells["K7"].PutValue(6000); | |
cells["L7"].PutValue(3000); | |
cells["M7"].PutValue(3000); | |
cells["B8"].PutValue(5000); | |
cells["C8"].PutValue(5500); | |
cells["D8"].PutValue(5000); | |
cells["E8"].PutValue(5500); | |
cells["F8"].PutValue(5400); | |
cells["G8"].PutValue(5030); | |
cells["H8"].PutValue(5000); | |
cells["I8"].PutValue(2500); | |
cells["J8"].PutValue(5500); | |
cells["K8"].PutValue(5200); | |
cells["L8"].PutValue(5500); | |
cells["M8"].PutValue(2510); | |
cells["B9"].PutValue(4100); | |
cells["C9"].PutValue(1500); | |
cells["D9"].PutValue(1000); | |
cells["E9"].PutValue(2300); | |
cells["F9"].PutValue(3300); | |
cells["G9"].PutValue(4030); | |
cells["H9"].PutValue(5000); | |
cells["I9"].PutValue(6000); | |
cells["J9"].PutValue(3500); | |
cells["K9"].PutValue(4300); | |
cells["L9"].PutValue(2300); | |
cells["M9"].PutValue(2110); | |
cells["B10"].PutValue(2000); | |
cells["C10"].PutValue(2300); | |
cells["D10"].PutValue(3000); | |
cells["E10"].PutValue(3300); | |
cells["F10"].PutValue(3400); | |
cells["G10"].PutValue(3030); | |
cells["H10"].PutValue(3000); | |
cells["I10"].PutValue(3000); | |
cells["J10"].PutValue(3500); | |
cells["K10"].PutValue(3500); | |
cells["L10"].PutValue(3500); | |
cells["M10"].PutValue(3510); | |
cells["B11"].PutValue(4400); | |
cells["C11"].PutValue(4500); | |
cells["D11"].PutValue(4000); | |
cells["E11"].PutValue(4300); | |
cells["F11"].PutValue(4400); | |
cells["G11"].PutValue(4030); | |
cells["H11"].PutValue(5000); | |
cells["I11"].PutValue(5000); | |
cells["J11"].PutValue(4500); | |
cells["K11"].PutValue(4400); | |
cells["L11"].PutValue(4400); | |
cells["M11"].PutValue(4510); | |
cells["B12"].PutValue(2000); | |
cells["C12"].PutValue(1500); | |
cells["D12"].PutValue(3000); | |
cells["E12"].PutValue(2300); | |
cells["F12"].PutValue(3400); | |
cells["G12"].PutValue(3030); | |
cells["H12"].PutValue(3000); | |
cells["I12"].PutValue(3000); | |
cells["J12"].PutValue(2500); | |
cells["K12"].PutValue(2500); | |
cells["L12"].PutValue(1500); | |
cells["M12"].PutValue(5110); | |
cells["B13"].PutValue(4000); | |
cells["C13"].PutValue(1400); | |
cells["D13"].PutValue(1400); | |
cells["E13"].PutValue(3300); | |
cells["F13"].PutValue(3300); | |
cells["G13"].PutValue(3730); | |
cells["H13"].PutValue(3800); | |
cells["I13"].PutValue(3600); | |
cells["J13"].PutValue(2600); | |
cells["K13"].PutValue(4600); | |
cells["L13"].PutValue(1400); | |
cells["M13"].PutValue(2660); | |
cells["B14"].PutValue(3000); | |
cells["C14"].PutValue(3500); | |
cells["D14"].PutValue(3333); | |
cells["E14"].PutValue(2330); | |
cells["F14"].PutValue(3430); | |
cells["G14"].PutValue(3040); | |
cells["H14"].PutValue(3040); | |
cells["I14"].PutValue(3030); | |
cells["J14"].PutValue(1509); | |
cells["K14"].PutValue(4503); | |
cells["L14"].PutValue(1503); | |
cells["M14"].PutValue(3113); | |
cells["B15"].PutValue(2010); | |
cells["C15"].PutValue(1520); | |
cells["D15"].PutValue(3030); | |
cells["E15"].PutValue(2320); | |
cells["F15"].PutValue(3410); | |
cells["G15"].PutValue(3000); | |
cells["H15"].PutValue(3000); | |
cells["I15"].PutValue(3020); | |
cells["J15"].PutValue(2520); | |
cells["K15"].PutValue(2520); | |
cells["L15"].PutValue(1520); | |
cells["M15"].PutValue(5120); | |
cells["B16"].PutValue(2220); | |
cells["C16"].PutValue(1200); | |
cells["D16"].PutValue(3220); | |
cells["E16"].PutValue(1320); | |
cells["F16"].PutValue(1400); | |
cells["G16"].PutValue(1030); | |
cells["H16"].PutValue(3200); | |
cells["I16"].PutValue(3020); | |
cells["J16"].PutValue(2100); | |
cells["K16"].PutValue(2100); | |
cells["L16"].PutValue(1100); | |
cells["M16"].PutValue(5210); | |
cells["B17"].PutValue(1444); | |
cells["C17"].PutValue(1540); | |
cells["D17"].PutValue(3040); | |
cells["E17"].PutValue(2340); | |
cells["F17"].PutValue(1440); | |
cells["G17"].PutValue(1030); | |
cells["H17"].PutValue(3000); | |
cells["I17"].PutValue(4000); | |
cells["J17"].PutValue(4500); | |
cells["K17"].PutValue(2500); | |
cells["L17"].PutValue(4500); | |
cells["M17"].PutValue(5550); | |
cells["B18"].PutValue(4000); | |
cells["C18"].PutValue(5500); | |
cells["D18"].PutValue(3000); | |
cells["E18"].PutValue(3300); | |
cells["F18"].PutValue(3330); | |
cells["G18"].PutValue(5330); | |
cells["H18"].PutValue(3400); | |
cells["I18"].PutValue(3040); | |
cells["J18"].PutValue(2540); | |
cells["K18"].PutValue(4500); | |
cells["L18"].PutValue(4500); | |
cells["M18"].PutValue(2110); | |
cells["B19"].PutValue(2000); | |
cells["C19"].PutValue(2500); | |
cells["D19"].PutValue(3200); | |
cells["E19"].PutValue(3200); | |
cells["F19"].PutValue(2330); | |
cells["G19"].PutValue(5230); | |
cells["H19"].PutValue(2400); | |
cells["I19"].PutValue(3240); | |
cells["J19"].PutValue(2240); | |
cells["K19"].PutValue(4300); | |
cells["L19"].PutValue(4100); | |
cells["M19"].PutValue(2310); | |
cells["B20"].PutValue(7000); | |
cells["C20"].PutValue(8500); | |
cells["D20"].PutValue(8000); | |
cells["E20"].PutValue(5300); | |
cells["F20"].PutValue(6330); | |
cells["G20"].PutValue(7330); | |
cells["H20"].PutValue(3600); | |
cells["I20"].PutValue(3940); | |
cells["J20"].PutValue(2940); | |
cells["K20"].PutValue(4600); | |
cells["L20"].PutValue(6500); | |
cells["M20"].PutValue(8710); | |
cells["B21"].PutValue(4000); | |
cells["C21"].PutValue(4500); | |
cells["D21"].PutValue(2000); | |
cells["E21"].PutValue(2200); | |
cells["F21"].PutValue(2000); | |
cells["G21"].PutValue(3000); | |
cells["H21"].PutValue(3000); | |
cells["I21"].PutValue(3000); | |
cells["J21"].PutValue(4330); | |
cells["K21"].PutValue(4420); | |
cells["L21"].PutValue(4500); | |
cells["M21"].PutValue(1330); | |
cells["B22"].PutValue(2050); | |
cells["C22"].PutValue(3520); | |
cells["D22"].PutValue(1030); | |
cells["E22"].PutValue(2000); | |
cells["F22"].PutValue(3000); | |
cells["G22"].PutValue(2000); | |
cells["H22"].PutValue(2010); | |
cells["I22"].PutValue(2210); | |
cells["J22"].PutValue(2230); | |
cells["K22"].PutValue(4240); | |
cells["L22"].PutValue(3330); | |
cells["M22"].PutValue(2000); | |
cells["B23"].PutValue(1222); | |
cells["C23"].PutValue(3000); | |
cells["D23"].PutValue(3020); | |
cells["E23"].PutValue(2770); | |
cells["F23"].PutValue(3011); | |
cells["G23"].PutValue(2000); | |
cells["H23"].PutValue(6000); | |
cells["I23"].PutValue(9000); | |
cells["J23"].PutValue(4000); | |
cells["K23"].PutValue(2000); | |
cells["L23"].PutValue(5000); | |
cells["M23"].PutValue(6333); | |
cells["B24"].PutValue(1000); | |
cells["C24"].PutValue(2000); | |
cells["D24"].PutValue(1000); | |
cells["E24"].PutValue(1300); | |
cells["F24"].PutValue(1330); | |
cells["G24"].PutValue(1390); | |
cells["H24"].PutValue(1600); | |
cells["I24"].PutValue(1900); | |
cells["J24"].PutValue(1400); | |
cells["K24"].PutValue(1650); | |
cells["L24"].PutValue(1520); | |
cells["M24"].PutValue(1910); | |
cells["B25"].PutValue(2000); | |
cells["C25"].PutValue(6600); | |
cells["D25"].PutValue(3300); | |
cells["E25"].PutValue(8300); | |
cells["F25"].PutValue(2000); | |
cells["G25"].PutValue(3000); | |
cells["H25"].PutValue(6000); | |
cells["I25"].PutValue(4000); | |
cells["J25"].PutValue(7000); | |
cells["K25"].PutValue(2000); | |
cells["L25"].PutValue(5000); | |
cells["M25"].PutValue(5500); | |
// Add Monthwise Summary formulas. | |
cells["B26"].Formula = "=SUM(B3:B25)"; | |
cells["C26"].Formula = "=SUM(C3:C25)"; | |
cells["D26"].Formula = "=SUM(D3:D25)"; | |
cells["E26"].Formula = "=SUM(E3:E25)"; | |
cells["F26"].Formula = "=SUM(F3:F25)"; | |
cells["G26"].Formula = "=SUM(G3:G25)"; | |
cells["H26"].Formula = "=SUM(H3:H25)"; | |
cells["I26"].Formula = "=SUM(I3:I25)"; | |
cells["J26"].Formula = "=SUM(J3:J25)"; | |
cells["K26"].Formula = "=SUM(K3:K25)"; | |
cells["L26"].Formula = "=SUM(L3:L25)"; | |
cells["M26"].Formula = "=SUM(M3:M25)"; | |
// Add Productwise Summary formulas. | |
cells["N3"].Formula = "=SUM(B3:M3)"; | |
cells["N4"].Formula = "=SUM(B4:M4)"; | |
cells["N5"].Formula = "=SUM(B5:M5)"; | |
cells["N6"].Formula = "=SUM(B6:M6)"; | |
cells["N7"].Formula = "=SUM(B7:M7)"; | |
cells["N8"].Formula = "=SUM(B8:M8)"; | |
cells["N9"].Formula = "=SUM(B9:M9)"; | |
cells["N10"].Formula = "=SUM(B10:M10)"; | |
cells["N11"].Formula = "=SUM(B11:M11)"; | |
cells["N12"].Formula = "=SUM(B12:M12)"; | |
cells["N13"].Formula = "=SUM(B13:M13)"; | |
cells["N14"].Formula = "=SUM(B14:M14)"; | |
cells["N15"].Formula = "=SUM(B15:M15)"; | |
cells["N16"].Formula = "=SUM(B16:M16)"; | |
cells["N17"].Formula = "=SUM(B17:M17)"; | |
cells["N18"].Formula = "=SUM(B18:M18)"; | |
cells["N19"].Formula = "=SUM(B19:M19)"; | |
cells["N20"].Formula = "=SUM(B20:M20)"; | |
cells["N21"].Formula = "=SUM(B21:M21)"; | |
cells["N22"].Formula = "=SUM(B22:M22)"; | |
cells["N23"].Formula = "=SUM(B23:M23)"; | |
cells["N24"].Formula = "=SUM(B24:M24)"; | |
cells["N25"].Formula = "=SUM(B25:M25)"; | |
// Add Grand Total. | |
cells["N26"].Formula = "=SUM(N3:N25)"; | |
} | |
private static void CreateCellsFormatting(Workbook workbook) | |
{ | |
// Define a style object adding a new style to the collection list. | |
Style stl0 = workbook.CreateStyle(); | |
// Set a custom shading color of the cells. | |
stl0.ForegroundColor = Color.FromArgb(155, 204, 255); | |
stl0.Pattern = BackgroundType.Solid; | |
stl0.Font.Name = "Trebuchet MS"; | |
stl0.Font.Size = 18; | |
stl0.Font.Color = Color.Maroon; | |
stl0.Font.IsBold = true; | |
stl0.Font.IsItalic = true; | |
// Define a style flag struct. | |
StyleFlag flag = new StyleFlag(); | |
flag.CellShading = true; | |
flag.FontName = true; | |
flag.FontSize = true; | |
flag.FontColor = true; | |
flag.FontBold = true; | |
flag.FontItalic = true; | |
// Get the first row in the first worksheet. | |
Row row = workbook.Worksheets[0].Cells.Rows[0]; | |
// Apply the style to it. | |
row.ApplyStyle(stl0, flag); | |
// Obtain the cells of the first worksheet. | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Set the height of the first row. | |
cells.SetRowHeight(0, 30); | |
// Define a style object adding a new style to the collection list. | |
Style stl1 = workbook.CreateStyle(); | |
// Set the rotation angle of the text. | |
stl1.RotationAngle = 45; | |
// Set the custom fill color of the cells. | |
stl1.ForegroundColor = Color.FromArgb(0, 51, 105); | |
stl1.Pattern = BackgroundType.Solid; | |
stl1.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; | |
stl1.Borders[BorderType.LeftBorder].Color = Color.White; | |
stl1.HorizontalAlignment = TextAlignmentType.Center; | |
stl1.VerticalAlignment = TextAlignmentType.Center; | |
stl1.Font.Name = "Times New Roman"; | |
stl1.Font.Size = 10; | |
stl1.Font.Color = Color.White; | |
stl1.Font.IsBold = true; | |
// Set a style flag struct. | |
flag = new StyleFlag(); | |
flag.LeftBorder = true; | |
flag.Rotation = true; | |
flag.CellShading = true; | |
flag.HorizontalAlignment = true; | |
flag.VerticalAlignment = true; | |
flag.FontName = true; | |
flag.FontSize = true; | |
flag.FontColor = true; | |
flag.FontBold = true; | |
row = workbook.Worksheets[0].Cells.Rows[1]; | |
// Apply the style to it. | |
row.ApplyStyle(stl1, flag); | |
// Set the height of the second row. | |
cells.SetRowHeight(1, 48); | |
// Define a style object adding a new style to the collection list. | |
Style stl2 = workbook.CreateStyle(); | |
// Set the custom cell shading color. | |
stl2.ForegroundColor = Color.FromArgb(155, 204, 255); | |
stl2.Pattern = BackgroundType.Solid; | |
stl2.Font.Name = "Trebuchet MS"; | |
stl2.Font.Color = Color.Maroon; | |
stl2.Font.Size = 10; | |
flag = new StyleFlag(); | |
flag.CellShading = true; | |
flag.FontName = true; | |
flag.FontColor = true; | |
flag.FontSize = true; | |
// Get the first column in the first worksheet. | |
Column col = workbook.Worksheets[0].Cells.Columns[0]; | |
// Apply the style to it. | |
col.ApplyStyle(stl2, flag); | |
// Define a style object adding a new style to the collection list. | |
Style stl3 = workbook.CreateStyle(); | |
// Set the custom cell filling color. | |
stl3.ForegroundColor = Color.FromArgb(124, 199, 72); | |
stl3.Pattern = BackgroundType.Solid; | |
cells["A2"].SetStyle(stl3); | |
// Define a style object adding a new style to the collection list. | |
Style stl4 = workbook.CreateStyle(); | |
// Set the custom font text color. | |
stl4.Font.Color = Color.FromArgb(0, 51, 105); | |
stl4.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; | |
stl4.Borders[BorderType.BottomBorder].Color = Color.FromArgb(124, 199, 72); | |
stl4.ForegroundColor = Color.White; | |
stl4.Pattern = BackgroundType.Solid; | |
// Set custom number format. | |
stl4.Custom = "$#,##0.0"; | |
// Set a style flag struct. | |
flag = new StyleFlag(); | |
flag.FontColor = true; | |
flag.CellShading = true; | |
flag.NumberFormat = true; | |
flag.BottomBorder = true; | |
// Define a style object adding a new style to the collection list. | |
Style stl5 = workbook.CreateStyle(); | |
stl5.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; | |
stl5.Borders[BorderType.BottomBorder].Color = Color.FromArgb(124, 199, 72); | |
stl5.ForegroundColor = Color.FromArgb(250, 250, 200); | |
stl5.Pattern = BackgroundType.Solid; | |
// Set custom number format. | |
stl5.Custom = "$#,##0.0"; | |
stl5.Font.Color = Color.Maroon; | |
// Create a named range of cells (B3:M25)in the first worksheet. | |
Range range = workbook.Worksheets[0].Cells.CreateRange("B3", "M25"); | |
// Name the range. | |
range.Name = "MyRange"; | |
// Apply the style to cells in the named range. | |
range.ApplyStyle(stl4, flag); | |
// Apply different style to alternative rows in the range. | |
for (int i = 0; i <= 22; i++) | |
{ | |
for (int j = 0; j < 12; j++) | |
{ | |
if (i % 2 == 0) | |
{ | |
range[i, j].SetStyle(stl5); | |
} | |
} | |
} | |
// Define a style object adding a new style to the collection list. | |
Style stl6 = workbook.CreateStyle(); | |
// Set the custom fill color of the cells. | |
stl6.ForegroundColor = Color.FromArgb(0, 51, 105); | |
stl6.Pattern = BackgroundType.Solid; | |
stl6.Font.Name = "Arial"; | |
stl6.Font.Size = 10; | |
stl6.Font.Color = Color.White; | |
stl6.Font.IsBold = true; | |
// Set the custom number format. | |
stl6.Custom = "$#,##0.0"; | |
// Set the style flag struct. | |
flag = new StyleFlag(); | |
flag.CellShading = true; | |
flag.FontName = true; | |
flag.FontSize = true; | |
flag.FontColor = true; | |
flag.FontBold = true; | |
flag.NumberFormat = true; | |
// Get the 26th row in the first worksheet which produces totals. | |
row = workbook.Worksheets[0].Cells.Rows[25]; | |
// Apply the style to it. | |
row.ApplyStyle(stl6, flag); | |
// Now apply this style to those cells (N3:N25) which has productwise sales totals. | |
for (int i = 2; i < 25; i++) | |
{ | |
cells[i, 13].SetStyle(stl6); | |
} | |
// Set N column's width to fit the contents. | |
workbook.Worksheets[0].Cells.SetColumnWidth(13, 9.33); | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate and open an Excel file | |
Workbook book = new Workbook(dataDir+ "book1.xlsx"); | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Specify the image format | |
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.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[1]; | |
// 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(100, 100); | |
// 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, 100, 100); | |
} | |
// Save the thumbnail | |
thumb.Save(dataDir+ "mythumbnail.out.bmp"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "WebQuerySample.xlsx"); | |
ExternalConnection connection = workbook.DataConnections[0]; | |
if (connection is WebQueryConnection) | |
{ | |
WebQueryConnection webQuery = (WebQueryConnection)connection; | |
Console.WriteLine("Web Query URL: " + webQuery.Url); | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open a template Excel file | |
Workbook workbook = new Workbook(dataDir+ "book1.xlsx"); | |
// Get the first worksheet in the workbook | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Get the A1 cell | |
Cell cell = sheet.Cells["A1"]; | |
// Get the conditional formatting result object | |
ConditionalFormattingResult cfr = cell.GetConditionalFormattingResult(); | |
// Get the icon set | |
ConditionalFormattingIcon icon = cfr.ConditionalFormattingIcon; | |
// Create the image file based on the icon's image data | |
File.WriteAllBytes(dataDir+ "imgIcon.out.jpg", icon.ImageData); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load your sample workbook which contains embedded PowerPoint ole object | |
Workbook wb = new Workbook(dataDir + "sample.xls"); | |
// Access its first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Access first ole object inside the worksheet | |
OleObject oleObj = ws.OleObjects[0]; | |
// Convert 16-bytes array into GUID | |
Guid guid = new Guid(oleObj.ClassIdentifier); | |
// Print the GUID | |
Console.WriteLine(guid.ToString().ToUpper()); |
This file contains hidden or 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 | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string outputPath = dataDir + "Output.out.xlsx"; | |
// Creating a DataTable that will serve as data source for designer spreadsheet | |
DataTable table = new DataTable("OppLineItems"); | |
table.Columns.Add("PRODUCT_FAMILY"); | |
table.Columns.Add("OPPORTUNITY_LINEITEM_PRODUCTNAME"); | |
table.Rows.Add(new object[] { "MMM", "P1" }); | |
table.Rows.Add(new object[] { "MMM", "P2" }); | |
table.Rows.Add(new object[] { "DDD", "P1" }); | |
table.Rows.Add(new object[] { "DDD", "P2" }); | |
table.Rows.Add(new object[] { "AAA", "P1" }); | |
// Loading the designer spreadsheet in an instance of Workbook | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Loading the instance of Workbook in an instance of WorkbookDesigner | |
WorkbookDesigner designer = new WorkbookDesigner(workbook); | |
// Set the WorkbookDesigner.CallBack property to an instance of newly created class | |
designer.CallBack = new SmartMarkerCallBack(workbook); | |
// Set the data source | |
designer.SetDataSource(table); | |
// Process the Smart Markers in the designer spreadsheet | |
designer.Process(false); | |
// Save the result | |
workbook.Save(outputPath); |
This file contains hidden or 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 | |
class SmartMarkerCallBack: ISmartMarkerCallBack | |
{ | |
Workbook workbook; | |
public SmartMarkerCallBack(Workbook workbook) { | |
this.workbook = workbook; | |
} | |
public void Process(int sheetIndex, int rowIndex, int colIndex, String tableName, String columnName) { | |
Console.WriteLine("Processing Cell: " + workbook.Worksheets[sheetIndex].Name + "!" + CellsHelper.CellIndexToName(rowIndex, colIndex)); | |
Console.WriteLine("Processing Marker: " + tableName + "." + columnName); | |
} | |
} |
This file contains hidden or 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 | |
public class GetWarningsForFontSubstitution : IWarningCallback | |
{ | |
public void Warning(WarningInfo info) | |
{ | |
if (info.WarningType == WarningType.FontSubstitution) | |
{ | |
Debug.WriteLine("WARNING INFO: " + info.Description); | |
} | |
} | |
public static void Run() | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.WarningCallback = new GetWarningsForFontSubstitution(); | |
dataDir = dataDir + "output_out.pdf"; | |
workbook.Save(dataDir, options); | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load your source excel file | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Access first shape | |
Shape sh = ws.Shapes[0]; | |
// Set the glow effect of the shape, Set its Size and Transparency properties | |
GlowEffect ge = sh.Glow; | |
ge.Size = 30; | |
ge.Transparency = 0.4; | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a new Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xlsx"); | |
// Get First worksheet of the workbook | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Hide the zero values in the sheet | |
sheet.DisplayZeros = false; | |
// Save the workbook | |
workbook.Save(dataDir + "outputfile.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the required workbook to convert | |
Workbook w = new Workbook(dataDir + "Sample1.xlsx"); | |
// Disable exporting frame scripts and document properties | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
options.ExportFrameScriptsAndProperties = false; | |
// Save workbook as HTML | |
w.Save(dataDir + "output.out.html", options); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Initialize a new Workbook | |
// Open an excel file | |
Workbook workbook = new Workbook(dataDir+ "book1.xlsx"); | |
// Implement 1904 date system | |
workbook.Settings.Date1904 = true; | |
// Save the excel file | |
workbook.Save(dataDir+ "Mybook.out.xlsx"); |
This file contains hidden or 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 new class derived from AbstractCalculationEngine | |
class CustomEngine : AbstractCalculationEngine | |
{ | |
// Override the Calculate method with custom logic | |
public override void Calculate(CalculationData data) | |
{ | |
// Check the forumla name and change the implementation | |
if (data.FunctionName.ToUpper() == "SUM") | |
{ | |
double val = (double)data.CalculatedValue; | |
val = val + 30; | |
// Assign the CalculationData.CalculatedValue | |
data.CalculatedValue = val; | |
} | |
} | |
} | |
class ImplementCustomCalculationEngine | |
{ | |
public static void Run() | |
{ | |
// Create an instance of Workbook | |
Workbook workbook = new Workbook(); | |
// Access first Worksheet from the collection | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Access Cell A1 and put a formula to sum values of B1 to B2 | |
Cell a1 = sheet.Cells["A1"]; | |
a1.Formula = "=Sum(B1:B2)"; | |
// Assign values to cells B1 & B2 | |
sheet.Cells["B1"].PutValue(10); | |
sheet.Cells["B2"].PutValue(10); | |
// Calculate all formulas in the Workbook | |
workbook.CalculateFormula(); | |
// The result of A1 should be 20 as per default calculation engine | |
Console.WriteLine("The value of A1 with default calculation engine: " + a1.StringValue); | |
// Create an instance of CustomEngine | |
CustomEngine engine = new CustomEngine(); | |
// Create an instance of CalculationOptions | |
CalculationOptions opts = new CalculationOptions(); | |
// Assign the CalculationOptions.CustomEngine property to the instance of CustomEngine | |
opts.CustomEngine = engine; | |
// Recalculate all formulas in Workbook using the custom calculation engine | |
workbook.CalculateFormula(opts); | |
// The result of A1 will be 50 as per custom calculation engine | |
Console.WriteLine("The value of A1 with custom calculation engine: " + a1.StringValue); | |
Console.WriteLine("Press any key to continue..."); | |
Console.ReadKey(); | |
} | |
} |
This file contains hidden or 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 | |
class ICustomEngine : AbstractCalculationEngine | |
{ | |
// Override the Calculate method with custom logic | |
public override void Calculate(CalculationData data) | |
{ | |
// Check the forumla name and calculate it yourself | |
if (data.FunctionName == "MyCompany.CustomFunction") | |
{ | |
// This is our calculated value | |
data.CalculatedValue = "Aspose.Cells."; | |
} | |
} | |
} | |
class ImplementDirectCalculationOfCustomFunction | |
{ | |
public static void Run() | |
{ | |
// Create a workbook | |
Workbook wb = new Workbook(); | |
// Accesss first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Add some text in cell A1 | |
ws.Cells["A1"].PutValue("Welcome to "); | |
// Create a calculation options with custom engine | |
CalculationOptions opts = new CalculationOptions(); | |
opts.CustomEngine = new ICustomEngine(); | |
// This line shows how you can call your own custom function without | |
// a need to write it in any worksheet cell | |
// After the execution of this line, it will return | |
// Welcome to Aspose.Cells. | |
object ret = ws.CalculateFormula("=A1 & MyCompany.CustomFunction()", opts); | |
// Print the calculated value on Console | |
Console.WriteLine("Calculated Value: " + ret); | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a Name for non sequenced range | |
int index = workbook.Worksheets.Names.Add("NonSequencedRange"); | |
Name name = workbook.Worksheets.Names[index]; | |
// Creating a non sequence range of cells | |
name.RefersTo = "=Sheet1!$A$1:$B$3,Sheet1!$E$5:$D$6"; | |
// Save the workbook | |
workbook.Save(dataDir+ "Output.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a Workbook object. | |
// Load a template file. | |
Workbook workbook = new Workbook(dataDir+ "book1.xlsx"); | |
// Get the first worksheet in the book. | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Insert 10 rows at row index 2 (insertion starts at 3rd row) | |
sheet.Cells.InsertRows(2, 10); | |
// Delete 5 rows now. (8th row - 12th row) | |
sheet.Cells.DeleteRows(7, 5); | |
// Save the excel file. | |
workbook.Save(dataDir+ "out_book1.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Define a string variable to store the image path. | |
string ImageUrl = dataDir+ "image2.jpg"; | |
// Get the picture into the streams. | |
FileStream fs = File.OpenRead(ImageUrl); | |
// 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 = dataDir+ "chord.wav"; | |
// Get the file into the streams. | |
fs = File.OpenRead(path); | |
// 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(); | |
int intIndex = 0; | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Add Ole Object | |
sheet.OleObjects.Add(14, 3, 200, 220, imageData); | |
workbook.Worksheets[0].OleObjects[intIndex].FileFormatType = FileFormatType.Unknown; | |
workbook.Worksheets[0].OleObjects[intIndex].ObjectData = objectData; | |
workbook.Worksheets[0].OleObjects[intIndex].ObjectSourceFullName = path; | |
// Save the excel file | |
workbook.Save(dataDir+ "testWAV.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Insert a linked picture (from Web Address) to B2 Cell. | |
Aspose.Cells.Drawing.Picture pic = workbook.Worksheets[0].Shapes.AddLinkedPicture(1, 1, 100, 100, "http:// Www.aspose.com/Images/aspose-logo.jpg"); | |
// Set the height and width of the inserted image. | |
pic.HeightInch = 1.04; | |
pic.WidthInch = 2.6; | |
// Save the Excel file. | |
workbook.Save(dataDir+ "outLinkedPicture.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet's cells collection | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Add string values to the cells | |
cells["A1"].PutValue("A1"); | |
cells["C10"].PutValue("C10"); | |
// Get the conditional icon's image data | |
byte[] imagedata = ConditionalFormattingIcon.GetIconImageData(IconSetType.TrafficLights31, 0); | |
// Create a stream based on the image data | |
MemoryStream stream = new MemoryStream(imagedata); | |
// Add a blank picture to the D1 cell | |
Picture pic = (Picture)workbook.Worksheets[0].Shapes.AddPicture(0, 3, stream, 10, 10); | |
// Specify the formula that refers to the source range of cells | |
pic.Formula = "A1:C10"; | |
// Update the shapes selected value in the worksheet | |
workbook.Worksheets[0].Shapes.UpdateSelectedValue(); | |
// Save the Excel file. | |
workbook.Save(dataDir + "referencedpicture.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an Excel file | |
Workbook wb = new Workbook(dataDir+ "TestBook.xlsx"); | |
// Instantiate the PdfSaveOption | |
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(dataDir+ "outPDF1.out.pdf", options); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create Workbook Object | |
Workbook wb = new Workbook(); | |
// Open first Worksheet in the workbook | |
Worksheet ws = wb.Worksheets[0]; | |
// Get Worksheet Cells Collection | |
Aspose.Cells.Cells cell = ws.Cells; | |
// Increase the width of First Column Width | |
cell.SetColumnWidth(0, 35); | |
// Increase the height of first row | |
cell.SetRowHeight(0, 65); | |
// Add Text to the Firts Cell with Explicit Line Breaks | |
cell[0, 0].PutValue("I am using\nthe latest version of \nAspose.Cells to \ntest this functionality"); | |
// Make Cell's Text wrap | |
Style style = cell[0, 0].GetStyle(); | |
style.IsTextWrapped = true; | |
cell[0, 0].SetStyle(style); | |
// Save Excel File | |
wb.Save(dataDir+ "WrappingText.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create Workbook Object | |
Workbook wb = new Workbook(); | |
// Open first Worksheet in the workbook | |
Worksheet ws = wb.Worksheets[0]; | |
// Get Worksheet Cells Collection | |
Aspose.Cells.Cells cell = ws.Cells; | |
// Increase the width of First Column Width | |
cell.SetColumnWidth(0, 35); | |
// Increase the height of first row | |
cell.SetRowHeight(0, 36); | |
// Add Text to the Firts Cell | |
cell[0, 0].PutValue("I am using the latest version of Aspose.Cells to test this functionality"); | |
// Make Cell's Text wrap | |
Style style = cell[0, 0].GetStyle(); | |
style.IsTextWrapped = true; | |
cell[0, 0].SetStyle(style); | |
// Save Excel File | |
wb.Save(dataDir+ "WrappingText.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load sample workbook | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access the Xml Map inside it | |
XmlMap map = wb.Worksheets.XmlMaps[0]; | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Map FIELD1 and FIELD2 to cell A1 and B2 | |
ws.Cells.LinkToXmlMap(map.Name, 0, 0, "/root/row/FIELD1"); | |
ws.Cells.LinkToXmlMap(map.Name, 1, 1, "/root/row/FIELD2"); | |
// Map FIELD4 and FIELD5 to cell C3 and D4 | |
ws.Cells.LinkToXmlMap(map.Name, 2, 2, "/root/row/FIELD4"); | |
ws.Cells.LinkToXmlMap(map.Name, 3, 3, "/root/row/FIELD5"); | |
// Map FIELD7 and FIELD8 to cell E5 and F6 | |
ws.Cells.LinkToXmlMap(map.Name, 4, 4, "/root/row/FIELD7"); | |
ws.Cells.LinkToXmlMap(map.Name, 5, 5, "/root/row/FIELD8"); | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "output.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specify the load options and filter the data | |
LoadOptions options = new LoadOptions(); | |
// Include everything except charts | |
options.LoadFilter = new LoadFilter(LoadDataFilterOptions.All & ~LoadDataFilterOptions.Chart); | |
// Load the workbook with specified load options | |
Workbook workbook = new Workbook(dataDir + "chart.xlsx", options); | |
// Save the workbook in PDF format | |
workbook.Save(dataDir + "ResultWithoutChart.pdf", SaveFormat.Pdf); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Define a new Workbook. | |
Workbook workbook; | |
// Load the workbook with the spcified worksheet only. | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx); | |
loadOptions.LoadFilter = new CustomLoad(); | |
// Creat the workbook. | |
workbook = new Workbook(dataDir+ "TestData.xlsx", loadOptions); | |
// Perform your desired task. | |
// Save the workbook. | |
workbook.Save(dataDir+ "outputFile.out.xlsx"); |
This file contains hidden or 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 | |
class CustomLoad : LoadFilter | |
{ | |
public override void StartSheet(Worksheet sheet) | |
{ | |
if (sheet.Name == "Sheet2") | |
{ | |
// Load everything from worksheet "Sheet2" | |
this.LoadDataFilterOptions = LoadDataFilterOptions.All; | |
} | |
else | |
{ | |
// Load nothing | |
this.LoadDataFilterOptions = LoadDataFilterOptions.None; | |
} | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Define memory stream object | |
System.IO.MemoryStream objImage; | |
// Define web client object | |
System.Net.WebClient objwebClient; | |
// Define a string which will hold the web image url | |
string sURL = "http:// Www.aspose.com/Images/aspose-logo.jpg"; | |
try | |
{ | |
// Instantiate the web client object | |
objwebClient = new System.Net.WebClient(); | |
// Now, extract data into memory stream downloading the image data into the array of bytes | |
objImage = new System.IO.MemoryStream(objwebClient.DownloadData(sURL)); | |
// Create a new workbook | |
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(); | |
// Get the first worksheet in the book | |
Aspose.Cells.Worksheet sheet = wb.Worksheets[0]; | |
// Get the first worksheet pictures collection | |
Aspose.Cells.Drawing.PictureCollection pictures = sheet.Pictures; | |
// Insert the picture from the stream to B2 cell | |
pictures.Add(1, 1, objImage); | |
// Save the excel file | |
wb.Save(dataDir+ "webimagebook.out.xlsx"); | |
} | |
catch (Exception ex) | |
{ | |
// Write the error message on the console | |
Console.WriteLine(ex.Message); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a sample workbook and add some data inside the first worksheet | |
Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
worksheet.Cells["P30"].PutValue("This is sample data."); | |
// Save the workbook in memory stream | |
MemoryStream ms = new MemoryStream(); | |
workbook.Save(ms, SaveFormat.Xlsx); | |
ms.Position = 0; | |
// Now load the workbook from memory stream with A5 paper size | |
LoadOptions opts = new LoadOptions(LoadFormat.Xlsx); | |
opts.SetPaperSize(PaperSizeType.PaperA5); | |
workbook = new Workbook(ms, opts); | |
// Save the workbook in pdf format | |
workbook.Save(dataDir + "LoadWorkbookWithPrinterSize-a5_out.pdf"); | |
// Now load the workbook again from memory stream with A3 paper size | |
ms.Position = 0; | |
opts = new LoadOptions(LoadFormat.Xlsx); | |
opts.SetPaperSize(PaperSizeType.PaperA3); | |
workbook = new Workbook(ms, opts); | |
// Save the workbook in pdf format | |
workbook.Save(dataDir + "LoadWorkbookWithPrinterSize-a3_out.pdf"); |
This file contains hidden or 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 | |
using (var inputStream = new MemoryStream()) | |
{ | |
using (var writer = new StreamWriter(inputStream)) | |
{ | |
writer.WriteLine("<html><head><title>Test Culture</title></head><body><table><tr><td>10-01-2016</td></tr></table></body></html>"); | |
writer.Flush(); | |
var culture = new CultureInfo("en-GB"); | |
culture.NumberFormat.NumberDecimalSeparator = ","; | |
culture.DateTimeFormat.DateSeparator = "-"; | |
culture.DateTimeFormat.ShortDatePattern = "dd-MM-yyyy"; | |
LoadOptions options = new LoadOptions(LoadFormat.Html); | |
options.CultureInfo = culture; | |
using (var workbook = new Workbook(inputStream, options)) | |
{ | |
var cell = workbook.Worksheets[0].Cells["A1"]; | |
Assert.AreEqual(CellValueType.IsDateTime, cell.Type); | |
Assert.AreEqual(new DateTime(2016, 1, 10), cell.DateTimeValue); | |
} | |
} | |
} |
This file contains hidden or 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 | |
using (var inputStream = new MemoryStream()) | |
{ | |
using (var writer = new StreamWriter(inputStream)) | |
{ | |
writer.WriteLine("<html><head><title>Test Culture</title></head><body><table><tr><td>1234,56</td></tr></table></body></html>"); | |
writer.Flush(); | |
var culture = new CultureInfo("en-GB"); | |
culture.NumberFormat.NumberDecimalSeparator = ","; | |
culture.DateTimeFormat.DateSeparator = "-"; | |
culture.DateTimeFormat.ShortDatePattern = "dd-MM-yyyy"; | |
LoadOptions options = new LoadOptions(LoadFormat.Html); | |
options.CultureInfo = culture; | |
using (var workbook = new Workbook(inputStream, options)) | |
{ | |
var cell = workbook.Worksheets[0].Cells["A1"]; | |
Assert.AreEqual(CellValueType.IsNumeric, cell.Type); | |
Assert.AreEqual(1234.56, cell.DoubleValue); | |
} | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load the sample Excel file inside the workbook object | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first shape inside the worksheet | |
Shape shape = worksheet.Shapes[0]; | |
// Displays the absolute position of the shape | |
Console.WriteLine("Absolute Position of this Shape is ({0} , {1})", shape.LeftToCorner, shape.TopToCorner); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(FileFormatType.Xlsx); | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Put data | |
sheet.Cells[0, 0].PutValue(1); | |
sheet.Cells[0, 1].PutValue(2); | |
sheet.Cells[0, 2].PutValue(3); | |
sheet.Cells[1, 0].PutValue(4); | |
sheet.Cells[1, 1].PutValue(5); | |
sheet.Cells[1, 2].PutValue(6); | |
sheet.Cells[2, 0].PutValue(7); | |
sheet.Cells[2, 1].PutValue(8); | |
sheet.Cells[2, 2].PutValue(9); | |
// Generate the chart | |
int chartIndex = sheet.Charts.Add(Aspose.Cells.Charts.ChartType.ScatterConnectedByLinesWithDataMarker, 5, 1, 24, 10); | |
Chart chart = sheet.Charts[chartIndex]; | |
chart.Title.Text = "Test"; | |
chart.CategoryAxis.Title.Text = "X-Axis"; | |
chart.ValueAxis.Title.Text = "Y-Axis"; | |
chart.NSeries.CategoryData = "A1:C1"; | |
// Insert series | |
chart.NSeries.Add("A2:C2", false); | |
Series series = chart.NSeries[0]; | |
int pointCount = series.Points.Count; | |
for (int i = 0; i < pointCount; i++) | |
{ | |
ChartPoint pointIndex = series.Points[i]; | |
pointIndex.DataLabels.Text = "Series 1" + "\n" + "Point " + i; | |
} | |
// Insert series | |
chart.NSeries.Add("A3:C3", false); | |
series = chart.NSeries[1]; | |
pointCount = series.Points.Count; | |
for (int i = 0; i < pointCount; i++) | |
{ | |
ChartPoint pointIndex = series.Points[i]; | |
pointIndex.DataLabels.Text = "Series 2" + "\n" + "Point " + i; | |
} | |
workbook.Save(dataDir + "output_out.xlsx", Aspose.Cells.SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the existing excel file. | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Get the chart in the first worksheet. | |
Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; | |
// Add a WordArt watermark (shape) to the chart's plot area. | |
Aspose.Cells.Drawing.Shape wordart = chart.Shapes.AddTextEffectInChart(MsoPresetTextEffect.TextEffect2, | |
"CONFIDENTIAL", "Arial Black", 66, false, false, 1200, 500, 2000, 3000); | |
// Get the shape's fill format. | |
FillFormat wordArtFormat = wordart.Fill; | |
// Set the transparency. | |
wordArtFormat.Transparency = 0.9; | |
// Get the line format. | |
LineFormat lineFormat = wordart.Line; | |
// Set Line format to invisible. | |
lineFormat.Weight = 0.0; | |
// Save the excel file. | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first three shapes of the worksheet | |
Shape shape1 = worksheet.Shapes[0]; | |
Shape shape2 = worksheet.Shapes[1]; | |
Shape shape3 = worksheet.Shapes[2]; | |
// Change the adjustment values of the shapes | |
shape1.Geometry.ShapeAdjustValues[0].Value = 0.5d; | |
shape2.Geometry.ShapeAdjustValues[0].Value = 0.8d; | |
shape3.Geometry.ShapeAdjustValues[0].Value = 0.5d; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create new workbook | |
Workbook workbook = new Workbook(FileFormatType.Xlsx); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add data for chart | |
// Category Axis Values | |
worksheet.Cells["A2"].PutValue("C1"); | |
worksheet.Cells["A3"].PutValue("C2"); | |
worksheet.Cells["A4"].PutValue("C3"); | |
// First vertical series | |
worksheet.Cells["B1"].PutValue("T1"); | |
worksheet.Cells["B2"].PutValue(6); | |
worksheet.Cells["B3"].PutValue(3); | |
worksheet.Cells["B4"].PutValue(2); | |
// Second vertical series | |
worksheet.Cells["C1"].PutValue("T2"); | |
worksheet.Cells["C2"].PutValue(7); | |
worksheet.Cells["C3"].PutValue(2); | |
worksheet.Cells["C4"].PutValue(5); | |
// Third vertical series | |
worksheet.Cells["D1"].PutValue("T3"); | |
worksheet.Cells["D2"].PutValue(8); | |
worksheet.Cells["D3"].PutValue(4); | |
worksheet.Cells["D4"].PutValue(2); | |
// Create Column chart with easy way | |
int idx = worksheet.Charts.Add(ChartType.Column, 6, 5, 20, 13); | |
Chart ch = worksheet.Charts[idx]; | |
ch.SetChartDataRange("A1:D4", true); | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// Get the Chart from the "Chart" worksheet. | |
Aspose.Cells.Charts.Chart chartsource = workbook.Worksheets["Chart"].Charts[0]; | |
Aspose.Cells.Drawing.ChartShape cshape = chartsource.ChartObject; | |
// Copy the Chart to the Result Worksheet | |
workbook.Worksheets["Result"].Shapes.AddCopy(cshape, 20, 0, 2, 0); | |
// Save the Worksheet | |
workbook.Save(dataDir + "ChartCopied_out.xlsx"); |
This file contains hidden or 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 | |
// Open the template file | |
workbook = new Workbook(dataDir + "sample2.xlsx"); | |
// Get the Shapes from the "Control" worksheet. | |
Aspose.Cells.Drawing.ShapeCollection shape = workbook.Worksheets["Control"].Shapes; | |
// Copy the Textbox to the Result Worksheet | |
workbook.Worksheets["Result"].Shapes.AddCopy(shape[0], 5, 0, 2, 0); | |
// Copy the Oval Shape to the Result Worksheet | |
workbook.Worksheets["Result"].Shapes.AddCopy(shape[1], 10, 0, 2, 0); | |
// Save the Worksheet | |
workbook.Save(dataDir + "ControlsCopied_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the template file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Get the Picture from the "Picture" worksheet. | |
Aspose.Cells.Drawing.Picture picturesource = workbook.Worksheets["Picture"].Pictures[0]; | |
// Save Picture to Memory Stream | |
MemoryStream ms = new MemoryStream(picturesource.Data); | |
// Copy the picture to the Result Worksheet | |
workbook.Worksheets["Result"].Pictures.Add(picturesource.UpperLeftRow, picturesource.UpperLeftColumn, ms, picturesource.WidthScale, picturesource.HeightScale); | |
// Save the Worksheet | |
workbook.Save(dataDir + "PictureCopied_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first sparkline group | |
SparklineGroup group = worksheet.SparklineGroupCollection[0]; | |
// Add Data Ranges and Locations inside this sparkline group | |
group.SparklineCollection.Add("D5:O5", 4, 15); | |
group.SparklineCollection.Add("D6:O6", 5, 15); | |
group.SparklineCollection.Add("D7:O7", 6, 15); | |
group.SparklineCollection.Add("D8:O8", 7, 15); | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook | |
var book = new Workbook(); | |
// Access first worksheet from the collection | |
var sheet = book.Worksheets[0]; | |
// Access cells collection of the first worksheet | |
var cells = sheet.Cells; | |
// Insert data column wise | |
cells["A1"].PutValue("Category"); | |
cells["A2"].PutValue("Fruit"); | |
cells["A3"].PutValue("Fruit"); | |
cells["A4"].PutValue("Fruit"); | |
cells["A5"].PutValue("Fruit"); | |
cells["A6"].PutValue("Vegetables"); | |
cells["A7"].PutValue("Vegetables"); | |
cells["A8"].PutValue("Vegetables"); | |
cells["A9"].PutValue("Vegetables"); | |
cells["A10"].PutValue("Beverages"); | |
cells["A11"].PutValue("Beverages"); | |
cells["A12"].PutValue("Beverages"); | |
cells["B1"].PutValue("Food"); | |
cells["B2"].PutValue("Apple"); | |
cells["B3"].PutValue("Banana"); | |
cells["B4"].PutValue("Apricot"); | |
cells["B5"].PutValue("Grapes"); | |
cells["B6"].PutValue("Carrot"); | |
cells["B7"].PutValue("Onion"); | |
cells["B8"].PutValue("Cabage"); | |
cells["B9"].PutValue("Potatoe"); | |
cells["B10"].PutValue("Coke"); | |
cells["B11"].PutValue("Coladas"); | |
cells["B12"].PutValue("Fizz"); | |
cells["C1"].PutValue("Cost"); | |
cells["C2"].PutValue(2.2); | |
cells["C3"].PutValue(3.1); | |
cells["C4"].PutValue(4.1); | |
cells["C5"].PutValue(5.1); | |
cells["C6"].PutValue(4.4); | |
cells["C7"].PutValue(5.4); | |
cells["C8"].PutValue(6.5); | |
cells["C9"].PutValue(5.3); | |
cells["C10"].PutValue(3.2); | |
cells["C11"].PutValue(3.6); | |
cells["C12"].PutValue(5.2); | |
cells["D1"].PutValue("Profit"); | |
cells["D2"].PutValue(0.1); | |
cells["D3"].PutValue(0.4); | |
cells["D4"].PutValue(0.5); | |
cells["D5"].PutValue(0.6); | |
cells["D6"].PutValue(0.7); | |
cells["D7"].PutValue(1.3); | |
cells["D8"].PutValue(0.8); | |
cells["D9"].PutValue(1.3); | |
cells["D10"].PutValue(2.2); | |
cells["D11"].PutValue(2.4); | |
cells["D12"].PutValue(3.3); | |
// Create ListObject, Get the List objects collection in the first worksheet | |
var listObjects = sheet.ListObjects; | |
// Add a List based on the data source range with headers on | |
var index = listObjects.Add(0, 0, 11, 3, true); | |
sheet.AutoFitColumns(); | |
// Create chart based on ListObject | |
index = sheet.Charts.Add(ChartType.Column, 21, 1, 35, 18); | |
var chart = sheet.Charts[index]; | |
chart.SetChartDataRange("A1:D12", true); | |
chart.NSeries.CategoryData = "A2:B12"; | |
// Save spreadsheet | |
book.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook in XLSX format | |
Workbook workbook = new Workbook(FileFormatType.Xlsx); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add two columns of data | |
worksheet.Cells["A1"].PutValue("Retail"); | |
worksheet.Cells["A2"].PutValue("Services"); | |
worksheet.Cells["A3"].PutValue("Info & Communication"); | |
worksheet.Cells["A4"].PutValue("Transport Equip"); | |
worksheet.Cells["A5"].PutValue("Construction"); | |
worksheet.Cells["A6"].PutValue("Other Products"); | |
worksheet.Cells["A7"].PutValue("Wholesale"); | |
worksheet.Cells["A8"].PutValue("Land Transport"); | |
worksheet.Cells["A9"].PutValue("Air Transport"); | |
worksheet.Cells["A10"].PutValue("Electric Appliances"); | |
worksheet.Cells["A11"].PutValue("Securities"); | |
worksheet.Cells["A12"].PutValue("Textiles & Apparel"); | |
worksheet.Cells["A13"].PutValue("Machinery"); | |
worksheet.Cells["A14"].PutValue("Metal Products"); | |
worksheet.Cells["A15"].PutValue("Cash"); | |
worksheet.Cells["A16"].PutValue("Banks"); | |
worksheet.Cells["B1"].PutValue(10.4); | |
worksheet.Cells["B2"].PutValue(5.2); | |
worksheet.Cells["B3"].PutValue(6.4); | |
worksheet.Cells["B4"].PutValue(10.4); | |
worksheet.Cells["B5"].PutValue(7.9); | |
worksheet.Cells["B6"].PutValue(4.1); | |
worksheet.Cells["B7"].PutValue(3.5); | |
worksheet.Cells["B8"].PutValue(5.7); | |
worksheet.Cells["B9"].PutValue(3); | |
worksheet.Cells["B10"].PutValue(14.7); | |
worksheet.Cells["B11"].PutValue(3.6); | |
worksheet.Cells["B12"].PutValue(2.8); | |
worksheet.Cells["B13"].PutValue(7.8); | |
worksheet.Cells["B14"].PutValue(2.4); | |
worksheet.Cells["B15"].PutValue(1.8); | |
worksheet.Cells["B16"].PutValue(10.1); | |
// Create a pie chart and add it to the collection of charts | |
int id = worksheet.Charts.Add(ChartType.Pie, 3, 3, 23, 13); | |
// Access newly created Chart instance | |
Chart chart = worksheet.Charts[id]; | |
// Set series data range | |
chart.NSeries.Add("B1:B16", true); | |
// Set category data range | |
chart.NSeries.CategoryData = "A1:A16"; | |
// Turn off legend | |
chart.ShowLegend = false; | |
// Access data labels | |
DataLabels dataLabels = chart.NSeries[0].DataLabels; | |
// Turn on category names | |
dataLabels.ShowCategoryName = true; | |
// Turn on percentage format | |
dataLabels.ShowPercentage = true; | |
// Set position | |
dataLabels.Position = LabelPositionType.OutsideEnd; | |
// Set separator | |
dataLabels.Separator = DataLablesSeparatorType.Comma; |
This file contains hidden or 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 | |
// In order to save the chart image, create an instance of ImageOrPrintOptions | |
ImageOrPrintOptions anOption = new ImageOrPrintOptions(); | |
// Set image format | |
anOption.ImageFormat = System.Drawing.Imaging.ImageFormat.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"); |
This file contains hidden or 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 | |
// Turn on leader lines | |
chart.NSeries[0].HasLeaderLines = true; | |
// Calculete chart | |
chart.Calculate(); | |
// You need to move DataLabels a little leftward or rightward depending on their position to show leader lines | |
int DELTA = 100; | |
for (int i = 0; i < chart.NSeries[0].Points.Count; i++) | |
{ | |
int X = chart.NSeries[0].Points[i].DataLabels.X; | |
// If it is greater than 2000, then move the X position a little right otherwise move the X position a little left | |
if (X > 2000) | |
chart.NSeries[0].Points[i].DataLabels.X = X + DELTA; | |
else | |
chart.NSeries[0].Points[i].DataLabels.X = X - DELTA; | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Insert picture of your choice | |
int index = workbook.Worksheets[0].Pictures.Add(0, 0, dataDir + "signature.jpg"); | |
// Access picture and add signature line inside it | |
Picture pic = workbook.Worksheets[0].Pictures[index]; | |
// Create signature line object | |
SignatureLine s = new SignatureLine(); | |
s.Signer = "John Doe"; | |
s.Title = "Development Lead"; | |
s.Email = "[email protected]"; | |
// Assign the signature line object to Picture.SignatureLine property | |
pic.SignatureLine = s; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook | |
Workbook workbook = new Workbook(); | |
// Retrieve the first Worksheet in Workbook | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Retrieve the Cells of the first Worksheet | |
var cells = worksheet.Cells; | |
// Input some data which chart will use as source | |
cells["A1"].PutValue("Previous Year"); | |
cells["A2"].PutValue("January"); | |
cells["A3"].PutValue("March"); | |
cells["A4"].PutValue("August"); | |
cells["A5"].PutValue("October"); | |
cells["A6"].PutValue("Current Year"); | |
cells["B1"].PutValue(8.5); | |
cells["B2"].PutValue(1.5); | |
cells["B3"].PutValue(7.5); | |
cells["B4"].PutValue(7.5); | |
cells["B5"].PutValue(8.5); | |
cells["B6"].PutValue(3.5); | |
cells["C1"].PutValue(1.5); | |
cells["C2"].PutValue(4.5); | |
cells["C3"].PutValue(3.5); | |
cells["C4"].PutValue(9.5); | |
cells["C5"].PutValue(7.5); | |
cells["C6"].PutValue(9.5); | |
// Add a Chart of type Line in same worksheet as of data | |
int idx = worksheet.Charts.Add(ChartType.Line, 4, 4, 25, 13); | |
// Retrieve the Chart object | |
Chart chart = worksheet.Charts[idx]; | |
// Add Series | |
chart.NSeries.Add("$B$1:$C$6", true); | |
// Add Category Data | |
chart.NSeries.CategoryData = "$A$1:$A$6"; | |
// Series has Up Down Bars | |
chart.NSeries[0].HasUpDownBars = true; | |
// Set the colors of Up and Down Bars | |
chart.NSeries[0].UpBars.Area.ForegroundColor = Color.Green; | |
chart.NSeries[0].DownBars.Area.ForegroundColor = Color.Red; | |
// Make both Series Lines invisible | |
chart.NSeries[0].Border.IsVisible = false; | |
chart.NSeries[1].Border.IsVisible = false; | |
// Set the Plot Area Formatting Automatic | |
chart.PlotArea.Area.Formatting = FormattingType.Automatic; | |
// Delete the Legend | |
chart.Legend.LegendEntries[0].IsDeleted = true; | |
chart.Legend.LegendEntries[1].IsDeleted = true; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the chart | |
Chart chart = worksheet.Charts[0]; | |
//Determine which axis exists in chart | |
bool ret = chart.HasAxis(AxisType.Category, true); | |
Console.WriteLine("Has Primary Category Axis: " + ret); | |
ret = chart.HasAxis(AxisType.Category, false); | |
Console.WriteLine("Has Secondary Category Axis: " + ret); | |
ret = chart.HasAxis(AxisType.Value, true); | |
Console.WriteLine("Has Primary Value Axis: " + ret); | |
ret = chart.HasAxis(AxisType.Value, false); | |
Console.WriteLine("Has Seconary Value Axis: " + ret); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load the sample Excel file inside the workbook object | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first chart inside the worksheet | |
Chart chart = worksheet.Charts[0]; | |
// Disable the Text Wrapping of Data Labels in all Series | |
chart.NSeries[0].DataLabels.IsTextWrapped = false; | |
chart.NSeries[1].DataLabels.IsTextWrapped = false; | |
chart.NSeries[2].DataLabels.IsTextWrapped = false; | |
// Save the workbook | |
workbook.Save(dataDir + "Output_out.xlsx"); |
This file contains hidden or 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 | |
/* | |
* Save the number of rows & columns from the source DataTable in seperate variables. | |
* These values will be used later to identify the chart's data range from DataSheet | |
*/ | |
int chartRows = table.Rows.Count; | |
int chartCols = table.Columns.Count; | |
// Add a new Worksheet of type Chart to Workbook | |
int chartSheetIdx = book.Worksheets.Add(SheetType.Chart); | |
// Access the newly added Worksheet via its index | |
var chartSheet = book.Worksheets[chartSheetIdx]; | |
// Name the Worksheet | |
chartSheet.Name = "Chart"; | |
// Add a chart of type ColumnStacked to newly added Worksheet | |
int chartIdx = chartSheet.Charts.Add(ChartType.ColumnStacked, 0, 0, chartRows, chartCols); | |
// Access the newly added Chart via its index | |
var chart = chartSheet.Charts[chartIdx]; | |
// Set the data range for the chart | |
chart.SetChartDataRange(dataSheet.Name + "!A1:" + CellsHelper.ColumnIndexToName(chartCols - 1) + (chartRows + 1).ToString(), false); | |
// Set the chart to size with window | |
chart.SizeWithWindow = true; | |
// Set the format for the tick labels | |
chart.ValueAxis.TickLabels.NumberFormat = "$###,### K"; | |
// Set chart title | |
chart.Title.Text = "Sales Summary"; | |
// Set ChartSheet an active sheet | |
book.Worksheets.ActiveSheetIndex = chartSheetIdx; | |
// Save the final result | |
book.Save(dataDir + "report_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook | |
var book = new Workbook(); | |
// Access the first, default Worksheet by passing its index | |
var dataSheet = book.Worksheets[0]; | |
// Name the Worksheet for later reference | |
dataSheet.Name = "ChartData"; | |
// Access the CellsCollection of first Worksheet | |
var cells = dataSheet.Cells; | |
// Insert static data (headers) | |
cells["B1"].PutValue("Item 1"); | |
cells["C1"].PutValue("Item 2"); | |
cells["D1"].PutValue("Item 3"); | |
cells["E1"].PutValue("Item 4"); | |
cells["F1"].PutValue("Item 5"); | |
cells["G1"].PutValue("Item 6"); | |
cells["H1"].PutValue("Item 7"); | |
cells["I1"].PutValue("Item 8"); | |
cells["J1"].PutValue("Item 9"); | |
cells["K1"].PutValue("Item 10"); | |
cells["L1"].PutValue("Item 11"); | |
cells["M1"].PutValue("Item 12"); | |
// Place Smart Markers | |
cells["A2"].PutValue("&=Sales.Year"); | |
cells["B2"].PutValue("&=Sales.Item1"); | |
cells["C2"].PutValue("&=Sales.Item2"); | |
cells["D2"].PutValue("&=Sales.Item3"); | |
cells["E2"].PutValue("&=Sales.Item4"); | |
cells["F2"].PutValue("&=Sales.Item5"); | |
cells["G2"].PutValue("&=Sales.Item6"); | |
cells["H2"].PutValue("&=Sales.Item7"); | |
cells["I2"].PutValue("&=Sales.Item8"); | |
cells["J2"].PutValue("&=Sales.Item9"); | |
cells["K2"].PutValue("&=Sales.Item10"); | |
cells["L2"].PutValue("&=Sales.Item11"); | |
cells["M2"].PutValue("&=Sales.Item12"); |
This file contains hidden or 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 an instance of DataTable and name is according to the Smart Markers | |
var table = new DataTable("Sales"); | |
/* | |
* Add columns to the newly created DataTable while specifying the column type | |
* It is important that the DataTable should have at least one column for each | |
* Smart Marker entry from the designer spreadsheet | |
*/ | |
table.Columns.Add("Year", typeof(string)); | |
table.Columns.Add("Item1", typeof(int)); | |
table.Columns.Add("Item2", typeof(int)); | |
table.Columns.Add("Item3", typeof(int)); | |
table.Columns.Add("Item4", typeof(int)); | |
table.Columns.Add("Item5", typeof(int)); | |
table.Columns.Add("Item6", typeof(int)); | |
table.Columns.Add("Item7", typeof(int)); | |
table.Columns.Add("Item8", typeof(int)); | |
table.Columns.Add("Item9", typeof(int)); | |
table.Columns.Add("Item10", typeof(int)); | |
table.Columns.Add("Item11", typeof(int)); | |
table.Columns.Add("Item12", typeof(int)); | |
// Add some rows with data to the DataTable | |
table.Rows.Add("2000", 2310, 0, 110, 15, 20, 25, 30, 1222, 200, 421, 210, 133); | |
table.Rows.Add("2005", 1508, 0, 170, 280, 190, 400, 105, 132, 303, 199, 120, 100); | |
table.Rows.Add("2010", 0, 210, 230, 140, 150, 160, 170, 110, 1999, 1229, 1120, 2300); | |
table.Rows.Add("2015", 3818, 320, 340, 260, 210, 310, 220, 0, 0, 0, 0, 122); |
This file contains hidden or 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 an instance of WorkbookDesigner class | |
var designer = new WorkbookDesigner(); | |
// Assign the Workbook property to the instance of Workbook created in first step | |
designer.Workbook = book; | |
// Set the data source | |
designer.SetDataSource(table); | |
// Call Process method to populate data | |
designer.Process(); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first chart inside the worksheet | |
Chart chart = worksheet.Charts[0]; | |
// Calculate the Chart first to get the Equation Text of Trendline | |
chart.Calculate(); | |
// Access the Trendline | |
Trendline trendLine = chart.NSeries[0].TrendLines[0]; | |
// Read the Equation Text of Trendline | |
Console.WriteLine("Equation Text: " + trendLine.DataLabels.Text); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from sample Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Access first worksheet of the workbook | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Print worksheet name | |
Console.WriteLine("Sheet Name: " + worksheet.Name); | |
// Access the first chart inside this worksheet | |
Chart chart = worksheet.Charts[0]; | |
// Access the chart's sheet and display its name again | |
Console.WriteLine("Chart's Sheet Name: " + chart.Worksheet.Name); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook | |
Workbook workbook = new Workbook(); | |
// Get the first default sheet | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Add Watermark | |
Shape wordart = sheet.Shapes.AddTextEffect(MsoPresetTextEffect.TextEffect1, | |
"CONFIDENTIAL", "Arial Black", 50, false, true | |
, 18, 8, 1, 1, 130, 800); | |
// Lock Shape Aspects | |
wordart.IsLocked = true; | |
wordart.SetLockedProperty(ShapeLockType.Selection, true); | |
wordart.SetLockedProperty(ShapeLockType.ShapeType, true); | |
wordart.SetLockedProperty(ShapeLockType.Move, true); | |
wordart.SetLockedProperty(ShapeLockType.Resize, true); | |
wordart.SetLockedProperty(ShapeLockType.Text, true); | |
// Get the fill format of the word art | |
FillFormat wordArtFormat = wordart.Fill; | |
// Set the color | |
wordArtFormat.SetOneColorGradient(Color.Red, 0.2, GradientStyleType.Horizontal, 2); | |
// Set the transparency | |
wordArtFormat.Transparency = 0.9; | |
// Make the line invisible | |
wordart.HasLine = false; | |
// Save the file | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load source excel file containing excel 2016 charts | |
Workbook book = new Workbook(dataDir + "excel2016Charts.xlsx"); | |
// Access the first worksheet which contains the charts | |
Worksheet sheet = book.Worksheets[0]; | |
// Access all charts one by one and read their types | |
for (int i = 0; i < sheet.Charts.Count; i++) | |
{ | |
// Access the chart | |
Chart ch = sheet.Charts[i]; | |
// Print chart type | |
Console.WriteLine(ch.Type); | |
// Change the title of the charts as per their types | |
ch.Title.Text = "Chart Type is " + ch.Type.ToString(); | |
} | |
// Save the workbook | |
book.Save(dataDir + "out_excel2016Charts.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Read the source excel file | |
Workbook book = new Workbook(dataDir + "sourceGlowEffectColor.xlsx"); | |
// Access first worksheet | |
Worksheet sheet = book.Worksheets[0]; | |
// Access the shape | |
Shape shape = sheet.Shapes[0]; | |
// Read the glow effect color and its various properties | |
GlowEffect effect = shape.Glow; | |
CellsColor color = effect.Color; | |
Console.WriteLine("Color: " + color.Color); | |
Console.WriteLine("ColorIndex: " + color.ColorIndex); | |
Console.WriteLine("IsShapeColor: " + color.IsShapeColor); | |
Console.WriteLine("Transparency: " + color.Transparency); | |
Console.WriteLine("Type: " + color.Type); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from source file | |
Workbook workbook = new Workbook(dataDir + "LinkedShape.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Change the value of cell A1 | |
Cell cell = worksheet.Cells["A1"]; | |
cell.PutValue(100); | |
// Update the value of the Linked Picture which is linked to cell A1 | |
worksheet.Shapes.UpdateSelectedValue(); | |
// Save the workbook in pdf format | |
workbook.Save(dataDir + "output_out.pdf", SaveFormat.Pdf); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook containing the Chart | |
var book = new Workbook(dataDir + "source.xlsx"); | |
// Access the Worksheet that contains the Chart | |
var sheet = book.Worksheets[0]; | |
foreach (Chart chart in sheet.Charts) | |
{ | |
for (int index = 0; index < chart.NSeries.Count; index++) | |
{ | |
// Access the DataLabels of indexed NSeries | |
var labels = chart.NSeries[index].DataLabels; | |
// Set ResizeShapeToFitText property to true | |
labels.IsResizeShapeToFitText = true; | |
} | |
// Calculate Chart | |
chart.Calculate(); | |
} | |
// Save the result | |
book.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook from source Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first chart inside the sheet | |
Chart chart = worksheet.Charts[0]; | |
// Access the data label of first series first point | |
DataLabels dlbls = chart.NSeries[0].Points[0].DataLabels; | |
// Set data label text | |
dlbls.Text = "Rich Text Label"; | |
// Set the font setting of the first 10 characters | |
FontSetting fntSetting = dlbls.Characters(0, 10); | |
fntSetting.Font.Color = Color.Red; | |
fntSetting.Font.IsBold = true; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Set the name of worksheet | |
sheet.Name = "Data"; | |
// Get the cells collection in the sheet. | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Put some values into a cells of the Data sheet. | |
cells["A1"].PutValue("Region"); | |
cells["A2"].PutValue("France"); | |
cells["A3"].PutValue("Germany"); | |
cells["A4"].PutValue("England"); | |
cells["A5"].PutValue("Sweden"); | |
cells["A6"].PutValue("Italy"); | |
cells["A7"].PutValue("Spain"); | |
cells["A8"].PutValue("Portugal"); | |
cells["B1"].PutValue("Sale"); | |
cells["B2"].PutValue(70000); | |
cells["B3"].PutValue(55000); | |
cells["B4"].PutValue(30000); | |
cells["B5"].PutValue(40000); | |
cells["B6"].PutValue(35000); | |
cells["B7"].PutValue(32000); | |
cells["B8"].PutValue(10000); | |
// Add a chart sheet. | |
int sheetIndex = workbook.Worksheets.Add(SheetType.Chart); | |
sheet = workbook.Worksheets[sheetIndex]; | |
// Set the name of worksheet | |
sheet.Name = "Chart"; | |
// Create chart | |
int chartIndex = 0; | |
chartIndex = sheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 1, 1, 25, 10); | |
Aspose.Cells.Charts.Chart chart = sheet.Charts[chartIndex]; | |
// Set some properties of chart plot area. | |
// To set a picture as fill format and make the border invisible. | |
FileStream fs = File.OpenRead(dataDir+ "aspose.png"); | |
byte[] data = new byte[fs.Length]; | |
fs.Read(data, 0, data.Length); | |
chart.PlotArea.Area.FillFormat.ImageData = data; | |
chart.PlotArea.Border.IsVisible = false; | |
// Set properties of chart title | |
chart.Title.Text = "Sales By Region"; | |
chart.Title.Font.Color = Color.Blue; | |
chart.Title.Font.IsBold = true; | |
chart.Title.Font.Size = 12; | |
// Set properties of nseries | |
chart.NSeries.Add("Data!B2:B8", true); | |
chart.NSeries.CategoryData = "Data!A2:A8"; | |
chart.NSeries.IsColorVaried = true; | |
// Set the Legend. | |
Aspose.Cells.Charts.Legend legend = chart.Legend; | |
legend.Position = Aspose.Cells.Charts.LegendPositionType.Top; | |
// Save the excel file | |
workbook.Save(dataDir + "column_chart_out.xls"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from the source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the chart inside the worksheet | |
Chart chart = worksheet.Charts[0]; | |
// Check the "Label Contains - Value From Cells" | |
DataLabels dataLabels = chart.NSeries[0].DataLabels; | |
dataLabels.ShowCellRange = true; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook object | |
var workbook = new Workbook(); | |
// Get the first worksheet | |
var worksheet = workbook.Worksheets[0]; | |
// Create a range in the second worksheet | |
var range = worksheet.Cells.CreateRange("C21", "C24"); | |
// Name the range | |
range.Name = "MyRange"; | |
// Fill different cells with data in the range | |
range[0, 0].PutValue("North"); | |
range[1, 0].PutValue("South"); | |
range[2, 0].PutValue("East"); | |
range[3, 0].PutValue("West"); | |
ComboBox comboBox = worksheet.Shapes.AddComboBox(15, 0, 2, 0, 17, 64); | |
comboBox.InputRange = "=MyRange"; | |
comboBox.LinkedCell = "=B16"; | |
comboBox.SelectedIndex = 0; | |
Cell cell = worksheet.Cells["B16"]; | |
Style style = cell.GetStyle(); | |
style.Font.Color = Color.White; | |
cell.SetStyle(style); | |
worksheet.Cells["C16"].Formula = "=INDEX(Sheet1!$C$21:$C$24,$B$16,1)"; | |
// Put some data for chart source | |
// Data Headers | |
worksheet.Cells["D15"].PutValue("Jan"); | |
worksheet.Cells["D20"].PutValue("Jan"); | |
worksheet.Cells["E15"].PutValue("Feb"); | |
worksheet.Cells["E20"].PutValue("Feb"); | |
worksheet.Cells["F15"].PutValue("Mar"); | |
worksheet.Cells["F20"].PutValue("Mar"); | |
worksheet.Cells["G15"].PutValue("Apr"); | |
worksheet.Cells["G20"].PutValue("Apr"); | |
worksheet.Cells["H15"].PutValue("May"); | |
worksheet.Cells["H20"].PutValue("May"); | |
worksheet.Cells["I15"].PutValue("Jun"); | |
worksheet.Cells["I20"].PutValue("Jun"); | |
// Data | |
worksheet.Cells["D21"].PutValue(304); | |
worksheet.Cells["D22"].PutValue(402); | |
worksheet.Cells["D23"].PutValue(321); | |
worksheet.Cells["D24"].PutValue(123); | |
worksheet.Cells["E21"].PutValue(300); | |
worksheet.Cells["E22"].PutValue(500); | |
worksheet.Cells["E23"].PutValue(219); | |
worksheet.Cells["E24"].PutValue(422); | |
worksheet.Cells["F21"].PutValue(222); | |
worksheet.Cells["F22"].PutValue(331); | |
worksheet.Cells["F23"].PutValue(112); | |
worksheet.Cells["F24"].PutValue(350); | |
worksheet.Cells["G21"].PutValue(100); | |
worksheet.Cells["G22"].PutValue(200); | |
worksheet.Cells["G23"].PutValue(300); | |
worksheet.Cells["G24"].PutValue(400); | |
worksheet.Cells["H21"].PutValue(200); | |
worksheet.Cells["H22"].PutValue(300); | |
worksheet.Cells["H23"].PutValue(400); | |
worksheet.Cells["H24"].PutValue(500); | |
worksheet.Cells["I21"].PutValue(400); | |
worksheet.Cells["I22"].PutValue(200); | |
worksheet.Cells["I23"].PutValue(200); | |
worksheet.Cells["I24"].PutValue(100); | |
// Dynamically load data on selection of Dropdown value | |
worksheet.Cells["D16"].Formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,2,FALSE),0)"; | |
worksheet.Cells["E16"].Formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,3,FALSE),0)"; | |
worksheet.Cells["F16"].Formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,4,FALSE),0)"; | |
worksheet.Cells["G16"].Formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,5,FALSE),0)"; | |
worksheet.Cells["H16"].Formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,6,FALSE),0)"; | |
worksheet.Cells["I16"].Formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,7,FALSE),0)"; | |
// Create Chart | |
int index = worksheet.Charts.Add(ChartType.Column, 0, 3, 12, 9); | |
Chart chart = worksheet.Charts[index]; | |
chart.NSeries.Add("='Sheet1'!$D$16:$I$16", false); | |
chart.NSeries[0].Name = "=C16"; | |
chart.NSeries.CategoryData = "=$D$15:$I$15"; | |
// Save result on disc | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add some data in cells | |
worksheet.Cells["A1"].PutValue("2-Color Scale"); | |
worksheet.Cells["D1"].PutValue("3-Color Scale"); | |
for (int i = 2; i <= 15; i++) | |
{ | |
worksheet.Cells["A" + i].PutValue(i); | |
worksheet.Cells["D" + i].PutValue(i); | |
} | |
// Adding 2-Color Scale Conditional Formatting | |
CellArea ca = CellArea.CreateCellArea("A2", "A15"); | |
int idx = worksheet.ConditionalFormattings.Add(); | |
FormatConditionCollection fcc = worksheet.ConditionalFormattings[idx]; | |
fcc.AddCondition(FormatConditionType.ColorScale); | |
fcc.AddArea(ca); | |
FormatCondition fc = worksheet.ConditionalFormattings[idx][0]; | |
fc.ColorScale.Is3ColorScale = false; | |
fc.ColorScale.MaxColor = Color.LightBlue; | |
fc.ColorScale.MinColor = Color.LightGreen; | |
// Adding 3-Color Scale Conditional Formatting | |
ca = CellArea.CreateCellArea("D2", "D15"); | |
idx = worksheet.ConditionalFormattings.Add(); | |
fcc = worksheet.ConditionalFormattings[idx]; | |
fcc.AddCondition(FormatConditionType.ColorScale); | |
fcc.AddArea(ca); | |
fc = worksheet.ConditionalFormattings[idx][0]; | |
fc.ColorScale.Is3ColorScale = true; | |
fc.ColorScale.MaxColor = Color.LightBlue; | |
fc.ColorScale.MidColor = Color.Yellow; | |
fc.ColorScale.MinColor = Color.LightGreen; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook or load existing | |
var book = new Workbook(); | |
// Access the Worksheet on which desired rule has to be applied | |
var sheet = book.Worksheets[0]; | |
// Add FormatConditions to the instance of Worksheet | |
int idx = sheet.ConditionalFormattings.Add(); | |
// Access the newly added FormatConditions via its index | |
var conditionCollection = sheet.ConditionalFormattings[idx]; | |
// Define a CellsArea on which conditional formatting will be applicable | |
// The code creates a CellArea ranging from A1 to I20 | |
var area = CellArea.CreateCellArea("A1", "I20"); | |
//Add area to the instance of FormatConditions | |
conditionCollection.AddArea(area); | |
// Add a condition to the instance of FormatConditions | |
// For this case, the condition type is expression, which is based on some formula | |
idx = conditionCollection.AddCondition(FormatConditionType.Expression); | |
// Access the newly added FormatCondition via its index | |
FormatCondition formatCondirion = conditionCollection[idx]; | |
// Set the formula for the FormatCondition | |
// Formula uses the Excel's built-in functions as discussed earlier in this article | |
formatCondirion.Formula1 = @"=MOD(ROW(),2)=0"; | |
// Set the background color and patter for the FormatCondition's Style | |
formatCondirion.Style.BackgroundColor = Color.Blue; | |
formatCondirion.Style.Pattern = BackgroundType.Solid; | |
// Save the result on disk | |
book.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source excel file | |
Workbook workbook = new Workbook(dataDir + "source.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); | |
// Access the conditional formatting databar | |
DataBar dbar = fcc[0].DataBar; | |
// Create image or print options | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.ImageFormat = ImageFormat.Png; | |
// Get the image bytes of the databar | |
byte[] imgBytes = dbar.ToImage(cell, opts); | |
// Write image bytes on the disk | |
File.WriteAllBytes(dataDir + "databar_out.png", imgBytes); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "WebQuerySample.xlsx"); | |
ExternalConnection connection = workbook.DataConnections[0]; | |
if (connection is WebQueryConnection) | |
{ | |
WebQueryConnection webQuery = (WebQueryConnection)connection; | |
Console.WriteLine("Web Query URL: " + webQuery.Url); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(dataDir + "DataConnection.xlsx"); | |
// Access first Data Connection | |
ExternalConnection conn = workbook.DataConnections[0]; | |
// Change the Data Connection Name and Odc file | |
conn.Name = "MyConnectionName"; | |
conn.OdcFile = "C:\\Users\\MyDefaulConnection.odc"; | |
// Change the Command Type, Command and Connection String | |
DBConnection dbConn = conn as DBConnection; | |
dbConn.CommandType = OLEDBCommandType.SqlStatement; | |
dbConn.Command = "Select * from AdminTable"; | |
dbConn.ConnectionInfo = "Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False"; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 workbook from source excel file | |
Workbook wb = new Workbook("Query TXT.xlsx"); | |
// Display the address(range) of result range of query table | |
Console.WriteLine(wb.Worksheets[0].QueryTables[0].ResultRange.Address); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from source excel file | |
Workbook workbook = new Workbook(dataDir + "Sample.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first Query Table | |
QueryTable qt = worksheet.QueryTables[0]; | |
// Print Query Table Data | |
Console.WriteLine("Adjust Column Width: " + qt.AdjustColumnWidth); | |
Console.WriteLine("Preserve Formatting: " + qt.PreserveFormatting); | |
// Now set Preserve Formatting to true | |
qt.PreserveFormatting = true; | |
// Save the workbook | |
workbook.Save(dataDir + "Output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook object from source file | |
Workbook workbook = new Workbook(dataDir+ "connection.xlsx"); | |
// Access the external collections | |
ExternalConnectionCollection connections = workbook.DataConnections; | |
int connectionCount = connections.Count; | |
ExternalConnection connection = null; | |
for (int i = 0; i < connectionCount; i++) | |
{ | |
connection = connections[i]; | |
// Check if the Connection is DBConnection, then retrieve its various properties | |
if (connection is DBConnection) | |
{ | |
DBConnection dbConn = (DBConnection)connection; | |
// Retrieve DB Connection Command | |
Console.WriteLine("Command: " + dbConn.Command); | |
// Retrieve DB Connection Command Type | |
Console.WriteLine("Command Type: " + dbConn.CommandType); | |
// Retrieve DB Connection Description | |
Console.WriteLine("Description: " + dbConn.ConnectionDescription); | |
// Retrieve DB Connection ID | |
Console.WriteLine("Id: " + dbConn.ConnectionId); | |
// Retrieve DB Connection Info | |
Console.WriteLine("Info: " + dbConn.ConnectionInfo); | |
// Retrieve DB Connection Credentials | |
Console.WriteLine("Credentials: " + dbConn.Credentials); | |
// Retrieve DB Connection Name | |
Console.WriteLine("Name: " + dbConn.Name); | |
// Retrieve DB Connection ODC File | |
Console.WriteLine("OdcFile: " + dbConn.OdcFile); | |
// Retrieve DB Connection Source File | |
Console.WriteLine("Source file: " + dbConn.SourceFile); | |
// Retrieve DB Connection Type | |
Console.WriteLine("Type: " + dbConn.Type); | |
// Retrieve DB Connection Parameters Collection | |
ConnectionParameterCollection paramCollection = dbConn.Parameters; | |
int paramCount = paramCollection.Count; | |
// Iterate the Parameter Collection | |
for (int j = 0; j < paramCount; j++) | |
{ | |
ConnectionParameter param = paramCollection[j]; | |
// Retrieve Parameter Cell Reference | |
Console.WriteLine("Cell reference: " + param.CellReference); | |
// Retrieve Parameter Name | |
Console.WriteLine("Parameter name: " + param.Name); | |
// Retrieve Parameter Prompt | |
Console.WriteLine("Prompt: " + param.Prompt); | |
// Retrieve Parameter SQL Type | |
Console.WriteLine("SQL Type: " + param.SqlType); | |
// Retrieve Parameter Type | |
Console.WriteLine("Param Type: " + param.Type); | |
// Retrieve Parameter Value | |
Console.WriteLine("Param Value: " + param.Value); | |
}// End for | |
}// End if | |
}// End for |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cell D5 which lies inside the table | |
Cell cell = worksheet.Cells["D5"]; | |
// Put value inside the cell D5 | |
cell.PutValue("D5 Data"); | |
// Access the Table from this cell | |
ListObject table = cell.GetTable(); | |
// Add some value using Row and Column Offset | |
table.PutCellValue(2, 2, "Offset [2,2]"); | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
Cell cell = worksheet.Cells["A1"]; | |
cell.HtmlString = "<Font Style=\"FONT-WEIGHT: bold;FONT-STYLE: italic;TEXT-DECORATION: underline;FONT-FAMILY: Arial;FONT-SIZE: 11pt;COLOR: #ff0000;\">This is simple HTML formatted text.</Font>"; | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cell B2 and add some value inside it | |
Cell cell = worksheet.Cells["B2"]; | |
cell.PutValue("Welcome to Aspose!"); | |
// Enlarge its font to size 16 | |
Style style = cell.GetStyle(); | |
style.Font.Size = 16; | |
cell.SetStyle(style); | |
// Calculate the width and height of the cell value in unit of pixels | |
int widthOfValue = cell.GetWidthOfValue(); | |
int heightOfValue = cell.GetHeightOfValue(); | |
// Print both values | |
Console.WriteLine("Width of Cell Value: " + widthOfValue); | |
Console.WriteLine("Height of Cell Value: " + heightOfValue); | |
// Set the row height and column width to adjust/fit the cell value inside cell | |
worksheet.Cells.SetColumnWidthPixel(1, widthOfValue); | |
worksheet.Cells.SetRowHeightPixel(1, heightOfValue); | |
// Save the output excel file | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Source worksheet | |
Worksheet srcSheet = workbook.Worksheets[0]; | |
// Add destination worksheet | |
Worksheet dstSheet = workbook.Worksheets.Add("Destination Sheet"); | |
// Set the row height of the 4th row. This row height will be copied to destination range | |
srcSheet.Cells.SetRowHeight(3, 50); | |
// Create source range to be copied | |
Range srcRange = srcSheet.Cells.CreateRange("A1:D10"); | |
// Create destination range in destination worksheet | |
Range dstRange = dstSheet.Cells.CreateRange("A1:D10"); | |
// PasteOptions, we want to copy row heights of source range to destination range | |
PasteOptions opts = new PasteOptions(); | |
opts.PasteType = PasteType.RowHeights; | |
// Copy source range to destination range with paste options | |
dstRange.Copy(srcRange, opts); | |
// Write informative message in cell D4 of destination worksheet | |
dstSheet.Cells["D4"].PutValue("Row heights of source range copied to destination range"); | |
// Save the workbook in xlsx format | |
workbook.Save(dataDir + "output_out.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cell A1 | |
Cell cell = worksheet.Cells["A1"]; | |
// Put value inside the cell | |
cell.PutValue(0.012345); | |
// Format the cell that it should display 0.01 instead of 0.012345 | |
Style style = cell.GetStyle(); | |
style.Number = 2; | |
cell.SetStyle(style); | |
// Get string value as Cell Style | |
string value = cell.GetStringValue(CellValueFormatStrategy.CellStyle); | |
Console.WriteLine(value); | |
// Get string value without any formatting | |
value = cell.GetStringValue(CellValueFormatStrategy.None); | |
Console.WriteLine(value); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate the workbook from sample Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Access its first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Cell C1 has the Decimal Validation applied on it. It can take only the values Between 10 and 20 | |
Cell cell = worksheet.Cells["C1"]; | |
// Access the valditation applied on this cell | |
Validation validation = cell.GetValidation(); | |
// Read various properties of the validation | |
Console.WriteLine("Reading Properties of Validation"); | |
Console.WriteLine("--------------------------------"); | |
Console.WriteLine("Type: " + validation.Type); | |
Console.WriteLine("Operator: " + validation.Operator); | |
Console.WriteLine("Formula1: " + validation.Formula1); | |
Console.WriteLine("Formula2: " + validation.Formula2); | |
Console.WriteLine("Ignore blank: " + validation.IgnoreBlank); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load a file in an instance of Workbook | |
var book = new Workbook(dataDir + "sample.xlsx"); | |
// Get the enumerator from Cells collection | |
IEnumerator cellEnumerator = book.Worksheets[0].Cells.GetEnumerator(); | |
// Traverse cells in the collection | |
while (cellEnumerator.MoveNext()) | |
{ | |
var cell = cellEnumerator.Current as Aspose.Cells.Cell; | |
Console.WriteLine(cell.Name + " " + cell.Value); | |
} | |
// Get enumerator from an object of Row | |
IEnumerator rowEnumerator = book.Worksheets[0].Cells.Rows[0].GetEnumerator(); | |
// Traverse cells in the given row | |
while (rowEnumerator.MoveNext()) | |
{ | |
var cell = rowEnumerator.Current as Aspose.Cells.Cell; | |
Console.WriteLine(cell.Name + " " + cell.Value); | |
} | |
// Get enumerator from an object of Range | |
IEnumerator rangeEnumerator = book.Worksheets[0].Cells.CreateRange("A1:B10").GetEnumerator(); | |
// Traverse cells in the range | |
while (rangeEnumerator.MoveNext()) | |
{ | |
var cell = rangeEnumerator.Current as Aspose.Cells.Cell; | |
Console.WriteLine(cell.Name + " " + cell.Value); | |
} |
This file contains hidden or 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 | |
// Get the enumerator for ColumnsCollection | |
IEnumerator colsEnumerator = book.Worksheets[0].Cells.Columns.GetEnumerator(); | |
// Traverse columns in the collection | |
while (colsEnumerator.MoveNext()) | |
{ | |
var col = colsEnumerator.Current as Aspose.Cells.Column; | |
Console.WriteLine(col.Index); | |
} |
This file contains hidden or 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 | |
// Get the enumerator for RowCollection | |
IEnumerator rowsEnumerator = book.Worksheets[0].Cells.Rows.GetEnumerator(); | |
// Traverse rows in the collection | |
while (rowsEnumerator.MoveNext()) | |
{ | |
var row = rowsEnumerator.Current as Aspose.Cells.Row; | |
Console.WriteLine(row.Index); | |
} |
This file contains hidden or 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 | |
// Get Cells collection of first worksheet | |
var cells = book.Worksheets[0].Cells; | |
// Get the MaxDisplayRange | |
var displayRange = cells.MaxDisplayRange; | |
// Loop over all cells in the MaxDisplayRange | |
for (int row = displayRange.FirstRow; row < displayRange.RowCount; row++) | |
{ | |
for (int col = displayRange.FirstColumn; col < displayRange.ColumnCount; col++) | |
{ | |
// Read the Cell value | |
Console.WriteLine(displayRange[row, col].StringValue); | |
} | |
} |
This file contains hidden or 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 | |
// Get Cells collection of first worksheet | |
var cells2 = book.Worksheets[0].Cells; | |
// Loop over all cells | |
for (int row = 0; row < cells2.MaxDataRow; row++) | |
{ | |
for (int col = 0; col < cells2.MaxDataColumn; col++) | |
{ | |
// Read the Cell value | |
Console.WriteLine(cells2[row, col].StringValue); | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook | |
Workbook workbook = new Workbook(); | |
// Populate Data into Cells | |
Cells cells = workbook.Worksheets[0].Cells; | |
cells["A1"].PutValue("data1"); | |
cells["B1"].PutValue("data2"); | |
cells["A2"].PutValue("data3"); | |
cells["B2"].PutValue("data4"); | |
// Save workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate the workbook from sample Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
/* | |
* Access Cell C1 | |
* Cell C1 has the Decimal Validation applied on it. | |
* It can take only the values Between 10 and 20 | |
*/ | |
Cell cell = worksheet.Cells["C1"]; | |
// Enter 3 inside this cell, Since it is not between 10 and 20, it should fail the validation | |
cell.PutValue(3); | |
// Check if number 3 satisfies the Data Validation rule applied on this cell | |
Console.WriteLine("Is 3 a Valid Value for this Cell: " + cell.GetValidationValue()); | |
// Enter 15 inside this cell, Since it is between 10 and 20, it should succeed the validation | |
cell.PutValue(15); | |
// Check if number 15 satisfies the Data Validation rule applied on this cell | |
Console.WriteLine("Is 15 a Valid Value for this Cell: " + cell.GetValidationValue()); | |
// Enter 30 inside this cell, Since it is not between 10 and 20, it should fail the validation again | |
cell.PutValue(30); | |
// Check if number 30 satisfies the Data Validation rule applied on this cell | |
Console.WriteLine("Is 30 a Valid Value for this Cell: " + cell.GetValidationValue()); |
This file contains hidden or 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 | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string outputPath = dataDir + "Output_out.xlsm"; | |
Workbook workbook = new Workbook(); | |
VbaProject vbaProj = workbook.VbaProject; | |
vbaProj.References.AddRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation"); | |
vbaProj.References.AddRegisteredReference("Office", "*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE14\\MSO.DLL#Microsoft Office 14.0 Object Library"); | |
workbook.Save(outputPath); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create new workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add VBA Module | |
int idx = workbook.VbaProject.Modules.Add(worksheet); | |
// Access the VBA Module, set its name and codes | |
Aspose.Cells.Vba.VbaModule module = workbook.VbaProject.Modules[idx]; | |
module.Name = "TestModule"; | |
module.Codes = "Sub ShowMessage()" + "\r\n" + | |
" MsgBox \"Welcome to Aspose!\"" + "\r\n" + | |
"End Sub"; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsm", SaveFormat.Xlsm); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
if (!System.IO.Directory.Exists(dataDir)) | |
{ | |
System.IO.Directory.CreateDirectory(dataDir); | |
} | |
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(); | |
Aspose.Cells.Worksheet sheet = workbook.Worksheets[0]; | |
int moduleIdx = workbook.VbaProject.Modules.Add(sheet); | |
Aspose.Cells.Vba.VbaModule module = workbook.VbaProject.Modules[moduleIdx]; | |
module.Codes = | |
"Sub ShowMessage()" + "\r\n" + | |
" MsgBox \"Welcome to Aspose!\"" + "\r\n" + | |
"End Sub"; | |
Aspose.Cells.Drawing.Button button = sheet.Shapes.AddButton(2, 0, 2, 0, 28, 80); | |
button.Placement = Aspose.Cells.Drawing.PlacementType.FreeFloating; | |
button.Font.Name = "Tahoma"; | |
button.Font.IsBold = true; | |
button.Font.Color = System.Drawing.Color.Blue; | |
button.Text = "Aspose"; | |
button.MacroName = sheet.Name + ".ShowMessage"; | |
dataDir = dataDir + "Output.out.xlsm"; | |
workbook.Save(dataDir); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "sampleVBAProjectSigned.xlsm"); | |
Console.WriteLine("Is VBA Code Project Signed: " + workbook.VbaProject.IsSigned); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "Sample1.xlsx"); | |
Console.WriteLine("VBA Project is Signed: " + workbook.VbaProject.IsSigned); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "sampleVBAProjectSigned.xlsm"); | |
// Signature is valid | |
Console.WriteLine("Is VBA Code Project Valid Signed: " + workbook.VbaProject.IsValidSigned); | |
// Modify the VBA Code, save the workbook then reload | |
// VBA Code Signature will now be invalid | |
string code = workbook.VbaProject.Modules[1].Codes; | |
code = code.Replace("Welcome to Aspose", "Welcome to Aspose.Cells"); | |
workbook.VbaProject.Modules[1].Codes = code; | |
// Save | |
workbook.Save(dataDir + "output_out.xlsm"); | |
// Reload | |
workbook = new Workbook(dataDir + "output_out.xlsm"); | |
// Now the signature is invalid | |
Console.WriteLine("Is VBA Code Project Valid Signed: " + workbook.VbaProject.IsValidSigned); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from excel file | |
Workbook wb = new Workbook(dataDir + "Book1.xlsm"); | |
// Please use System.Security.Cryptography.X509Certificates namespace for X509Certificate2 class | |
X509Certificate2 cert = new X509Certificate2(dataDir + "SampleCert.pfx", "1234"); | |
// Create a Digital Signature | |
DigitalSignature ds = new DigitalSignature(cert, "Signing Digital Signature using Aspose.Cells", DateTime.Now); | |
// Sign VBA Code Project with Digital Signature | |
wb.VbaProject.Sign(ds); | |
// Save the workbook | |
wb.Save(dataDir + "DigitallySigned_out.xlsm"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load your source excel file into workbook object | |
Workbook workbook = new Workbook(dataDir + "sampleVBAProjectSigned.xlsm"); | |
// Retrieve bytes data of Digital Certificate of VBA Project | |
byte[] certBytes = workbook.VbaProject.CertRawData; | |
// Save Certificate Data into FileStream | |
File.WriteAllBytes(dataDir + "Cert_out_", certBytes); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsm"); | |
// Change the VBA Module Code | |
foreach (VbaModule module in workbook.VbaProject.Modules) | |
{ | |
string code = module.Codes; | |
// Replace the original message with the modified message | |
if (code.Contains("This is test message.")) | |
{ | |
code = code.Replace("This is test message.", "This is Aspose.Cells message."); | |
module.Codes = code; | |
} | |
} | |
// Save the output Excel file | |
workbook.Save(dataDir + "output_out.xlsm"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// dsc is signature collection contains one or more signature needed to sign | |
DigitalSignatureCollection dsc = new DigitalSignatureCollection(); | |
// Cert must contain private key, it can be contructed from cert file or windows certificate collection. aa is password of cert | |
X509Certificate2 cert = new X509Certificate2(dataDir + "mykey2.pfx", "aa"); | |
DigitalSignature ds = new DigitalSignature(cert, "test for sign", DateTime.Now); | |
dsc.Add(ds); | |
Workbook wb = new Workbook(); | |
// wb.SetDigitalSignature signs all signatures in dsc | |
wb.SetDigitalSignature(dsc); | |
wb.Save(dataDir + @"newfile_out.xlsx"); | |
// open the file | |
wb = new Workbook(dataDir + @"newfile_out.xlsx"); | |
System.Console.WriteLine(wb.IsDigitallySigned); | |
// Get digitalSignature collection from workbook | |
dsc = wb.GetDigitalSignature(); | |
foreach (DigitalSignature dst in dsc) | |
{ | |
System.Console.WriteLine(dst.Comments); //test for sign -OK | |
System.Console.WriteLine(dst.SignTime); //11/25/2010 1:22:01 PM -OK | |
System.Console.WriteLine(dst.IsValid); //True -OK | |
} |
This file contains hidden or 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 workbook object | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Put some data in these cells | |
worksheet.Cells["A4"].PutValue("Test"); | |
worksheet.Cells["S4"].PutValue("Test"); | |
// Set paper size | |
worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4; | |
// Set fit to pages wide as 1 | |
worksheet.PageSetup.FitToPagesWide = 1; | |
// Calculate page scale via sheet render | |
SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions()); | |
// Convert page scale double value to percentage | |
string strPageScale = sr.PageScale.ToString("0%"); | |
// Write the page scale value | |
Console.WriteLine(strPageScale); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load sample excel file | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access the first sheet which contains chart | |
Worksheet source = wb.Worksheets[0]; | |
// Add another sheet named DestSheet | |
Worksheet destination = wb.Worksheets.Add("DestSheet"); | |
// Set CopyOptions.ReferToDestinationSheet to true | |
CopyOptions options = new CopyOptions(); | |
options.ReferToDestinationSheet = true; | |
// Copy all the rows of source worksheet to destination worksheet which includes chart as well | |
// The chart data source will now refer to DestSheet | |
destination.Cells.CopyRows(source.Cells, 0, 0, source.Cells.MaxDisplayRange.RowCount, options); | |
// Save workbook in xlsx format | |
wb.Save(dataDir + "output_out.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook and load a spreadsheet | |
var book = new Workbook(dataDir + "sample.xlsx"); | |
// Access the protected Worksheet | |
var sheet = book.Worksheets[0]; | |
// Check if Worksheet is password protected | |
if (sheet.Protection.IsProtectedWithPassword) | |
{ | |
Console.WriteLine("Worksheet is password protected"); | |
} | |
else | |
{ | |
Console.WriteLine("Worksheet is not password protected"); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specify password to open inside the load options | |
LoadOptions opts = new LoadOptions(); | |
opts.Password = "1234"; | |
// Open the source Excel file with load options | |
Workbook workbook = new Workbook(dataDir + "sampleBook.xlsx", opts); | |
// Check if 567 is Password to modify | |
bool ret = workbook.Settings.WriteProtection.ValidatePassword("567"); | |
Console.WriteLine("Is 567 correct Password to modify: " + ret); | |
// Check if 5679 is Password to modify | |
ret = workbook.Settings.WriteProtection.ValidatePassword("5678"); | |
Console.WriteLine("Is 5678 correct Password to modify: " + ret); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open workbook | |
Workbook workbook = new Workbook(dataDir + "sample.xlsb"); | |
// Save Workbook to XLSM format | |
workbook.Save(dataDir + "output_out.xlsm", SaveFormat.Xlsm); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open a file into the first book. | |
Workbook excelWorkbook1 = new Workbook(dataDir + @"FirstWorkbook.xlsx"); | |
// Copy the first sheet of the first book with in the workbook | |
excelWorkbook1.Worksheets[2].Copy(excelWorkbook1.Worksheets["Copy"]); | |
// Save the file. | |
excelWorkbook1.Save(dataDir + @"FirstWorkbookCopied_out.xlsx"); |
This file contains hidden or 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 | |
// Open a file into the first book. | |
Workbook excelWorkbook3 = new Workbook(dataDir + @"FirstWorkbook.xlsx"); | |
// Open a file into the second book. | |
Workbook excelWorkbook4 = new Workbook(dataDir + @"SecondWorkbook.xlsx"); | |
// Add new worksheet into second Workbook | |
excelWorkbook4.Worksheets.Add(); | |
// Copy the first sheet of the first book into second book. | |
excelWorkbook4.Worksheets[1].Copy(excelWorkbook3.Worksheets["Copy"]); | |
// Save the file. | |
excelWorkbook4.Save(dataDir + @"CopyWorksheetsBetweenWorkbooks_out.xlsx"); |
This file contains hidden or 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 | |
// Open a file into the first book. | |
Workbook excelWorkbook2 = new Workbook(dataDir + @"FirstWorkbook.xlsx"); | |
// Move the sheet | |
excelWorkbook2.Worksheets["Move"].MoveTo(2); | |
// Save the file. | |
excelWorkbook2.Save(dataDir + @"FirstWorkbookMoved_out.xlsx"); |
This file contains hidden or 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 | |
//Open a file into the first book. | |
Workbook excelWorkbook5 = new Workbook(dataDir + @"FirstWorkbook.xlsx"); | |
//Create another Workbook. Open a file into the Second book. | |
Workbook excelWorkbook6 = new Workbook(dataDir + @"SecondWorkbook.xlsx"); | |
//Add New Worksheet | |
excelWorkbook6.Worksheets.Add(); | |
//Copy the sheet from first book into second book. | |
excelWorkbook6.Worksheets[2].Copy(excelWorkbook5.Worksheets[2]); | |
//Remove the copied worksheet from first workbook | |
excelWorkbook5.Worksheets.RemoveAt(2); | |
//Save the file. | |
excelWorkbook5.Save(dataDir + @"FirstWorkbookWithMove_out.xlsx"); | |
//Save the file. | |
excelWorkbook6.Save(dataDir + @"SecondWorkbookWithMove_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook and load an existing spreadsheet | |
var book = new Workbook(dataDir + "sample.xlsx"); | |
// Loop over all worksheets in the workbook | |
for (int i = 0; i < book.Worksheets.Count; i++) | |
{ | |
Worksheet sheet = book.Worksheets[i]; | |
// Check if worksheet has populated cells | |
if (sheet.Cells.MaxDataRow != -1) | |
{ | |
Console.WriteLine(sheet.Name + " is not empty because one or more cells are populated"); | |
} | |
// Check if worksheet has shapes | |
else if (sheet.Shapes.Count > 0) | |
{ | |
Console.WriteLine(sheet.Name + " is not empty because there are one or more shapes"); | |
} | |
// Check if worksheet has empty initialized cells | |
else | |
{ | |
Aspose.Cells.Range range = sheet.Cells.MaxDisplayRange; | |
var rangeIterator = range.GetEnumerator(); | |
if (rangeIterator.MoveNext()) | |
{ | |
Console.WriteLine(sheet.Name + " is not empty because one or more cells are initialized"); | |
} | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
//Detect file format | |
FileFormatInfo info = FileFormatUtil.DetectFileFormat(dataDir + "Book1.xlsx"); | |
//Gets the detected load format | |
Console.WriteLine("The spreadsheet format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat)); | |
//Check if the file is encrypted. | |
Console.WriteLine("The file is encrypted: " + info.IsEncrypted); |
This file contains hidden or 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 | |
// The path to the License File | |
string licPath = @"Aspose.Cells.lic"; | |
// Create workbook object before setting a license | |
Workbook workbook = new Workbook(); | |
// Check if the license is loaded or not. It will return false | |
Console.WriteLine(workbook.IsLicensed); | |
try | |
{ | |
Aspose.Cells.License lic = new Aspose.Cells.License(); | |
lic.SetLicense(licPath); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Check if the license is loaded or not. Now it will return true | |
Console.WriteLine(workbook.IsLicensed); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "Sample.xlsx"); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
for (int i = 0; i < worksheet.Hyperlinks.Count; i++) | |
{ | |
Hyperlink hl = worksheet.Hyperlinks[i]; | |
hl.Address = "http://www.aspose.com"; | |
} | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cell A1 | |
Cell cell = worksheet.Cells["A1"]; | |
// Put value inside the cell | |
cell.PutValue(0.012345); | |
// Format the cell that it should display 0.01 instead of 0.012345 | |
Style style = cell.GetStyle(); | |
style.Number = 2; | |
cell.SetStyle(style); | |
// Display the cell values as it displays in excel | |
Console.WriteLine("Cell String Value: " + cell.StringValue); | |
// Display the cell value without any format | |
Console.WriteLine("Cell String Value without Format: " + cell.StringValueWithoutFormat); | |
// Export Data Table Options with FormatStrategy as CellStyle | |
ExportTableOptions opts = new ExportTableOptions(); | |
opts.ExportAsString = true; | |
opts.FormatStrategy = CellValueFormatStrategy.CellStyle; | |
// Export Data Table | |
DataTable dt = worksheet.Cells.ExportDataTable(0, 0, 1, 1, opts); | |
// Display the value of very first cell | |
Console.WriteLine("Export Data Table with Format Strategy as Cell Style: " + dt.Rows[0][0].ToString()); | |
// Export Data Table Options with FormatStrategy as None | |
opts.FormatStrategy = CellValueFormatStrategy.None; | |
dt = worksheet.Cells.ExportDataTable(0, 0, 1, 1, opts); | |
// Display the value of very first cell | |
Console.WriteLine("Export Data Table with Format Strategy as None: " + dt.Rows[0][0].ToString()); |
This file contains hidden or 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 reference | |
Workbook workbook = null; | |
// Print the version number of Excel 2003 XLS file | |
workbook = new Workbook("Excel2003.xls"); | |
Console.WriteLine("Excel 2003 XLS Version: " + workbook.BuiltInDocumentProperties.Version); | |
// Print the version number of Excel 2007 XLS file | |
workbook = new Workbook("Excel2007.xls"); | |
Console.WriteLine("Excel 2007 XLS Version: " + workbook.BuiltInDocumentProperties.Version); | |
// Print the version number of Excel 2010 XLS file | |
workbook = new Workbook("Excel2010.xls"); | |
Console.WriteLine("Excel 2010 XLS Version: " + workbook.BuiltInDocumentProperties.Version); | |
// Print the version number of Excel 2013 XLS file | |
workbook = new Workbook("Excel2013.xls"); | |
Console.WriteLine("Excel 2013 XLS Version: " + workbook.BuiltInDocumentProperties.Version); | |
// Print the version number of Excel 2007 XLSX file | |
workbook = new Workbook("Excel2007.xlsx"); | |
Console.WriteLine("Excel 2007 XLSX Version: " + workbook.BuiltInDocumentProperties.Version); | |
// Print the version number of Excel 2010 XLSX file | |
workbook = new Workbook("Excel2010.xlsx"); | |
Console.WriteLine("Excel 2010 XLSX Version: " + workbook.BuiltInDocumentProperties.Version); | |
// Print the version number of Excel 2013 XLSX file | |
workbook = new Workbook("Excel2013.xlsx"); | |
Console.WriteLine("Excel 2013 XLSX Version: " + workbook.BuiltInDocumentProperties.Version); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
TxtLoadOptions opts = new TxtLoadOptions(); | |
opts.Separator = ','; | |
opts.HasFormula = true; | |
// Load your CSV file with formulas in a Workbook object | |
Workbook workbook = new Workbook(dataDir + "sample.csv", opts); | |
// You can also import your CSV file like this | |
// The code below is importing CSV file starting from cell D4 | |
Worksheet worksheet = workbook.Worksheets[0]; | |
worksheet.Cells.ImportCSV(dataDir + "sample.csv", opts, 3, 3); | |
// Save your workbook in Xlsx format | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook | |
Workbook workbook = new Workbook(); | |
// URL that contains your XML data for mapping | |
string XML = "http://www.aspose.com/docs/download/attachments/434475650/sampleXML.txt"; | |
// Import your XML Map data starting from cell A1 | |
workbook.ImportXml(XML, "Sheet1", 0, 0); | |
// Save workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specify the load options and filter the data | |
LoadOptions options = new LoadOptions(); | |
// Include everything except charts | |
options.LoadFilter = new LoadFilter(LoadDataFilterOptions.All & ~LoadDataFilterOptions.Chart); | |
// Load the workbook with specified load options | |
Workbook workbook = new Workbook(dataDir + "chart.xlsx", options); | |
// Save the workbook in PDF format | |
workbook.Save(dataDir + "ResultWithoutChart.pdf", SaveFormat.Pdf); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Put some value in cell A1 | |
Cell cell = worksheet.Cells["A1"]; | |
cell.PutValue("Welcome to Aspose!"); | |
// Save ODS in ODF 1.2 version which is default | |
OdsSaveOptions options = new OdsSaveOptions(); | |
workbook.Save(dataDir + "ODF1.2_out.ods", options); | |
// Save ODS in ODF 1.1 version | |
options.IsStrictSchema11 = true; | |
workbook.Save(dataDir + "ODF1.1_out.ods", options); |
This file contains hidden or 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 workbook object | |
Workbook wb1 = new Workbook(); | |
// Call Dispose method | |
wb1.Dispose(); | |
// Call Dispose method via Using statement | |
using (Workbook wb2 = new Workbook()) | |
{ | |
// Any other code goes here | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add 10 in cell A1 and A2 | |
worksheet.Cells["A1"].PutValue(10); | |
worksheet.Cells["A2"].PutValue(10); | |
// Add Sum formula in cell D4 but customize it as --- | |
Cell cell = worksheet.Cells["D4"]; | |
Style style = cell.GetStyle(); | |
style.Custom = "---"; | |
cell.SetStyle(style); | |
// The result of formula will be 20 but 20 will not be visible because the cell is formated as --- | |
cell.Formula = "=Sum(A1:A2)"; | |
// Calculate the workbook | |
workbook.CalculateFormula(); | |
// Create find options, we will search 20 using original values otherwise 20 will never be found because it is formatted as --- | |
FindOptions options = new FindOptions(); | |
options.LookInType = LookInType.OriginalValues; | |
options.LookAtType = LookAtType.EntireContent; | |
Cell foundCell = null; | |
object obj = 20; | |
// Find 20 which is Sum(A1:A2) and formatted as --- | |
foundCell = worksheet.Cells.Find(obj, foundCell, options); | |
// Print the found cell | |
Console.WriteLine(foundCell); | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Read AutoRecover property | |
Console.WriteLine("AutoRecover: " + workbook.Settings.AutoRecover); | |
// Set AutoRecover property to false | |
workbook.Settings.AutoRecover = false; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); | |
// Read the saved workbook again | |
workbook = new Workbook(dataDir + "output_out.xlsx"); | |
// Read AutoRecover property | |
Console.WriteLine("AutoRecover: " + workbook.Settings.AutoRecover); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook and load a spreadsheet | |
var book = new Workbook(dataDir + "Sample.xlsx"); | |
// Access the protected Worksheet | |
var sheet = book.Worksheets[0]; | |
// Check if Worksheet is password protected | |
if (sheet.Protection.IsProtectedWithPassword) | |
{ | |
// Verify the password used to protect the Worksheet | |
if (sheet.Protection.VerifyPassword("1234")) | |
{ | |
Console.WriteLine("Specified password has matched"); | |
} | |
else | |
{ | |
Console.WriteLine("Specified password has not matched"); | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook | |
Workbook workbook = new Workbook(); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Create a range | |
Range range = worksheet.Cells.CreateRange("A1:D4"); | |
// Merge range into a single cell | |
range.Merge(); | |
// Save the workbook | |
workbook.Save(dataDir+ "output.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load your source workbook containing MINIFS and MAXIFS functions | |
Workbook wb = new Workbook(dataDir + "sample_MINIFS_MAXIFS.xlsx"); | |
// Perform Aspose.Cells formula calculation | |
wb.CalculateFormula(); | |
// Save the calculations result in pdf format | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
opts.OnePagePerSheet = true; | |
wb.Save(dataDir + "output_out.pdf", opts); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
/* | |
* Create a workbook. | |
* Open a template file. | |
* In the book1.xls file, we have applied Ms Excel's | |
* Named style i.e., "Percent" to the range "A1:C8". | |
*/ | |
Workbook workbook = new Workbook(dataDir+ "book1.xlsx"); | |
// We get the Percent style and create a style object. | |
Style style = workbook.GetNamedStyle("Percent"); | |
// Change the number format to "0.00%". | |
style.Number = 11; | |
// Set the font color. | |
style.Font.Color = System.Drawing.Color.Red; | |
// Update the style. so, the style of range "A1:C8" will be changed too. | |
style.Update(); | |
// Save the excel file. | |
workbook.Save(dataDir+ "book2.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook. | |
Workbook workbook = new Workbook(); | |
// Create a new style object. | |
Style style = workbook.CreateStyle(); | |
// Set the number format. | |
style.Number = 14; | |
// Set the font color to red color. | |
style.Font.Color = System.Drawing.Color.Red; | |
// Name the style. | |
style.Name = "Date1"; | |
// Get the first worksheet cells. | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Specify the style (described above) to A1 cell. | |
cells["A1"].SetStyle(style); | |
// Create a range (B1:D1). | |
Range range = cells.CreateRange("B1", "D1"); | |
// Initialize styleflag object. | |
StyleFlag flag = new StyleFlag(); | |
// Set all formatting attributes on. | |
flag.All = true; | |
// Apply the style (described above)to the range. | |
range.ApplyStyle(style, flag); | |
// Modify the style (described above) and change the font color from red to black. | |
style.Font.Color = System.Drawing.Color.Black; | |
// Done! Since the named style (described above) has been set to a cell and range, | |
// The change would be Reflected(new modification is implemented) to cell(A1) and // Range (B1:D1). | |
style.Update(); | |
// Save the excel file. | |
workbook.Save(dataDir+ "book_styles.out.xls"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate the workbook object | |
// Open the Excel file | |
Workbook workbook = new Workbook(dataDir+ "book1.xls"); | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Create Cell's area | |
CellArea ca = new CellArea(); | |
ca.StartColumn = 0; | |
ca.EndColumn = 1; | |
ca.StartRow = 0; | |
ca.EndRow = 4; | |
// Move Range | |
cells.MoveRange(ca, 0, 2); | |
// Save the resultant file | |
workbook.Save(dataDir+ "book2.out.xls"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specify the LoadOptions | |
LoadOptions opt = new LoadOptions(); | |
// Set the memory preferences | |
opt.MemorySetting = MemorySetting.MemoryPreference; | |
// Instantiate the Workbook | |
// Load the Big Excel file having large Data set in it | |
Workbook wb = new Workbook(dataDir+ "Book1.xlsx", opt); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook | |
Workbook wb = new Workbook(); | |
// Set the memory preferences | |
// Note: This setting cannot take effect for the existing worksheets that are created before using the below line of code | |
wb.Settings.MemorySetting = MemorySetting.MemoryPreference; | |
// Note: The memory settings also would not work for the default sheet i.e., "Sheet1" etc. automatically created by the Workbook | |
// To change the memory setting of existing sheets, please change memory setting for them manually: | |
Cells cells = wb.Worksheets[0].Cells; | |
cells.MemorySetting = MemorySetting.MemoryPreference; | |
// Input large dataset into the cells of the worksheet. | |
// Your code goes here. | |
// ......... | |
// Get cells of the newly created Worksheet "Sheet2" whose memory setting is same with the one defined in WorkbookSettings: | |
cells = wb.Worksheets.Add("Sheet2").Cells; | |
// ......... | |
// Input large dataset into the cells of the worksheet. | |
// Your code goes here. | |
// ......... |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the template workbook | |
Workbook workbook = new Workbook(dataDir + "CustomerReport.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Setting the orientation to Portrait | |
worksheet.PageSetup.Orientation = PageOrientationType.Portrait; | |
// Setting the scaling factor to 100 | |
// worksheet.PageSetup.Zoom = 100; | |
// OR Alternately you can use Fit to Page Options as under | |
// Setting the number of pages to which the length of the worksheet will be spanned | |
worksheet.PageSetup.FitToPagesTall = 1; | |
// Setting the number of pages to which the width of the worksheet will be spanned | |
worksheet.PageSetup.FitToPagesWide = 1; | |
// Setting the paper size to A4 | |
worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4; | |
// Setting the print quality of the worksheet to 1200 dpi | |
worksheet.PageSetup.PrintQuality = 1200; | |
//Setting the first page number of the worksheet pages | |
worksheet.PageSetup.FirstPageNumber = 2; | |
// Save the workbook | |
workbook.Save(dataDir + "PageSetup_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the template workbook | |
Workbook workbook = new Workbook(dataDir + "PageSetup.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
PageSetup pageSetup = worksheet.PageSetup; | |
// Specifying the cells range (from A1 cell to E30 cell) of the print area | |
pageSetup.PrintArea = "A1:E30"; | |
// Defining column numbers A & E as title columns | |
pageSetup.PrintTitleColumns = "$A:$E"; | |
// Defining row numbers 1 as title rows | |
pageSetup.PrintTitleRows = "$1:$2"; | |
// Allowing to print gridlines | |
pageSetup.PrintGridlines = true; | |
// Allowing to print row/column headings | |
pageSetup.PrintHeadings = true; | |
// Allowing to print worksheet in black & white mode | |
pageSetup.BlackAndWhite = true; | |
// Allowing to print comments as displayed on worksheet | |
pageSetup.PrintComments = PrintCommentsType.PrintInPlace; | |
// Allowing to print worksheet with draft quality | |
pageSetup.PrintDraft = true; | |
// Allowing to print cell errors as N/A | |
pageSetup.PrintErrors = PrintErrorsType.PrintErrorsNA; | |
// Setting the printing order of the pages to over then down | |
pageSetup.Order = PrintOrderType.OverThenDown; | |
// Save the workbook | |
workbook.Save(dataDir + "PageSetup_Print_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source excel file | |
Workbook workbook = new Workbook(dataDir + "pivotTable_sample.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first pivot table | |
PivotTable pivotTable = worksheet.PivotTables[0]; | |
// 1 - Show the pivot table in compact form | |
pivotTable.ShowInCompactForm(); | |
// Refresh the pivot table | |
pivotTable.RefreshData(); | |
pivotTable.CalculateData(); | |
// Save the output | |
workbook.Save(dataDir + "CompactForm_out.xlsx"); | |
// 2 - Show the pivot table in outline form | |
pivotTable.ShowInOutlineForm(); | |
// Refresh the pivot table | |
pivotTable.RefreshData(); | |
pivotTable.CalculateData(); | |
// Save the output | |
workbook.Save(dataDir + "OutlineForm_out.xlsx"); | |
// 3 - Show the pivot table in tabular form | |
pivotTable.ShowInTabularForm(); | |
// Refresh the pivot table | |
pivotTable.RefreshData(); | |
pivotTable.CalculateData(); | |
// Save the output | |
workbook.Save(dataDir + "TabularForm_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first pivot table inside the worksheet | |
PivotTable pivotTable = worksheet.PivotTables[0]; | |
// Access cell by display name of 2nd data field of the pivot table | |
Cell cell = pivotTable.GetCellByDisplayName(pivotTable.DataFields[0].DisplayName); | |
// Access cell style and set its fill color and font color | |
Style style = cell.GetStyle(); | |
style.ForegroundColor = Color.LightBlue; | |
style.Font.Color = Color.Black; | |
// Set the style of the cell | |
pivotTable.Format(cell.Row, cell.Column, style); | |
// Save workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first pivot table object | |
PivotTable pivotTable = worksheet.PivotTables[0]; | |
// Remove pivot table using pivot table object | |
worksheet.PivotTables.Remove(pivotTable); | |
// OR you can remove pivot table using pivot table position by uncommenting below line | |
//worksheet.PivotTables.RemoveAt(0); | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook wb = new Workbook(dataDir + "input.xlsx"); | |
PivotTable pt = wb.Worksheets[0].PivotTables[0]; | |
// Indicating if or not display the empty cell value | |
pt.DisplayNullString = true; | |
// Indicating the null string | |
pt.NullString = "null"; | |
pt.CalculateData(); | |
pt.RefreshDataOnOpeningFile = false; | |
wb.Save(dataDir+ "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook wb = new Workbook(dataDir + "source.xlsx"); | |
Worksheet wsPivot = wb.Worksheets.Add("pvtNew Hardware"); | |
Worksheet wsData = wb.Worksheets["New Hardware - Yearly"]; | |
// Get the pivottables collection for the pivot sheet | |
PivotTableCollection pivotTables = wsPivot.PivotTables; | |
// Add PivotTable to the worksheet | |
int index = pivotTables.Add("='New Hardware - Yearly'!A1:D621", "A3", "HWCounts_PivotTable"); | |
// Get the PivotTable object | |
PivotTable pvtTable = pivotTables[index]; | |
// Add vendor row field | |
pvtTable.AddFieldToArea(PivotFieldType.Row, "Vendor"); | |
// Add item row field | |
pvtTable.AddFieldToArea(PivotFieldType.Row, "Item"); | |
// Add data field | |
pvtTable.AddFieldToArea(PivotFieldType.Data, "2014"); | |
// Turn off the subtotals for the vendor row field | |
PivotField pivotField = pvtTable.RowFields["Vendor"]; | |
pivotField.SetSubtotals(PivotFieldSubtotalType.None, true); | |
// Turn off grand total | |
pvtTable.ColumnGrand = false; | |
/* | |
* Please call the PivotTable.RefreshData() and PivotTable.CalculateData() | |
* before using PivotItem.Position, | |
* PivotItem.PositionInSameParentNode and PivotItem.Move(int count, bool isSameParent). | |
*/ | |
pvtTable.RefreshData(); | |
pvtTable.CalculateData(); | |
pvtTable.RowFields["Item"].PivotItems["4H12"].PositionInSameParentNode = 0; | |
pvtTable.RowFields["Item"].PivotItems["DIF400"].PositionInSameParentNode = 3; | |
/* | |
* As a result of using PivotItem.PositionInSameParentNode, | |
* it will change the original sort sequence. | |
* So when you use PivotItem.PositionInSameParentNode in another parent node. | |
* You need call the method named "CalculateData" again. | |
*/ | |
pvtTable.CalculateData(); | |
pvtTable.RowFields["Item"].PivotItems["CA32"].PositionInSameParentNode = 1; | |
pvtTable.RowFields["Item"].PivotItems["AAA3"].PositionInSameParentNode = 2; | |
// Save file | |
wb.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook book = new Workbook(); | |
// Access first worksheet | |
Worksheet sheet = book.Worksheets[0]; | |
// Add column headings in cell A1 and B1 | |
sheet.Cells[0, 0].PutValue("Column A"); | |
sheet.Cells[0, 1].PutValue("Column B"); | |
// Add list object, set its name and style | |
ListObject listObject = sheet.ListObjects[sheet.ListObjects.Add(0, 0, 1, sheet.Cells.MaxColumn, true)]; | |
listObject.TableStyleType = TableStyleType.TableStyleMedium2; | |
listObject.DisplayName = "Table"; | |
// Set the formula of second column so that it propagates to new rows automatically while entering data | |
listObject.ListColumns[1].Formula = "=[Column A] + 1"; | |
// Save the workbook in xlsx format | |
book.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
public static void Main() | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
} | |
public static Workbook testWorkbook; | |
public static void ThreadLoop() | |
{ | |
Random random = new Random(); | |
while (Thread.CurrentThread.IsAlive) | |
{ | |
try | |
{ | |
int row = random.Next(0, 10000); | |
int col = random.Next(0, 100); | |
string s = testWorkbook.Worksheets[0].Cells[row, col].StringValue; | |
if (s != "R" + row + "C" + col) | |
{ | |
Console.WriteLine("This message will show up when cells read values are incorrect."); | |
} | |
} | |
catch { } | |
} | |
} | |
public static void TestMultiThreadingRead() | |
{ | |
testWorkbook = new Workbook(); | |
testWorkbook.Worksheets.Clear(); | |
testWorkbook.Worksheets.Add("Sheet1"); | |
for (var row = 0; row < 10000; row++) | |
for (var col = 0; col < 100; col++) | |
testWorkbook.Worksheets[0].Cells[row, col].Value = "R" + row + "C" + col; | |
// Commenting this line will show a pop-up message | |
// testWorkbook.Worksheets[0].Cells.MultiThreadReading = true; | |
Thread myThread1; | |
myThread1 = new Thread(new ThreadStart(ThreadLoop)); | |
myThread1.Start(); | |
Thread myThread2; | |
myThread2 = new Thread(new ThreadStart(ThreadLoop)); | |
myThread2.Start(); | |
System.Threading.Thread.Sleep(5 * 1000); | |
myThread1.Abort(); | |
myThread2.Abort(); | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filePath = dataDir + "MultiEncoded.csv"; | |
// Set Multi Encoded Property to True | |
TxtLoadOptions options = new TxtLoadOptions(); | |
options.IsMultiEncoded = true; | |
// Load the CSV file into Workbook | |
Workbook workbook = new Workbook(filePath, options); | |
// Save it in XLSX format | |
workbook.Save( filePath + ".out.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load your source excel file | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Access first shape | |
Shape sh = ws.Shapes[0]; | |
// Set the reflection effect of the shape, set its Blur, Size, Transparency and Distance properties | |
ReflectionEffect re = sh.Reflection; | |
re.Blur = 30; | |
re.Size = 90; | |
re.Transparency = 0; | |
re.Distance = 80; | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load template excel file containing unused styles | |
Workbook workbook = new Workbook(dataDir + "Template-With-Unused-Custom-Style.xlsx"); | |
// Remove all unused styles inside the template this will also remove AsposeStyle which is an unused style inside the template | |
workbook.RemoveUnusedStyles(); | |
// Save the file | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a workbook | |
// Open the template file | |
Workbook book = new Workbook(dataDir+ "MyTestBook1.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = book.Worksheets[0]; | |
// 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.ImageFormat = System.Drawing.Imaging.ImageFormat.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, dataDir+ "img_MyTestBook1.out.emf"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
//Read the source excel file having text with gradient fill | |
Workbook wb = new Workbook(dataDir + "sourceGradientFill.xlsx"); | |
//Save workbook to html format | |
wb.Save(dataDir + "out_sourceGradientFill.html"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cells | |
Cell cell1 = worksheet.Cells["A1"]; | |
Cell cell2 = worksheet.Cells["B1"]; | |
// Set the styles of both cells to Times New Roman | |
Style style = cell1.GetStyle(); | |
style.Font.Name = "Times New Roman"; | |
cell1.SetStyle(style); | |
cell2.SetStyle(style); | |
// Put the values inside the cell | |
cell1.PutValue("Hello without Non-Breaking Hyphen"); | |
cell2.PutValue("Hello" + Convert.ToChar(8209) + " with Non-Breaking Hyphen"); | |
// Autofit the columns | |
worksheet.AutoFitColumns(); | |
// Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity | |
workbook.Save(dataDir + "SampleOutput_out.pdf"); | |
// Save to Pdf after setting PdfSaveOptions.IsFontSubstitutionCharGranularity to true | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
opts.IsFontSubstitutionCharGranularity = true; | |
workbook.Save(dataDir + "SampleOutput2_out.pdf", opts); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source file | |
Workbook workbook = new Workbook(dataDir + "SampleChartBook.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first chart inside the worksheet | |
Aspose.Cells.Charts.Chart chart = worksheet.Charts[0]; | |
// Set image or print options | |
Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions(); | |
opts.SaveFormat = SaveFormat.SVG; | |
// Save the chart to svg format | |
chart.ToImage(dataDir + "Image_out.svg", opts); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source file | |
Workbook workbook = new Workbook(dataDir + "SampleChartBook.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first chart inside the worksheet | |
Aspose.Cells.Charts.Chart chart = worksheet.Charts[0]; | |
// Set image or print options with SVGFitToViewPort true | |
Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions(); | |
opts.SaveFormat = SaveFormat.SVG; | |
opts.SVGFitToViewPort = true; | |
// Save the chart to svg format | |
chart.ToImage(dataDir + "Image_out.svg", opts); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the template workbook | |
Workbook workbook = new Workbook(dataDir + "CustomerReport.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Setting the orientation to Portrait | |
worksheet.PageSetup.Orientation = PageOrientationType.Portrait; | |
// Setting the scaling factor to 100 | |
// worksheet.PageSetup.Zoom = 100; | |
// OR Alternately you can use Fit to Page Options as under | |
// Setting the number of pages to which the length of the worksheet will be spanned | |
worksheet.PageSetup.FitToPagesTall = 1; | |
// Setting the number of pages to which the width of the worksheet will be spanned | |
worksheet.PageSetup.FitToPagesWide = 1; | |
// Setting the paper size to A4 | |
worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4; | |
// Setting the print quality of the worksheet to 1200 dpi | |
worksheet.PageSetup.PrintQuality = 1200; | |
//Setting the first page number of the worksheet pages | |
worksheet.PageSetup.FirstPageNumber = 2; | |
// Save the workbook | |
workbook.Save(dataDir + "PageSetup_out_.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook from source Excel file | |
Workbook workbook = new Workbook(dataDir + "SampleWorkbookWithComments.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
/* | |
* For print no comments use "PrintCommentsType.PrintNoComments" | |
* and for print the comments as displayed on sheet use "PrintCommentsType.PrintInPlace" | |
* For Print the comments at the end of sheet we use "PrintCommentsType.PrintSheetEnd" | |
*/ | |
worksheet.PageSetup.PrintComments = PrintCommentsType.PrintSheetEnd; | |
// Save workbook in pdf format | |
workbook.Save(dataDir + "PrintCommentWhileSavingToPdf_out.pdf"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from source Excel file | |
Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); | |
string printerName = ""; | |
while (string.IsNullOrEmpty(printerName) && string.IsNullOrWhiteSpace(printerName)) | |
{ | |
Console.WriteLine("Please Enter Your Printer Name:"); | |
printerName = Console.ReadLine(); | |
} | |
// Print the worbook specifying the range of pages. Here we are printing pages 2-3 | |
WorkbookRender wr = new WorkbookRender(workbook, new ImageOrPrintOptions()); | |
try | |
{ | |
wr.ToPrinter(printerName, 1, 2); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Print the worksheet specifying the range of pages. Here we are printing pages 2-3 | |
SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions()); | |
try | |
{ | |
sr.ToPrinter(printerName, 1, 2); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a workbook with Excel file. | |
Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); | |
string printerName = ""; | |
while (string.IsNullOrEmpty(printerName) && string.IsNullOrWhiteSpace(printerName)) | |
{ | |
Console.WriteLine("Please Enter Your Printer Name:"); | |
printerName = Console.ReadLine(); | |
} | |
// Define a worksheet. | |
Worksheet worksheet; | |
// Get the second sheet. | |
worksheet = workbook.Worksheets[1]; | |
// Apply different Image/Print options. | |
Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions(); | |
options.PrintingPage = PrintingPageType.Default; | |
SheetRender sr = new SheetRender(worksheet, options); | |
Console.WriteLine("Printing SampleBook.xlsx"); | |
// Print the sheet. | |
try | |
{ | |
sr.ToPrinter(printerName); | |
Console.WriteLine("Pinting finished."); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a workbook with an Excel file. | |
Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); | |
string printerName = ""; | |
while (string.IsNullOrEmpty(printerName) && string.IsNullOrWhiteSpace(printerName)) | |
{ | |
Console.WriteLine("Please Enter Your Printer Name:"); | |
printerName = Console.ReadLine(); | |
} | |
// Apply different Image/Print options. | |
Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions(); | |
options.ImageFormat = System.Drawing.Imaging.ImageFormat.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); | |
Console.WriteLine("Printing SampleBook.xlsx"); | |
// Print the workbook. | |
try | |
{ | |
wr.ToPrinter(printerName); | |
Console.WriteLine("Pinting finished."); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source file | |
Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Create empty Bitmap | |
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1100, 600); | |
// Create Graphics Context | |
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); | |
g.Clear(System.Drawing.Color.Blue); | |
// Set one page per sheet to true in image or print options | |
Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions(); | |
opts.OnePagePerSheet = true; | |
// Render worksheet to graphics context | |
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(worksheet, opts); | |
sr.ToImage(0, g, 0, 0); | |
// Save the graphics context image in Png format | |
bmp.Save(dataDir + "OutputImage_out.png", System.Drawing.Imaging.ImageFormat.Png); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load excel file into workbook object | |
Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); | |
// Save into Pdf with Minimum size | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
opts.OptimizationType = Aspose.Cells.Rendering.PdfOptimizationType.MinimumSize; | |
workbook.Save(dataDir + "OptimizedOutput_out.pdf", opts); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Defining string variables to store paths to font folders & font file | |
string fontFolder1 = dataDir + "Arial"; | |
string fontFolder2 = dataDir + "Calibri"; | |
string fontFile = dataDir + "arial.ttf"; | |
// Setting first font folder with SetFontFolder method | |
// Second parameter directs the API to search the subfolders for font files | |
FontConfigs.SetFontFolder(fontFolder1, true); | |
// Setting both font folders with SetFontFolders method | |
// Second parameter prohibits the API to search the subfolders for font files | |
FontConfigs.SetFontFolders(new string[] { fontFolder1, fontFolder2 }, false); | |
// Defining FolderFontSource | |
FolderFontSource sourceFolder = new FolderFontSource(fontFolder1, false); | |
// Defining FileFontSource | |
FileFontSource sourceFile = new FileFontSource(fontFile); | |
// Defining MemoryFontSource | |
MemoryFontSource sourceMemory = new MemoryFontSource(System.IO.File.ReadAllBytes(fontFile)); | |
// Setting font sources | |
FontConfigs.SetFontSources(new FontSourceBase[] { sourceFolder, sourceFile, sourceMemory }); |
This file contains hidden or 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 | |
// Substituting the Arial font with Times New Roman & Calibri | |
FontConfigs.SetFontSubstitutes("Arial", new string[] { "Times New Roman", "Calibri" }); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object and access first worksheet. | |
Workbook wb = new Workbook(); | |
Worksheet ws = wb.Worksheets[0]; | |
// Access cell B4 and add some text inside it. | |
Cell cell = ws.Cells["B4"]; | |
cell.PutValue("This text has some unknown or invalid font which does not exist."); | |
// Set the font of cell B4 which is unknown. | |
Style st = cell.GetStyle(); | |
st.Font.Name = "UnknownNotExist"; | |
st.Font.Size = 20; | |
cell.SetStyle(st); | |
// Now save the workbook in html format and set the default font to Courier New. | |
HtmlSaveOptions opts = new HtmlSaveOptions(); | |
opts.DefaultFontName = "Courier New"; | |
wb.Save(dataDir + "out_courier_new_out.htm", opts); | |
// Now save the workbook in html format once again but set the default font to Arial. | |
opts.DefaultFontName = "Arial"; | |
wb.Save(dataDir + "out_arial_out.htm", opts); | |
// Now save the workbook in html format once again but set the default font to Times New Roman. | |
opts.DefaultFontName = "Times New Roman"; | |
wb.Save(dataDir + "times_new_roman_out.htm", opts); |
This file contains hidden or 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 | |
// 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.ImageFormat = ImageFormat.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"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source Excel file | |
Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); | |
string printerName = ""; | |
while (string.IsNullOrEmpty(printerName) && string.IsNullOrWhiteSpace(printerName)) | |
{ | |
Console.WriteLine("Please Enter Your Printer Name:"); | |
printerName = Console.ReadLine(); | |
} | |
string jobName = "Job Name while Printing with Aspose.Cells"; | |
// Print workbook using WorkbookRender | |
WorkbookRender wr = new WorkbookRender(workbook, new ImageOrPrintOptions()); | |
try | |
{ | |
wr.ToPrinter(printerName, jobName); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Print worksheet using SheetRender | |
SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions()); | |
try | |
{ | |
sr.ToPrinter(printerName, jobName); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source file | |
Workbook workbook = new Workbook(dataDir + "SampleBook.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.ImageFormat = System.Drawing.Imaging.ImageFormat.Png; | |
opts.SetDesiredSize(400, 400); | |
// Render sheet into image | |
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(worksheet, opts); | |
sr.ToImage(0, dataDir + "ImageWithDesiredSize_out.png"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook object with template | |
Workbook book = new Workbook(dataDir + "SampleBook.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.ImageFormat = System.Drawing.Imaging.ImageFormat.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 | |
sr.ToImage(0, dataDir + @"SheetImage_out.tiff"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Initialize a new Workbook | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir+ "input.xlsx"); | |
// Implement one page per worksheet option | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.OnePagePerSheet = true; | |
// Save the PDF file | |
workbook.Save(dataDir+ "OutputFile.out.pdf", pdfSaveOptions); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load your source excel file containing Unicode Supplementary characters | |
Workbook wb = new Workbook(dataDir + "unicode-supplementary-characters.xlsx"); | |
// Save the workbook | |
wb.Save(dataDir + "RenderUnicodeInOutput_out.pdf"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Initialize a new Workbook | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir+ "input.xlsx"); | |
// Instantiate the PdfSaveOptions | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
// Set Image Resample properties | |
pdfSaveOptions.SetImageResample(300, 70); | |
// Save the PDF file | |
workbook.Save(dataDir+ "OutputFile_out_pdf", pdfSaveOptions); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Get the Excel file path | |
string filePath = dataDir + "input.xlsx"; | |
// Instantiage a new workbook and open the Excel, File from its location | |
Workbook workbook = new Workbook(filePath); | |
// Get the count of the worksheets in the workbook | |
int sheetCount = workbook.Worksheets.Count; | |
// Make all sheets invisible except first worksheet | |
for (int i = 1; i < workbook.Worksheets.Count; i++) | |
{ | |
workbook.Worksheets[i].IsVisible = false; | |
} | |
// Take Pdfs of each sheet | |
for (int j = 0; j < workbook.Worksheets.Count; j++) | |
{ | |
Worksheet ws = workbook.Worksheets[j]; | |
workbook.Save(dataDir + "worksheet-" + ws.Name + ".out.pdf"); | |
if (j < workbook.Worksheets.Count - 1) | |
{ | |
workbook.Worksheets[j + 1].IsVisible = true; | |
workbook.Worksheets[j].IsVisible = false; | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filePath = dataDir+ "input.xlsx"; | |
Workbook workbook = new Workbook(filePath); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Specify the range where you want to search | |
// Here the range is E3:H6 | |
CellArea area = CellArea.CreateCellArea("E9", "H15"); | |
// Specify Find options | |
FindOptions opts = new FindOptions(); | |
opts.LookInType = LookInType.Values; | |
opts.LookAtType = LookAtType.EntireContent; | |
opts.SetRange(area); | |
Cell cell = null; | |
do | |
{ | |
// Search the cell with value search within range | |
cell = worksheet.Cells.Find("search", cell, opts); | |
// If no such cell found, then break the loop | |
if (cell == null) | |
break; | |
// Replace the cell with value replace | |
cell.PutValue("replace"); | |
} while (true); | |
// Save the workbook | |
workbook.Save(dataDir+ "output.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir+ "input.xlsx"); | |
// Instantiate PDFSaveOptions to manage security attributes | |
PdfSaveOptions saveOption = new PdfSaveOptions(); | |
saveOption.SecurityOptions = new Aspose.Cells.Rendering.PdfSecurity.PdfSecurityOptions(); | |
// Set the user password | |
saveOption.SecurityOptions.UserPassword = "user"; | |
// Set the owner password | |
saveOption.SecurityOptions.OwnerPassword = "owner"; | |
// Disable extracting content permission | |
saveOption.SecurityOptions.ExtractContentPermission = false; | |
// Disable print permission | |
saveOption.SecurityOptions.PrintPermission = false; | |
// Save the PDF document with encrypted settings | |
workbook.Save(dataDir+ "securepdf_test.out.pdf", saveOption); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// 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 = dataDir+ "aspose-logo.jpg"; | |
// Get the picture into the streams. | |
FileStream fs = File.OpenRead(ImageUrl); | |
// 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(); | |
// Set the background image for the sheet. | |
sheet.BackgroundImage = imageData; | |
// Save the Excel file | |
workbook.Save(dataDir + "BackImageSheet.out.xlsx"); | |
// Save the HTML file | |
workbook.Save(dataDir + "BackImageSheet1.out.html", SaveFormat.Html); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook | |
// Load an Excel file | |
Workbook wb = new Workbook(dataDir + "Book1.xlsx"); | |
// Instantiate SheetRender object based on the first worksheet | |
// Set the ImageOrPrintOptions with desired pixel format (24 bits per pixel) and image format type | |
SheetRender sr = new SheetRender(wb.Worksheets[0], new ImageOrPrintOptions { PixelFormat = PixelFormat.Format24bppRgb, ImageFormat = ImageFormat.Tiff }); | |
// Save the image (first page of the sheet) with the specified options | |
sr.ToImage(0, dataDir + "outImage1.out.tiff"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook wb = new Workbook(); | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Create a textbox with some text | |
TextBox tb = ws.Shapes.AddTextBox(0, 0, 0, 0, 100, 700); | |
tb.Text = "Aspose File Format APIs"; | |
tb.Font.Size = 44; | |
// Sets preset WordArt style to the text of the shape. | |
FontSetting fntSetting = tb.GetCharacters()[0] as FontSetting; | |
fntSetting.SetWordArtStyle(PresetWordArtStyle.WordArtStyle3); | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook | |
Workbook wb = new Workbook(); | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Add text box inside the sheet | |
ws.Shapes.AddTextBox(2, 0, 2, 0, 100, 200); | |
// Access first shape which is a text box and set is text | |
Shape shape = ws.Shapes[0]; | |
shape.Text = "Sign up for your free phone number.\nCall and text online for free."; | |
// Acccess the first paragraph | |
TextParagraph p = shape.TextBody.TextParagraphs[1]; | |
// Set the line space | |
p.LineSpaceSizeType = LineSpaceSizeType.Points; | |
p.LineSpace = 20; | |
// Set the space after | |
p.SpaceAfterSizeType = LineSpaceSizeType.Points; | |
p.SpaceAfter = 10; | |
// Set the space before | |
p.SpaceBeforeSizeType = LineSpaceSizeType.Points; | |
p.SpaceBefore = 10; | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "output_out.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiating a Workbook object. | |
Workbook workbook = new Workbook(); | |
// Setting ScaleCrop and LinksUpToDate BuiltIn Document Properties. | |
workbook.BuiltInDocumentProperties.ScaleCrop = true; | |
workbook.BuiltInDocumentProperties.LinksUpToDate = true; | |
// Saving the Excel file. | |
workbook.Save(dataDir + "output.xls", SaveFormat.Auto); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a Workbook object. | |
// Open an excel file. | |
Workbook workbook = new Workbook(dataDir+ "Book1.xlsx"); | |
// Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider). | |
workbook.SetEncryptionOptions(EncryptionType.StrongCryptographicProvider, 128); | |
// Password protect the file. | |
workbook.Settings.Password = "1234"; | |
// Save the Excel file. | |
workbook.Save(dataDir+ "encryptedBook1.out.xls"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// 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 the font color and size of the textbox | |
tb.Font.Color = Color.Red; | |
tb.Font.Size = 16; | |
// Save the output file | |
wb.Save(dataDir + "SettingTextEffectsShadowOfShapeOrTextbox_out.xlsx", SaveFormat.Xlsx); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir+ "Book1.xlsx"); | |
// Get the first worksheet in the book | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Set the tab color | |
worksheet.TabColor = Color.Red; | |
// Save the Excel file | |
workbook.Save(dataDir+ "worksheettabcolor.out.xls"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load your source excel file | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Access first shape | |
Shape sh = ws.Shapes[0]; | |
// Set the shadow effect of the shape, Set its Angle, Blur, Distance and Transparency properties | |
ShadowEffect se = sh.ShadowEffect; | |
se.Angle = 150; | |
se.Blur = 4; | |
se.Distance = 45; | |
se.Transparency = 0.3; | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load excel file containing a shape | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Access first shape | |
Shape sh = ws.Shapes[0]; | |
// Apply different three dimensional settings | |
ThreeDFormat n3df = sh.ThreeDFormat; | |
n3df.ContourWidth = 17; | |
n3df.ExtrusionHeight = 32; | |
// Save the output excel file in xlsx format | |
wb.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filePath = dataDir+ "source.xlsx"; | |
// Load the source workbook | |
Workbook workbook = new Workbook(filePath); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Show formulas of the worksheet | |
worksheet.ShowFormulas = true; | |
// Save the workbook | |
workbook.Save(dataDir+ ".out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir+ "Book_SourceData.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Get the cells collection in the sheet | |
Cells cells = worksheet.Cells; | |
// Obtain the DataSorter object in the workbook | |
DataSorter sorter = workbook.DataSorter; | |
// Set the first order | |
sorter.Order1 = Aspose.Cells.SortOrder.Ascending; | |
// Define the first key. | |
sorter.Key1 = 0; | |
// Set the second order | |
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 = 1; | |
// Specify the start column index. | |
ca.StartColumn = 0; | |
// Specify the last row index. | |
ca.EndRow = 9; | |
// Specify the last column index. | |
ca.EndColumn = 2; | |
// Sort data in the specified data range (A2:C10) | |
sorter.Sort(workbook.Worksheets[0].Cells, ca); | |
// Saving the excel file in the default (that is Excel 2003) format | |
workbook.Save(dataDir+ "outBook_SortedData.out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from source Excel file | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Get the Cells collection in the first worksheet | |
Cells cells = worksheet.Cells; | |
// Create a cellarea i.e.., A2:B11 | |
CellArea ca = CellArea.CreateCellArea("A2", "B11"); | |
// Apply subtotal, the consolidation function is Sum and it will applied to Second column (B) in the list | |
cells.Subtotal(ca, 0, ConsolidationFunction.Sum, new int[] { 1 }, true, false, true); | |
// Set the direction of outline summary | |
worksheet.Outline.SummaryRowBelow = true; | |
// Save the excel file | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 an instance of Workbook class | |
Workbook book = new Workbook(); | |
// Setting this property to true will make Aspose.Cells to throw exception | |
// when invalid custom number format is assigned to Style.Custom property | |
book.Settings.CheckCustomNumberFormat = true; | |
// Access first worksheet | |
Worksheet sheet = book.Worksheets[0]; | |
// Access cell A1 and put some number to it | |
Cell cell = sheet.Cells["A1"]; | |
cell.PutValue(2347); | |
// Access cell's style and set its Style.Custom property | |
Style style = cell.GetStyle(); | |
// This line will throw exception if Workbook.Settings.CheckCustomNumberFormat is set to true | |
style.Custom = "ggg @ fff"; //Invalid custom number format |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate workbook object with an Excel file | |
Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); | |
for (int i = 0; i < workbook.Worksheets.Count; i++) | |
{ | |
workbook.Worksheets[i].Cells.ConvertStringToNumericValue(); | |
} | |
workbook.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(); | |
// Specify custom separators | |
workbook.Settings.NumberDecimalSeparator = '.'; | |
workbook.Settings.NumberGroupSeparator = ' '; | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Set cell value | |
Cell cell = worksheet.Cells["A1"]; | |
cell.PutValue(123456.789); | |
// Set custom cell style | |
Style style = cell.GetStyle(); | |
style.Custom = "#,##0.000;[Red]#,##0.000"; | |
cell.SetStyle(style); | |
worksheet.AutoFitColumns(); | |
// Save workbook as pdf | |
workbook.Save(dataDir + "CustomSeparator_out.pdf"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cell A1 | |
Cell cell = worksheet.Cells["A1"]; | |
// Set the HTML string | |
cell.HtmlString = "<font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'>Text 1 </font><font style='font-family:Wingdings;font-size:8.0pt;color:#009DD9;mso-font-charset:2;'>l</font><font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'> Text 2 </font><font style='font-family:Wingdings;font-size:8.0pt;color:#009DD9;mso-font-charset:2;'>l</font><font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'> Text 3 </font><font style='font-family:Wingdings;font-size:8.0pt;color:#009DD9;mso-font-charset:2;'>l</font><font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'> Text 4 </font>"; | |
// Auto fit the Columns | |
worksheet.AutoFitColumns(); | |
// Save the workbook | |
workbook.Save(dataDir + "BulletsInCells_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Extract theme name applied to this workbook | |
Console.WriteLine(workbook.Theme); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cell A1 | |
Cell cell = worksheet.Cells["A1"]; | |
// Get the style object | |
Style style = cell.GetStyle(); | |
if (style.ForegroundThemeColor != null) | |
{ | |
// Extract theme color applied to this cell if theme has foregroundtheme color defined | |
Console.WriteLine(style.ForegroundThemeColor.ColorType); | |
} | |
else | |
{ | |
Console.WriteLine("Theme has not foreground color defined."); | |
} | |
// Extract theme color applied to the bottom border of the cell if theme has border color defined | |
Border bot = style.Borders[BorderType.BottomBorder]; | |
if (bot.ThemeColor != null) | |
{ | |
Console.WriteLine(bot.ThemeColor.ColorType); | |
} | |
else | |
{ | |
Console.WriteLine("Theme has not Border color defined."); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "SourceFile.xlsx"); | |
workbook.Save(dataDir + "CustomDateFormat_out.pdf"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cells | |
Cell cell1 = worksheet.Cells["A1"]; | |
Cell cell2 = worksheet.Cells["B1"]; | |
// Set the styles of both cells to Times New Roman | |
Style styleObject = workbook.CreateStyle(); | |
styleObject.Font.Color = System.Drawing.Color.Red; | |
styleObject.Font.Name = "Times New Roman"; | |
cell1.SetStyle(styleObject); | |
cell2.SetStyle(styleObject); | |
// Put the values inside the cell | |
cell1.PutValue("Hello World!"); | |
cell2.PutValue("Hello World!!"); | |
// Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity | |
workbook.Save(dataDir + "SampleOutput_out.xlsx"); |
This file contains hidden or 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 | |
// Intialize an object of the Workbook class to load template file | |
Workbook sourceWb = new Workbook("SampleTextboxExcel2016.xlsx"); | |
// Access the target textbox whose text is to be aligned | |
var sourceTextBox = sourceWb.Worksheets[0].Shapes[0]; | |
// Create and object of the target workbook | |
var destWb = new Workbook(); | |
// Access first worksheet from the collection | |
var _sheet = destWb.Worksheets[0]; | |
//Create new textbox | |
TextBox _textBox = (TextBox)_sheet.Shapes.AddShape( MsoDrawingType.TextBox,1, 0, 1, 0, 200, 200); | |
// Alternatively text box can be added using following line as well | |
// TextBox _textBox = _sheet.Shapes.AddTextBox(1, 0, 1, 0, 200, 200); | |
// Use Html string from a template file textbox | |
_textBox.HtmlText = sourceTextBox.HtmlText; | |
// Save the workbook on disc | |
destWb.Save("Output.xlsx"); |
This file contains hidden or 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 | |
class GlobalizationSettingsImp : GlobalizationSettings | |
{ | |
// This function will return the sub total name | |
public override String GetTotalName(ConsolidationFunction functionType) | |
{ | |
return "Chinese Total - 可能的用法"; | |
} | |
// This function will return the grand total name | |
public override String GetGrandTotalName(ConsolidationFunction functionType) | |
{ | |
return "Chinese Grand Total - 可能的用法"; | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load your source workbook | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Set the glorbalization setting to change subtotal and grand total names | |
GlobalizationSettings gsi = new GlobalizationSettingsImp(); | |
wb.Settings.GlobalizationSettings = gsi; | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Apply subtotal on A1:B10 | |
CellArea ca = CellArea.CreateCellArea("A1", "B10"); | |
ws.Cells.Subtotal(ca, 0, ConsolidationFunction.Sum, new int[] { 2, 3, 4 }); | |
// Set the width of the first column | |
ws.Cells.SetColumnWidth(0, 40); | |
// Save the output excel file | |
wb.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook | |
Workbook wb = new Workbook(dataDir + "SourceFile.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) | |
{ | |
// Access Shape ActiveX Control | |
ActiveXControl c = shape.ActiveXControl; | |
// Check if ActiveX Control is ComboBox Control | |
if (c.Type == ControlType.ComboBox) | |
{ | |
// Type cast ActiveXControl into ComboBoxActiveXControl and change its value | |
ComboBoxActiveXControl comboBoxActiveX = (ComboBoxActiveXControl)c; | |
comboBoxActiveX.Value = "This is combo box control with updated value."; | |
} | |
} | |
// Save the workbook | |
wb.Save(dataDir + "OutputFile_out.xlsx"); |
This file contains hidden or 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 workbook | |
Workbook wb = new Workbook(); | |
// Add second sheet with name Sheet2 | |
wb.Worksheets.Add("Sheet2"); | |
// Access first sheet and add some integer value in cell C1 | |
// Also add some value in any cell to increase the number of blank rows and columns | |
Worksheet sht1 = wb.Worksheets[0]; | |
sht1.Cells["C1"].PutValue(4); | |
sht1.Cells["K30"].PutValue(4); | |
// Access second sheet and add formula in cell E3 which refers to cell C1 in first sheet | |
Worksheet sht2 = wb.Worksheets[1]; | |
sht2.Cells["E3"].Formula = "'Sheet1'!C1"; | |
// Calculate formulas of workbook | |
wb.CalculateFormula(); | |
// Print the formula and value of cell E3 in second sheet before deleting blank columns and rows in Sheet1. | |
Console.WriteLine("Cell E3 before deleting blank columns and rows in Sheet1."); | |
Console.WriteLine("--------------------------------------------------------"); | |
Console.WriteLine("Cell Formula: " + sht2.Cells["E3"].Formula); | |
Console.WriteLine("Cell Value: " + sht2.Cells["E3"].StringValue); | |
// If you comment DeleteOptions.UpdateReference property below, then the formula in cell E3 in second sheet will not be updated | |
DeleteOptions opts = new DeleteOptions(); | |
opts.UpdateReference = true; | |
// Delete all blank rows and columns with delete options | |
sht1.Cells.DeleteBlankColumns(opts); | |
sht1.Cells.DeleteBlankRows(opts); | |
// Calculate formulas of workbook | |
wb.CalculateFormula(); | |
// Print the formula and value of cell E3 in second sheet after deleting blank columns and rows in Sheet1. | |
Console.WriteLine(""); | |
Console.WriteLine(""); | |
Console.WriteLine("Cell E3 after deleting blank columns and rows in Sheet1."); | |
Console.WriteLine("--------------------------------------------------------"); | |
Console.WriteLine("Cell Formula: " + sht2.Cells["E3"].Formula); | |
Console.WriteLine("Cell Value: " + sht2.Cells["E3"].StringValue); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string inputPath = dataDir + "Sample.xlsx"; | |
string outputPath = dataDir + "Output.out.xlsx"; | |
Workbook workbook = new Workbook(inputPath); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
Cell cell = worksheet.Cells["A1"]; | |
Console.WriteLine("Before updating the font settings...."); | |
FontSetting[] fnts = cell.GetCharacters(); | |
for (int i = 0; i < fnts.Length; i++) | |
{ | |
Console.WriteLine(fnts[i].Font.Name); | |
} | |
// Modify the first FontSetting Font Name | |
fnts[0].Font.Name = "Arial"; | |
// And update it using SetCharacters() method | |
cell.SetCharacters(fnts); | |
Console.WriteLine(); | |
Console.WriteLine("After updating the font settings...."); | |
fnts = cell.GetCharacters(); | |
for (int i = 0; i < fnts.Length; i++) | |
{ | |
Console.WriteLine(fnts[i].Font.Name); | |
} | |
// Save workbook | |
workbook.Save(outputPath); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate the Workbook | |
// Load an Excel file | |
Workbook workbook = new Workbook(dataDir+ "sample.xlsx"); | |
// Create HtmlSaveOptions object | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
// Set the Presenation preference option | |
options.PresentationPreference = true; | |
// Save the Excel file to HTML with specified option | |
workbook.Save(dataDir+ "outPresentationlayout1.out.html", options); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string output1Path = dataDir + "Output.xlsx"; | |
string output2Path = dataDir + "Output.out.ods"; | |
Workbook workbook = new Workbook(); | |
Style style = workbook.CreateBuiltinStyle(BuiltinStyleType.Title); | |
Cell cell = workbook.Worksheets[0].Cells["A1"]; | |
cell.PutValue("Aspose"); | |
cell.SetStyle(style); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
worksheet.AutoFitColumn(0); | |
worksheet.AutoFitRow(0); | |
workbook.Save(output1Path); | |
Console.WriteLine("File saved {0}", output1Path); | |
workbook.Save(output2Path); | |
Console.WriteLine("File saved {0}", output1Path); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a Style object using CellsFactory class | |
CellsFactory cf = new CellsFactory(); | |
Style st = cf.CreateStyle(); | |
// Set the Style fill color to Yellow | |
st.Pattern = BackgroundType.Solid; | |
st.ForegroundColor = Color.Yellow; | |
// Create a workbook and set its default style using the created Style object | |
Workbook wb = new Workbook(); | |
wb.DefaultStyle = st; | |
// Save the workbook | |
wb.Save(dataDir + "output_out.xlsx"); |
This file contains hidden or 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 | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// The sample XML that will be injected to Workbook | |
string booksXML = @"<catalog> | |
<book> | |
<title>Complete C#</title> | |
<price>44</price> | |
</book> | |
<book> | |
<title>Complete Java</title> | |
<price>76</price> | |
</book> | |
<book> | |
<title>Complete SharePoint</title> | |
<price>55</price> | |
</book> | |
<book> | |
<title>Complete PHP</title> | |
<price>63</price> | |
</book> | |
<book> | |
<title>Complete VB.NET</title> | |
<price>72</price> | |
</book> | |
</catalog>"; | |
// Create an instance of Workbook class | |
Workbook workbook = new Workbook(); | |
// Add Custom XML Part to ContentTypePropertyCollection | |
workbook.ContentTypeProperties.Add("BookStore", booksXML); | |
// Save the resultant spreadsheet | |
workbook.Save(dataDir + "output.xlsx"); |
This file contains hidden or 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 | |
public class UsingImageMarkersWhileGroupingDataInSmartMarkers | |
{ | |
class Person | |
{ | |
// Create Name, City and Photo properties | |
private string m_Name; | |
private string m_City; | |
private byte[] m_Photo; | |
public Person(string name, string city, byte[] photo) | |
{ | |
m_Name = name; | |
m_City = city; | |
m_Photo = photo; | |
} | |
public string Name | |
{ | |
get { return m_Name; } | |
set { m_Name = value; } | |
} | |
public string City | |
{ | |
get { return m_City; } | |
set { m_City = value; } | |
} | |
public byte[] Photo | |
{ | |
get { return m_Photo; } | |
set { m_Photo = value; } | |
} | |
} | |
public static void Run() | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Get the images | |
byte[] photo1 = File.ReadAllBytes(dataDir + "moon.png"); | |
byte[] photo2 = File.ReadAllBytes(dataDir + "moon2.png"); | |
// Create a new workbook and access its worksheet | |
Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Set the standard row height to 35 | |
worksheet.Cells.StandardHeight = 35; | |
// Set column widhts of D, E and F | |
worksheet.Cells.SetColumnWidth(3, 20); | |
worksheet.Cells.SetColumnWidth(4, 20); | |
worksheet.Cells.SetColumnWidth(5, 40); | |
// Add the headings in columns D, E and F | |
worksheet.Cells["D1"].PutValue("Name"); | |
Style st = worksheet.Cells["D1"].GetStyle(); | |
st.Font.IsBold = true; | |
worksheet.Cells["D1"].SetStyle(st); | |
worksheet.Cells["E1"].PutValue("City"); | |
worksheet.Cells["E1"].SetStyle(st); | |
worksheet.Cells["F1"].PutValue("Photo"); | |
worksheet.Cells["F1"].SetStyle(st); | |
// Add smart marker tags in columns D, E, F | |
worksheet.Cells["D2"].PutValue("&=Person.Name(group:normal,skip:1)"); | |
worksheet.Cells["E2"].PutValue("&=Person.City"); | |
worksheet.Cells["F2"].PutValue("&=Person.Photo(Picture:FitToCell)"); | |
// Create Persons objects with photos | |
List<Person> persons = new List<Person>(); | |
persons.Add(new Person("George", "New York", photo1)); | |
persons.Add(new Person("George", "New York", photo2)); | |
persons.Add(new Person("George", "New York", photo1)); | |
persons.Add(new Person("George", "New York", photo2)); | |
persons.Add(new Person("Johnson", "London", photo2)); | |
persons.Add(new Person("Johnson", "London", photo1)); | |
persons.Add(new Person("Johnson", "London", photo2)); | |
persons.Add(new Person("Simon", "Paris", photo1)); | |
persons.Add(new Person("Simon", "Paris", photo2)); | |
persons.Add(new Person("Simon", "Paris", photo1)); | |
persons.Add(new Person("Henry", "Sydney", photo2)); | |
persons.Add(new Person("Henry", "Sydney", photo1)); | |
persons.Add(new Person("Henry", "Sydney", photo2)); | |
// Create a workbook designer | |
WorkbookDesigner designer = new WorkbookDesigner(workbook); | |
// Set the data source and process smart marker tags | |
designer.SetDataSource("Person", persons); | |
designer.Process(); | |
// Save the workbook | |
workbook.Save(dataDir + "UsingImageMarkersWhileGroupingDataInSmartMarkers.xlsx", SaveFormat.Xlsx); | |
} | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open a template excel file | |
Workbook book = new Workbook(dataDir + "Testbook1.xlsx"); | |
// Get the first worksheet. | |
Worksheet sheet = book.Worksheets[0]; | |
// Get the second worksheet. | |
// Worksheet sheet = book.Worksheets[1]; | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Specify the image format | |
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; | |
// If you want entire sheet as a singe image | |
imgOptions.OnePagePerSheet = true; | |
// 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(dataDir + "SheetImage_out.jpg"); |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(dataDir + "Testbook1.xlsx", new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx)); | |
foreach (Worksheet ws in wb.Worksheets) | |
{ | |
SheetRender sr = new SheetRender(ws, new ImageOrPrintOptions() { OnePagePerSheet = true, ImageFormat = ImageFormat.Jpeg }); | |
sr.ToImage(0, dataDir + "Img_" + ws.Index + "_out.jpg"); | |
} |
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
//Open template | |
Workbook book = new Workbook(dataDir + "Testbook1.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.ImageFormat = System.Drawing.Imaging.ImageFormat.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 | |
sr.ToImage(0, dataDir + @"SheetImage_out.tiff"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment