Akıllı işaretlerle veri ithal etme ve yerleştirme
Giriş
Akıllı işaretçiler, Aspose.Cells’in bir Microsoft Excel tasarımcı elektronik tablosuna hangi bilgileri yerleştireceğini bildirmek için kullanılır. Akıllı işaretçiler, yalnızca belirli bilgi ve biçimlendirmeyi içeren şablonlar oluşturmanıza izin verir.
Tasarım Elektronik Tablosu & Akıllı İşaretçiler
Tasarımcı elektronik tablolar, görsel biçimlendirme, formüller ve akıllı işaretçiler içeren standart Excel dosyalarıdır. Bağlantılı bir ya da daha fazla veri kaynağını, örneğin proje bilgilerini ve ilgili kişilerin bilgilerini içerebilir. Akıllı işaretçiler, bilgilerin yer almasını istediğiniz hücrelere yazılır.
Tüm akıllı işaretçiler, &= ile başlar. Bir veri işaretçisinin bir örneği, örneğin, &=Party.FullName’dir. Veri işaretçisi birden fazla ögeye yol açarsa, örneğin, tam bir satır, o zaman yeni bilgilere yer açmak için otomatik olarak aşağıdaki satırlar taşınır. Bu şekilde, toplam ve alt toplamlar eklenen verilere dayalı olarak hesaplamak için veri işaretçisinden hemen sonra bir satıra yerleştirilebilir. Eklenen satırlarda hesaplama yapmak için dinamik formüller kullanın.
Akıllı işaretçiler çoğu bilgi için veri kaynağı ve alan adı bölümlerinden oluşur. Özel bilgi, değişkenler ve değişken dizileri ile de iletilmiş olabilir. Değişkenler her zaman sadece bir hücreyi doldururken, değişken dizileri birkaç hücreyi doldurabilir. Bir hücre başına yalnızca bir veri işareti kullanın. Kullanılmayan akıllı işaretçiler kaldırılır.
Akıllı işaretçi ayrıca parametreler içerebilir. Parametreler, bilgilerin nasıl düzenleneceğini değiştirmenize olanak tanır. Bunlar, virgülle ayrılmış bir liste olarak parantez içinde akıllı işaretçinin sonuna eklenir.
Akıllı İşaretçi Seçenekleri
&=VeriKaynağı.AlanAdı &=[Veri Kaynağı].[Alan Adı] &=$DeğişkenAdı &=$DeğişkenDizisi &==DinamikFormül &=&=TekrarDinamikFormül
Parametreler
Aşağıdaki parametreler kabul edilir:
- noadd - Ekstra satırlar eklemeyin.
- skip:n - Her veri satırı için n sayısında satır atla.
- ascending:n ya da descending:n - Akıllı işaretçilerde veriyi sırala. n 1 ise, sütun sıralayıcının ilk anahtarıdır. Veri, veri kaynağının işlenmesinden sonra sıralanır. Örneğin: &=Tablo1.Alan3(ascending:1).
- horizontal - Veriyi yukarıdan aşağıya değil, soldan sağa yazın.
- numeric - Metni mümkünse numaraya dönüştürür.
- kaydırma - Veriyi sığdırmak için aşağıya ya da sağa kaydırarak ekstra satırlar veya sütunlar oluşturun. Kaydırma parametresi, Microsoft Excel’de olduğu gibi çalışır. Örneğin, Microsoft Excel’de bir hücre aralığını seçtiğinizde, sağ tıklayıp Ekle‘yi seçerek aşağıya hücre kaydır, sağa hücre kaydır ve diğer seçenekleri belirlediğinizde. Kısacası, kaydırma parametresi dikey/normal (yukarıdan aşağıya) ya da yatay (soldan sağa) akıllı işaretler için aynı işlevi doldurur.
- copystyle - Temel hücrenin stilini o sütundaki tüm hücrelere kopyala.
noadd ve skip parametreleri, veriyi alternatif satırlara eklemek için birleştirilebilir. Şablon, üstten alta işlenir, bu nedenle alternatif satırın önünde ekstra satırların eklenmesini önlemek için ilk satıra noadd eklemelisiniz.
Birden fazla parametreniz varsa, bunları virgülle ayırın, ancak boşluk bırakmayın: parametreA,parametreB,parametreC
Aşağıdaki ekran görüntüleri, her iki satıra veri eklemenin nasıl yapılacağını göstermektedir.
Şablon Dosyası | Çıkış Dosyası |
---|---|
![]() |
![]() |
Dinamik Formüller
Dinamik formüller, dışa aktarma işlemi sırasında eklenecek satırlara referans olan hücrelere Excel formüllerini eklemenizi sağlar. Dinamik formüller her eklenen satır için tekrarlayabilir veya yalnızca veri işaretinin konumlandığı hücreyi kullanabilir.
Dinamik formüller aşağıdaki ek seçenekleri sağlar:
- r - Geçerli satır numarası.
- 2, -1 - Geçerli satır numarasına göre ofset.
Örneğin:
&=&=B{-1}/C{-1}~(skip:1)
Dinamik formül işaretleyicisinde, “-1”, sırasıyla B ve C sütunlarında mevcut satıra ofset olarak belirlenecektir, atlamalı parametre bir satırdır. Ayrıca, dinamik formüllerde ileri parametreleri uygulamak için ayracı bir karakter olarak belirtmeliyiz.
"~"
dinamik formüllerde ileri parametreleri uygulamak için ayraç karakterini bir ayraç kararkteri olarak kullanın.
Aşağıdaki ekran görüntüleri, tekrarlanan dinamik bir formülü ve sonuçlanan Excel çalışma sayfasını göstermektedir.
Şablon Dosyası | Çıktı Dosyası |
---|---|
![]() |
![]() |
Hücre “C1” formülü = A1*B1 içerir, hücre “C2” = A2*B2 ve hücre “C3” = A3*B3 içerir. |
Akıllı İşaretleri işlemek çok kolaydır. Aşağıdaki örnek kod, Akıllı İşaretlerde dinamik formüllerin nasıl kullanılacağını göstermektedir. Şablon dosyasını yükler ve test verileri oluşturur, işaretleri işleyerek hücrelere veri doldurur.
// 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 Diziler Kullanma
Aşağıdaki örnek kod, akıllı işaretlerde değişken dizilerini nasıl kullanacağını göstermektedir. İlk çalışma sayfasının A1 hücresine dinamik olarak değişken dizi işaretini yerleştirir ve bu işaret için ayarladığımız değerlerin dizesini içerir, işaretleri işleyerek hücrelere veri doldurur. Son olarak Excel dosyasını kaydederiz.
// 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"); |
Veri Gruplama
Bazı Excel raporlarında verileri okumayı ve analiz etmeyi kolaylaştırmak için verileri gruplara ayırmanız gerekebilir. Verileri gruplara ayırmak için temel amaçlardan biri, her kayıt grubu üzerinde hesaplamaları (özet operasyonları gerçekleştirmek) çalıştırmaktır.
Aspose.Cells akıllı işaretleri, verileri alanlara göre gruplamayı ve her veri kümesi veya veri grubu arasına özet satırlar eklemeyi sağlar. Örneğin, Müşteriler.MüşteriID’ye göre verileri gruplandırıyorsanız, grup her değiştiğinde bir özet kaydı ekleyebilirsiniz.
Parametreler
Veri gruplama için kullanılan bazı akıllı işaretçi parametreleri aşağıda verilmiştir.
group:normal/merge/repeat
Seçebileceğiniz üç tür gruplamayı destekliyoruz.
- normal - Gruplama alanının değeri sütundaki ilgili kayıtlar için tekrarlanmaz; bunun yerine her veri grubu için bir kez yazdırılır.
- merge - Normal parametre için aynı davranışa sahiptir, ancak her grup için gruplandırma alanlarını birleştirir.
- repeat - Gruplama alanının değeri ilgili kayıtlar için tekrarlanır.
Örnek: &=Veriler.CustomerID(group:merge)
skip
Belirtilen sayıda satır atlar. Örneğin, &=Çalışanlar.ÇalışanID(grup:normal,skip:1)
Örneğin, &=Çalışanlar.ÇalışanID(grup:normal,atla:1)
subtotalN
Belirtilen bir gruplama alanıyla ilgili veri alanı için bir özet işlemi gerçekleştirir. N, veri listesinde alt toplamlar hesaplanırken kullanılan işlevi belirleyen 1 ile 11 arasındaki sayıları temsil eder. (1=ORTALAMA, 2=SAYI, 3=SAYMAK, 4=MAKS, 5=MIN,…9=TOPLAM vb.) Daha fazla ayrıntı için Microsoft Excel’in yardımında Subtotal başvurusuna bakınız.
Format aslında şu şekilde belirtilir: subtotalN:Ref, Ref gruplama sütununu temsil eder.
Örneğin,
- &=Ürünler.Birimler(subtotal9:Ürünler.ÜrünID) Ürünler tablosundaki Birimler alanı üzerinde ÜrünID alanına göre özet işlevi belirtir.
- &=Tabx.Col3(subtotal9:Tabx.Col1) Tabx tablosundaki Col1 tarafından gruplandırılan Col3 alanı üzerinde özet işlevi belirtir.
- &=Table1.ColumnD(subtotal9:Table1.ColumnA&Table1.ColumnB) Table1 tablosunda ColumnA ve ColumnB tarafından gruplandırılmış ColumnD alanı üzerinde özet işlemi belirtir.
Bu örnek, gruplama parametrelerinin işleyişi hakkında bilgi vermektedir. Microsoft Access veritabanından Northwind.mdb kullanır ve “Order Details” adlı tablodan veri çıkarır. Microsoft Excel’de SmartMarker_Designer.xls adında bir tasarım dosyası oluşturur ve işlem için sayfalara akıllı işaretçiler yerleştirir. İşaretçiler, çalışma sayfalarını doldurmak için işlenir. Veriler gruplandırılır ve düzenlenir.
Tasarım dosyasında iki çalışma sayfası bulunmaktadır. İlk çalışma sayfasına aşağıdaki ekran görüntüsünde gösterildiği gibi gruplama parametreleriyle akıllı işaretçiler yerleştiririz. Üç akıllı işaretçi (gruplama parametreleri ile birlikte) yerleştirilir: &=[Order Details].OrderID(group:merge,skip:1), &=[Order Details].Quantity(subtotal9:Order Details.OrderID), ve &=[Order Details].UnitPrice(subtotal9:Order Details.OrderID) sırasıyla A5, B5 ve C5 hücrelerine yerleştirilir.
SmartMarker_Designer.xls dosyasındaki ilk çalışma sayfası, akıllı işaretçilerle birlikte |
---|
![]() |
Tasarım dosyasının ikinci çalışma sayfasında aşağıdaki şekilde gösterildiği gibi daha fazla akıllı işaretçi yerleştiririz. Aşağıdaki akıllı işaretçileri yerleştiririz: |
&=[Order Details].OrderID(group:normal), |
&=[Order Details].Quantity, |
&=[Order Details].UnitPrice, |
&=&=B(r)*C(r), ve |
&=subtotal9:Order Details.OrderID sırasıyla A5, B5, C5, D5 ve C6 hücrelerine yerleştirilir. |
SmartMarker_Designer.xls dosyasının ikinci çalışma sayfası, karma akıllı işaretçilerle birlikte |
---|
![]() |
İşte örnekte kullanılan kaynak kod. |
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 Kullanarak
Aspose.Cells ayrıca akıllı işaretçilerde anonim türleri veya özel nesneleri destekler. Aşağıdaki örnek, bu nasıl çalıştığını göstermektedir. Anlık nesnelerden veri içe aktarma kullanımı için şu makaleyi ziyaret edin:
Dinamik nesneden veri 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ü Belirteçleri
Aspose.Cells akıllı işaretçileri ayrıca görüntü işaretçilerini de destekler. Bu bölüm size akıllı işaretçileri kullanarak resim eklemenin nasıl yapıldığını gösterir.
Görüntü Parametreleri
Resimleri yönetmek için akıllı işaretçi parametreleri.
- Resim:HücreyeSığdır - Resmi hücrenin satır yüksekliğine ve sütun genişliğine otomatik sığdır.
- Resim:ÖlçekN - Yüksekliği ve genişliği N yüzde ölçekle.
- Resim:Genişlik:Nin&Yükseklik:Nin - Resmi N inç yüksekliğinde ve N inç genişliğinde oluşturun. Sol ve Üst pozisyonları da belirleyebilirsiniz (puan cinsinden).
İşte örnekte kullanılan kaynak kod.
// 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"); |
Yerleşik Nesneleri Kullanmak
Aspose.Cells, iç içe geçmiş nesneleri akıllı işaretlerde destekler, iç içe geçen nesneler basit olmalıdır. Basit bir şablon dosyası kullanıyoruz. Birkaç iç içe akıllı işaret içeren tasarımcı elektronik tabloyu gösteren SM_NestedObjects.xlsx dosyasının ilk çalışma sayfasını görüntüleyin.
** SM_NestedObjects.xlsx dosyasının ilk çalışma sayfasında iç içe akıllı işaretleri gösteren ilk çalışma sayfasının ** |
---|
![]() |
Aşağıdaki örnek, bu işlemin nasıl çalıştığını gösterir. |
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; } | |
} | |
} |
Yerleşik Nesne Olarak Genel Liste Kullanma
Aspose.Cells artık iç içe genel liste kullanımı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ördüğünüz gibi, bir Öğretmen nesnesinin birden fazla gömülü Öğrenci nesnesini içerdiğini görebilirsiniz.
![]() |
---|
// 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ı İşaretçilerin HTML Özelliğini Kullanma
The following sample code explains the use of HTML property of the Smart Markers. When it will be processed, it will show “World” in “Hello World” as bold because of HTML tag.
// 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 akıllı işaretleri satır satır işlemektir. Ancak bazen aynı veri tablosunun akıllı işaretleri birlikte işlenmesi gerekebilir, satırda olup olmadığına bakılmaksızın, bu durumda işlemi çağırmadan önce bir adlandırılmış aralık “_CellsSmartMarkers” belirtmeniz ve WorkbookDesigner.LineByLine’ı false olarak belirtmeniz gerekir. Akıllı İşaretlerle Veri Birleştirirken Bildirim Alma
||
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ı İşaretçilerle Veri Birleştirirken Bildirim Almak
Gelişmiş konular
Gelişmiş Konular
- Akıllı İşaretlere Anonim veya Özel Nesne Ekleme
- Veri Çok Büyükse Diğer Çalışsayfalara Akıllı İşaret Verileri Otomatik Doldur
- Biçimlendirme Akıllı İşaretler
- Akıllı İşaretçilerle Veri Birleştirirken Bildirim Almak
- WorkbookDesigner için özel Veri Kaynağı Ayarlama
- Hücrelerde Öncü Apostrof Göster
- Akıllı İşaretçi Alanında Formula Parametresi Kullanımı
- Akıllı İşaretçi Alanında Verileri Gruplandırırken Resim İşaretçileri Kullanma