Akıllı işaretçiler ile verileri akıllıca içe aktarma ve yerleştirme
Giriş
akıllı işaretçilerAspose.Cells’in bir Microsoft Excel tasarımcı elektronik tablosuna hangi bilgilerin yerleştirileceğini bilmesini sağlamak için kullanılır. Akıllı işaretçiler, yalnızca belirli bilgileri ve biçimlendirmeyi içeren şablonlar oluşturmanıza olanak tanır.
Tasarımcı Elektronik Tablosu ve Akıllı İşaretleyiciler
Tasarımcı elektronik tabloları, görsel biçimlendirme, formüller ve akıllı işaretçiler içeren standart Excel dosyalarıdır. Bir projeden gelen bilgiler ve ilgili ilgili kişiler için bilgiler gibi bir veya daha fazla veri kaynağına başvuran akıllı işaretçiler içerebilirler. Akıllı işaretçiler, bilgiyi istediğiniz hücrelere yazılır.
Tüm akıllı işaretçiler &= ile başlar. Veri işaretçisine örnek olarak &=Party.FullName verilebilir. Veri işaretçisi birden fazla öğeyle, örneğin tam bir satırla sonuçlanırsa, sonraki satırlar yeni bilgilere yer açmak için otomatik olarak aşağı taşınır. Böylece ara toplamlar ve toplamlar, eklenen verilere dayalı hesaplamalar yapmak için veri işaretçisinden hemen sonra satıra yerleştirilebilir. Girilen satırlarda hesaplamalar yapmak için şunu kullanın:dinamik formüller.
Akıllı işaretçiler şunlardan oluşur:veri kaynağı vealan adıçoğu bilgi için parçalar. Değişkenler ve değişken dizileri ile özel bilgiler de iletilebilir. Değişkenler her zaman yalnızca bir hücreyi doldururken, değişken dizileri birkaç hücreyi doldurabilir. Hücre başına yalnızca bir veri işaretçisi kullanın. Kullanılmayan akıllı işaretçiler kaldırılır.
Akıllı işaretleyici ayrıca parametreler içerebilir. Parametreler, bilgilerin düzenlenme şeklini değiştirmenize olanak tanır. Akıllı işaretçinin sonuna parantez içinde virgülle ayrılmış bir liste olarak eklenirler.
Akıllı İşaretleyici Seçenekleri
&=DataSource.FieldName &=[Veri Kaynağı].[Alan Adı]&=$VariableName &=$Değişken Dizisi &==Dinamik Formül &=&=Tekrar DinamikFormül
parametreler
Aşağıdaki parametrelere izin verilir:
- ekleme - Verileri sığdırmak için fazladan satır eklemeyin.
- atla:n - Her veri satırı için n sayıda satır atlayın.
- artan:n veyaazalan:n - Verileri akıllı işaretleyicilerde sıralayın. n 1 ise sütun sıralayıcının ilk anahtarıdır. Veri kaynağı işlendikten sonra veriler sıralanır. Örneğin: &=Tablo1.Alan3(artan:1).
- yatay - Verileri yukarıdan aşağıya yazmak yerine soldan sağa yazın.
- sayısal - Mümkünse metni sayıya dönüştürün.
- vardiya - Verileri sığdırmak için fazladan satırlar veya sütunlar oluşturarak aşağı veya sağa kaydırın. Shift parametresi, Microsoft Excel’dekiyle aynı şekilde çalışır. Örneğin, Microsoft Excel’de, bir hücre aralığı seçtiğinizde, sağ tıklayın ve seçinSokmak ve belirtinhücreleri aşağı kaydır, Hücreleri sağa kaydır ve diğer seçenekler. kısacasıvardiya parametresi, dikey/normal (yukarıdan aşağıya) veya yatay (soldan sağa) akıllı işaretçiler için aynı işlevi yerine getirir.
- kopya stili - Temel hücrenin stilini o sütundaki tüm hücrelere kopyalayın.
Değişken satırlara veri eklemek için noadd ve jump parametreleri birleştirilebilir. Şablon aşağıdan yukarıya doğru işlendiği için, alternatif satırın önüne fazladan satır eklenmesini önlemek için ilk satıra noadd eklemelisiniz.
Birden fazla parametreniz varsa, bunları virgülle ayırın ancak boşluk kullanmayın: parameterA,parameterB,parameterC
Aşağıdaki ekran görüntüleri, her bir satıra nasıl veri ekleneceğini gösterir.
Şablon Dosyası | Çıktı dosyası |
---|---|
![]() |
![]() |
Dinamik Formüller
Dinamik formüller, formül dışa aktarma işlemi sırasında eklenecek satırlara başvursa bile Excel formüllerini hücrelere eklemenize olanak tanır. Dinamik formüller, eklenen her satır için yinelenebilir veya yalnızca veri işaretçisinin yerleştirildiği hücreyi kullanabilir.
Dinamik formüller aşağıdaki ek seçeneklere izin verir:
- r - Geçerli satır numarası.
- 2, -1 - Geçerli satır numarasına kaydırma.
Örneğin:
&=&=B{-1}/C{-1}~(skip:1)
Dinamik formül işaretçisinde “-1”, bölme işlemi için ayarlanacak sırasıyla B ve C sütunlarında geçerli satıra göre kaymayı ifade eder, atlama parametresi bir satırdır. Ayrıca, aşağıdaki karakteri belirtmeliyiz:
"~"
dinamik formüllerde daha fazla parametre uygulamak için bir ayırıcı karakter olarak.
Aşağıdaki ekran görüntüleri, yinelenen bir dinamik formülü ve sonuçta ortaya çıkan Excel çalışma sayfasını göstermektedir.
Şablon Dosyası | Çıktı dosyası |
---|---|
![]() |
![]() |
Cell “C1” formülü içerir**= A1*B1** , “C2” hücresi şunları içerir:**= A2*B2** ve “C3” hücresi şunları içerir:**= A3*B3**. |
Akıllı işaretleyicileri işlemek çok kolaydır. Aşağıda, nasıl yapıldığını gösteren, biri C#‘de ve diğeri VB’de olmak üzere iki kod parçacığı bulunmaktadır.
// 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); | |
//set the file path of designer spreadsheet containing smart markers | |
string designerFile = "templateDynamicFormulas.xlsx"; | |
//create your data set | |
DataSet dataset = new DataSet(); | |
DataTable dt = new DataTable("Answer"); | |
dataset.Tables.Add(dt); | |
DataColumn price = new DataColumn("Price", typeof(double)); | |
DataColumn amount = new DataColumn("Amount", typeof(int)); | |
dt.Columns.Add(price); | |
dt.Columns.Add(amount); | |
dt.Rows.Add(100.00, 2); | |
dt.Rows.Add(75.25, 3); | |
dt.Rows.Add(25.00, 5); | |
if (designerFile != null) | |
{ | |
// 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(); | |
} |
Değişken Dizileri Kullanma
Aşağıdaki örnek kod, Akıllı İşaretleyicilerde değişken dizilerin nasıl kullanılacağını gösterir. Çalışma kitabının ilk çalışma sayfasının A1 hücresine dinamik olarak işaretleyici için belirlediğimiz değer dizisini içeren bir değişken dizi işaretçisi yerleştiririz, işaretçileri hücrelere işaretçiye karşı dolduracak şekilde işleriz. Son olarak Excel dosyasını kaydediyoruz.
// 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 designer. | |
WorkbookDesigner report = new WorkbookDesigner(); | |
// Get the first worksheet of the workbook. | |
Worksheet w = report.Workbook.Worksheets[0]; | |
// Set the Variable Array marker to a cell. | |
// You may also place this Smart Marker into a template file manually in Ms Excel and then open this file via Workbook. | |
w.Cells["A1"].PutValue("&=$VariableArray"); | |
// Set the DataSource for the marker(s). | |
report.SetDataSource("VariableArray", new string[] { "English", "Arabic", "Hindi", "Urdu", "French" }); | |
// Process the markers. | |
report.Process(false); | |
// Save the Excel file. | |
report.Workbook.Save(dataDir + "output.xlsx"); |
Verileri Gruplandırma
Bazı Excel raporlarında, okumayı ve analiz etmeyi kolaylaştırmak için verileri gruplara ayırmanız gerekebilir. Verileri gruplara ayırmanın birincil amaçlarından biri, her bir kayıt grubu üzerinde hesaplamalar yapmaktır (özet işlemleri gerçekleştirmek).
Aspose.Cells akıllı işaretleyiciler, verileri alanlara göre gruplandırmanıza ve veri kümeleri veya veri grupları arasına özet satırları yerleştirmenize olanak tanır. Örneğin, verileri Customers.CustomerID’ye göre gruplandırıyorsanız, grup her değiştiğinde bir özet kayıt ekleyebilirsiniz.
parametreler
Aşağıda, verileri gruplandırmak için kullanılan akıllı işaretçi parametrelerinden bazıları verilmiştir.
grup:normal/birleştir/tekrarla
Aralarından seçim yapabileceğiniz üç tür grubu destekliyoruz.
- normal - Alan(lar)a göre grup değeri, sütundaki karşılık gelen kayıtlar için tekrarlanmaz; bunun yerine veri grubu başına bir kez yazdırılırlar.
- birleştirmek - Her grup kümesi için alan(lar)a göre gruptaki hücreleri birleştirme dışında normal parametreyle aynı davranış.
- tekrar et - Alan(lar)a göre grup değeri ilgili kayıtlar için tekrarlanır.
Örneğin: &=Customers.CustomerID(group:merge)
atlamak
Her gruptan sonra belirtilen sayıda satırı atlar.
Örneğin, &=Employees.EmployeeID(group:normal,skip:1)
ara toplamN
Alana göre grupla ilgili belirtilen alan verileri için bir özet işlemi gerçekleştirir. N, bir veri listesinde ara toplamları hesaplarken kullanılan işlevi belirten 1 ile 11 arasındaki sayıları temsil eder. (1=ORTALAMA, 2=SAYI, 3=SAYI, 4=MAKS, 5=MIN,…9=TOPLA vb.) Daha fazla ayrıntı için Microsoft Excel’in yardımındaki Ara toplam referansına bakın.
Biçim aslında şöyle belirtir: alt toplamN:Ref burada Ref sütuna göre grubu ifade eder.
Örneğin,
- &=Products.Units(subtotal9:Products.ProductID) şuna göre özet işlevini belirtir:Birimler alanı ile ilgili olarakÜrün kimliği alanÜrün:% s masa.
- &=Tabx.Col3(subtotal9:Tabx.Col1) özet fonksiyonunu belirtir.Sütun3 alan grubuCol1 masadaTabx.
- &=Table1.ColumnD(subtotal9:Table1.ColumnA&Table1.ColumnB) aşağıdaki özet işlevini belirtirsütunD alan grubuSütunA veSütunB masadaTablo 1.
Bu örnek, eylem halindeki bazı gruplandırma parametrelerini göstermektedir. Northwind.mdb Microsoft Access veritabanını kullanır ve “Sipariş Ayrıntıları” adlı tablodan veri çıkarır. Microsoft Excel’de SmartMarker_Designer.xls adlı bir tasarımcı dosyası oluşturuyoruz ve çalışma sayfalarında çeşitli hücrelere akıllı işaretleyiciler yerleştiriyoruz. İşaretçiler, çalışma sayfalarını doldurmak için işlenir. Veriler bir grup alanı tarafından yerleştirilir ve düzenlenir.
Tasarımcı dosyasında iki çalışma sayfası vardır. İlkinde, aşağıdaki ekran görüntüsünde gösterildiği gibi gruplama parametrelerine sahip akıllı işaretçiler koyduk. Üç akıllı işaretçi (gruplama parametreleriyle birlikte) yerleştirilir: &=[Sipariş Ayrıntıları].SiparişKimliği(grup:birleştir,atla:1), &=[Sipariş Ayrıntıları].Miktar(ara toplam9:Sipariş Ayrıntıları.SiparişKimliği) ve &=[Sipariş Ayrıntıları].BirimPrice(alt toplam9:Sipariş Ayrıntıları.SiparişKimliği) sırasıyla A5, B5 ve C5’e gider.
SmartMarker_Designer.xls dosyasındaki akıllı işaretleyicilerle tamamlanmış ilk çalışma sayfası |
---|
![]() |
Tasarımcı dosyasının ikinci çalışma sayfasında, aşağıdaki şekilde gösterildiği gibi bazı daha akıllı işaretçiler koyduk. Aşağıdaki akıllı işaretleri yerleştiriyoruz: |
&=[Sipariş Ayrıntıları].SiparişKimliği(grup:normal), |
&=[Sipariş Ayrıntıları].Miktar, |
&=[Sipariş Ayrıntıları].BirimFiyat, |
&=&=B(r)*C(r) ve |
&=alt toplam9:Sipariş Ayrıntıları.SiparişKimliği sırasıyla A5, B5, C5, D5 ve C6’ya. |
SmartMarker_Designer.xls dosyasının, karışık akıllı işaretçileri gösteren ikinci çalışma sayfası. |
---|
![]() |
İşte örnekte kullanılan kaynak kodu. |
private void SmartMarkers_GroupingData() | |
{ | |
//Examples-CSharp-SmartMarkers-GroupingData-1.cs | |
// 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 + "Designer.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"); | |
} | |
class OleDbCommand | |
{ | |
private string p; | |
private OleDbConnection con; | |
public OleDbCommand(string p, OleDbConnection con) | |
{ | |
// TODO: Complete member initialization | |
this.p = p; | |
this.con = con; | |
} | |
} | |
class OleDbConnection | |
{ | |
private string p; | |
public OleDbConnection(string p) | |
{ | |
// TODO: Complete member initialization | |
this.p = p; | |
} | |
internal void Open() | |
{ | |
} | |
} | |
class OleDbDataAdapter | |
{ | |
public OleDbCommand SelectCommand { get; set; } | |
internal void Fill(System.Data.DataSet ds, string p) | |
{ | |
} | |
} |
Anonim Türler veya Özel Nesneler Kullanma
Aspose.Cells, akıllı işaretleyicilerdeki anonim türleri veya özel nesneleri de destekler. Aşağıdaki örnek, bunun nasıl çalıştığını göstermektedir.Akıllı İşaretleyicileri kullanarak dinamik nesnelerden veri almak için aşağıdaki makaleyi ziyaret edin:
Dinamik nesneden veri kaynağı olarak içe aktarma
private void SmartMarkers_UsingAnonymousTypes() | |
{ | |
// 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 workbookdesigner object. | |
WorkbookDesigner report = new WorkbookDesigner(); | |
// Get the first worksheet(default sheet) in the workbook. | |
Aspose.Cells.Worksheet sheet = report.Workbook.Worksheets[0]; | |
// Input some markers to the cells. | |
sheet.Cells["A1"].PutValue("Name"); | |
sheet.Cells["B1"].PutValue("Age"); | |
sheet.Cells["A2"].PutValue("&=MyProduct.Name"); | |
sheet.Cells["B2"].PutValue("&=MyProduct.Age"); | |
// Instantiate the list collection based on the custom class. | |
IList<Person> list = new List<Person>(); | |
// Provide values for the markers using the custom class object. | |
list.Add(new Person("Simon", 30)); | |
list.Add(new Person("Johnson", 33)); | |
// Set the data source. | |
report.SetDataSource("MyProduct", list); | |
// Process the markers. | |
report.Process(false); | |
// Save the excel file. | |
report.Workbook.Save(dataDir + "Smart Marker Customobjects.xls"); | |
} | |
// Definition of Custom class. | |
public class Person | |
{ | |
private string m_Name; | |
public string Name | |
{ | |
get { return m_Name; } | |
set { m_Name = value; } | |
} | |
private int m_Age; | |
public int Age | |
{ | |
get { return m_Age; } | |
set { m_Age = value; } | |
} | |
internal Person(string name, int age) | |
{ | |
this.m_Name = name; | |
this.m_Age = age; | |
} | |
} |
Görüntü İşaretleyicileri
Aspose.Cells akıllı işaretleyiciler, görüntü işaretleyicilerini de destekler. Bu bölüm, akıllı işaretleyicileri kullanarak nasıl resim ekleyeceğinizi gösterir.
Görüntü Parametreleri
Görüntüleri yönetmek için akıllı işaretleyici parametreleri.
- Resim:Hücreye Sığdır - Görüntüyü hücrenin satır yüksekliğine ve sütun genişliğine otomatik olarak sığdırın.
- Resim:ÖlçekN - Yüksekliği ve genişliği yüzde N olarak ölçeklendirin.
- Resim:Genişlik:Nin&Yükseklik:Nin - Görüntüyü N inç yüksekliğinde ve N inç genişliğinde oluşturun. Sol ve Üst konumları da (puan olarak) belirleyebilirsiniz.
İşte örnekte kullanılan kaynak kodu.
// 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+ "output.xls"); |
Yuvalanmış Nesneleri Kullanma
Aspose.Cells, akıllı işaretleyicilerdeki iç içe nesneleri destekler, iç içe nesneler basit olmalıdır. Basit bir şablon dosyası kullanıyoruz. Bazı iç içe akıllı işaretçileri içeren tasarımcı elektronik tablosuna bakın.
İç içe akıllı işaretçileri gösteren SM_NestedObjects.xlsx dosyasının ilk çalışma sayfası. |
---|
![]() |
Aşağıdaki örnek bunun nasıl çalıştığını göstermektedir. |
private void SmartMarkers_UsingNestedObjects() | |
{ | |
// 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 + "output.xlsx"); | |
} | |
class Individual | |
{ | |
private String m_Name; | |
public String Name | |
{ | |
get { return m_Name; } | |
set { m_Name = value; } | |
} | |
private int m_Age; | |
public int Age | |
{ | |
get { return m_Age; } | |
set { m_Age = value; } | |
} | |
internal Individual(string name, int age) | |
{ | |
this.Name = name; | |
this.Age = age; | |
} | |
private Wife m_Wife; | |
public Wife Wife | |
{ | |
get { return m_Wife; } | |
set { m_Wife = value; } | |
} | |
} | |
public class Wife | |
{ | |
public Wife(string name, int age) | |
{ | |
this.m_name = name; | |
this.m_age = age; | |
} | |
private string m_name; | |
public string Name | |
{ | |
get { return m_name; } | |
set { m_name = value; } | |
} | |
private int m_age; | |
public int Age | |
{ | |
get { return m_age; } | |
set { m_age = value; } | |
} | |
} |
Genel Listeyi İç İçe Nesne Olarak Kullanma
Aspose.Cells artık genel listenin iç içe geçmiş bir nesne olarak kullanılmasını da destekliyor. Lütfen aşağıdaki kodla oluşturulan çıktı excel dosyasının ekran görüntüsünü kontrol edin. Ekran görüntüsünde görebileceğiniz gibi, bir Öğretmen nesnesi birden çok iç içe Öğrenci nesnesi içerir.
![]() |
---|
// 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(); | |
// Create a designer workbook | |
// Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
worksheet.Cells["A1"].PutValue("Teacher Name"); | |
worksheet.Cells["A2"].PutValue("&=Teacher.Name"); | |
worksheet.Cells["B1"].PutValue("Teacher Age"); | |
worksheet.Cells["B2"].PutValue("&=Teacher.Age"); | |
worksheet.Cells["C1"].PutValue("Student Name"); | |
worksheet.Cells["C2"].PutValue("&=Teacher.Students.Name"); | |
worksheet.Cells["D1"].PutValue("Student Age"); | |
worksheet.Cells["D2"].PutValue("&=Teacher.Students.Age"); | |
// Apply Style to A1:D1 | |
Range range = worksheet.Cells.CreateRange("A1:D1"); | |
Style style = workbook.CreateStyle(); | |
style.Font.IsBold = true; | |
style.ForegroundColor = Color.Yellow; | |
style.Pattern = BackgroundType.Solid; | |
StyleFlag flag = new StyleFlag(); | |
flag.All = true; | |
range.ApplyStyle(style, flag); | |
// Initialize WorkbookDesigner object | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
// Load the template file | |
designer.Workbook = workbook; | |
System.Collections.Generic.List<Teacher> list = new System.Collections.Generic.List<Teacher>(); | |
// Create an object for the Teacher class | |
Teacher h1 = new Teacher("Mark John", 30); | |
// Create the relevant student objects for the Teacher object | |
h1.Students = new List<Person>(); | |
h1.Students.Add(new Person("Chen Zhao", 14)); | |
h1.Students.Add(new Person("Jamima Winfrey", 18)); | |
h1.Students.Add(new Person("Reham Smith", 15)); | |
// Create another object for the Teacher class | |
Teacher h2 = new Teacher("Masood Shankar", 40); | |
// Create the relevant student objects for the Teacher object | |
h2.Students = new List<Person>(); | |
h2.Students.Add(new Person("Karishma Jathool", 16)); | |
h2.Students.Add(new Person("Angela Rose", 13)); | |
h2.Students.Add(new Person("Hina Khanna", 15)); | |
// Add the objects to the list | |
list.Add(h1); | |
list.Add(h2); | |
// Specify the DataSource | |
designer.SetDataSource("Teacher", list); | |
// Process the markers | |
designer.Process(); | |
// Autofit columns | |
worksheet.AutoFitColumns(); | |
// Save the Excel file. | |
designer.Workbook.Save(dataDir + "output.xlsx"); | |
Akıllı İşaretleyicilerin HTML özelliğini kullanma
Aşağıdaki örnek kod, Akıllı İşaretleyicilerin HTML özelliğinin kullanımını açıklar. İşleme gireceği zaman HTML nedeniyle “Hello World” de “World” yazacaktır. etiket.
// 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(); | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
designer.Workbook = workbook; | |
workbook.Worksheets[0].Cells["A1"].PutValue("&=$VariableArray(HTML)"); | |
designer.SetDataSource("VariableArray", new String[] { "Hello <b>World</b>", "Arabic", "Hindi", "Urdu", "French" }); | |
designer.Process(); | |
workbook.Save(dataDir + "output.xls"); | |
satır satır değil
Mevcut varsayılan işleme yöntemi, smartmaker’ı satır satır işlemektir. Ancak bazen aynı veri tablosunun akıllı işaretleyicilerinin birlikte işlenmesi gerekir. aynı satırda olsalar da olmasalar da, “_CellsSmartMarkers” adlı bir aralık belirtmeniz ve işlemeyi çağırmadan önce WorkbookDesigner.LineByLine’ı false olarak belirtmeniz gerekir.
||
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(); | |
Style style = workbook.CreateStyle(); | |
style.Pattern = BackgroundType.Solid; | |
style.ForegroundColor = Color.Black; | |
style.Font.Color = Color.White; | |
// Create a designer workbook | |
// Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
worksheet.Cells["A1"].PutValue("Teacher Name"); | |
worksheet.Cells["A1"].SetStyle(style); | |
worksheet.Cells["A2"].PutValue("&=Teacher.Name"); | |
worksheet.Cells["B1"].PutValue("Teacher Age"); | |
worksheet.Cells["B1"].SetStyle(style); | |
worksheet.Cells["B2"].PutValue("&=Teacher.Age"); | |
worksheet.Cells["A3"].PutValue("Student Name"); | |
worksheet.Cells["A3"].SetStyle(style); | |
worksheet.Cells["A4"].PutValue("&=Teacher.Students.Name"); | |
worksheet.Cells["B3"].PutValue("Student Age"); | |
worksheet.Cells["B3"].SetStyle(style); | |
worksheet.Cells["B4"].PutValue("&=Teacher.Students.Age"); | |
worksheet.AutoFitColumns(); | |
//A named range "_CellsSmartMarkers" must be added for checking which range contains all smart markers about a table. | |
worksheet.Cells.CreateRange("A1:B4").Name = "_CellsSmartMarkers"; | |
// Initialize WorkbookDesigner object | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
// Load the template file | |
designer.Workbook = workbook; | |
System.Collections.Generic.List<Teacher> list = new System.Collections.Generic.List<Teacher>(); | |
// Create an object for the Teacher class | |
Teacher h1 = new Teacher("Mark John", 30); | |
// Create the relevant student objects for the Teacher object | |
h1.Students = new List<Person>(); | |
h1.Students.Add(new Person("Chen Zhao", 14)); | |
h1.Students.Add(new Person("Jamima Winfrey", 18)); | |
h1.Students.Add(new Person("Reham Smith", 15)); | |
// Create another object for the Teacher class | |
Teacher h2 = new Teacher("Masood Shankar", 40); | |
// Create the relevant student objects for the Teacher object | |
h2.Students = new List<Person>(); | |
h2.Students.Add(new Person("Karishma Jathool", 16)); | |
h2.Students.Add(new Person("Angela Rose", 13)); | |
h2.Students.Add(new Person("Hina Khanna", 15)); | |
// Add the objects to the list | |
list.Add(h1); | |
list.Add(h2); | |
// Specify the DataSource | |
designer.SetDataSource("Teacher", list); | |
designer.LineByLine = false; | |
// Process the markers | |
designer.Process(); | |
// Autofit columns | |
worksheet.AutoFitColumns(); | |
// Save the Excel file. | |
designer.Workbook.Save(dataDir + "output.xlsx"); | |
public class Person | |
{ | |
private string m_Name; | |
public string Name | |
{ | |
get { return m_Name; } | |
set { m_Name = value; } | |
} | |
private int m_Age; | |
public int Age | |
{ | |
get { return m_Age; } | |
set { m_Age = value; } | |
} | |
internal Person(string name, int age) | |
{ | |
this.m_Name = name; | |
this.m_Age = age; | |
} | |
} | |
public class Teacher | |
{ | |
private string m_Name; | |
public string Name | |
{ | |
get { return m_Name; } | |
set { m_Name = value; } | |
} | |
private int m_Age; | |
public int Age | |
{ | |
get { return m_Age; } | |
set { m_Age = value; } | |
} | |
private List<Person> mStudents; | |
public List<Person> Students | |
{ | |
get { return mStudents; } | |
set { mStudents = value; } | |
} | |
public Teacher(string name, int age) | |
{ | |
this.Name = name; | |
this.Age = age; | |
} | |
} |
Akıllı İşaretleyiciler ile Verileri Birleştirirken Bildirim Alma
Bazen, tamamlanmadan önce işlenmekte olan hücre referansı veya belirli Akıllı İşaretleyici ile ilgili bildirimlerin alınması gerekebilir. Bu, WorkbookDesigner.CallBack özelliği ve ISmartMarkerCallBack kullanılarak elde edilebilir.
ileri konular
- SmartMarkers’a Anonim veya Özel Nesne Ekleme
- Veriler Çok Büyükse Akıllı İşaretleyici Verilerini Diğer Çalışma Sayfalarına Otomatik Olarak Doldur
- Akıllı İşaretçileri Biçimlendirme
- Akıllı İşaretleyiciler ile Verileri Birleştirirken Bildirim Alma
- WorkbookDesigner için özel DataSource ayarlama
- Hücrelerde baştaki kesme işaretini göster
- Akıllı İşaretleyici alanında Formül parametresini kullanma
- Akıllı İşaretleyicilerde Verileri Gruplandırırken Görüntü İşaretleyicileri Kullanma