إضافة كائن مجهول أو مخصص إلى العلامات الذكية
Contents
[
Hide
]
يشرح هذا كيفية استيراد كائنات مجهولة أو مخصصة إلى العلامات الذكية.
أحيانًا، تحتاج إلى تضمين كائنات مخصصة كمصدر بيانات للعلامات الذكية. تجعل Aspose.Cells من الممكن استخدام الكائنات المخصصة كمصدر بيانات.
يرجى رؤية الكود العيني التالي الذي يوضح كيفية إضافة كائنات مخصصة كمصدر بيانات للعلامات الذكية.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
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; | |
} | |
} |