Spread Studio for .NET使用教程:復(fù)制并插入工作表
用戶可以復(fù)制和插入一個(gè)工作表到同一個(gè)Spread組件或窗體中的另一個(gè)Spread組件。沒(méi)有內(nèi)置工作表復(fù)制方式,但是可以使用下面的代碼方法輕松創(chuàng)建自己的CopySheet方法。復(fù)制一個(gè)表并將之插入到組件中,只需創(chuàng)建一個(gè)新的方法,命名為CopySheet,如下所示,然后使用SheetViewCollection類中的Add或者Insert方法。
在調(diào)用CopySheet之后,使用SheetViewCollection.Add或SheetViewCollection.Insert把它插入到一個(gè)Spread組件(相同的一個(gè)或一個(gè)不同的一個(gè))。
也會(huì)在工作表中復(fù)制所有的形狀。
應(yīng)該注意,以這種方式復(fù)制工作表也會(huì)復(fù)制工作表中的NamedStyleCollection,并在集合中創(chuàng)建單獨(dú)的NamedStyle對(duì)象,獨(dú)立于復(fù)制,不能與復(fù)制工作表的原NamedStyleCollection共享。如果你想保持命名風(fēng)格共享,您可以將您想要分享的NamedStyleCollection分配到副本的NamedStyles屬性。這可以通過(guò)簡(jiǎn)單的將NamedStyleCollection分配給一個(gè)變量,然后設(shè)置NamedStyles屬性為Nothing(null in C#),然后復(fù)制,然后分配變量回到NamedStyles屬性。
Spread Designer可以用來(lái)在設(shè)計(jì)時(shí)復(fù)制和粘貼一個(gè)工作表。右鍵單擊設(shè)計(jì)器中工作表標(biāo)簽圖標(biāo)彈出復(fù)制,剪切,粘貼菜單。這個(gè)SpreadActions類有剪貼復(fù)制,剪切,粘貼的選項(xiàng)。
》》》免費(fèi)下載Spread Studio for .NET最新版
使用代碼:
創(chuàng)建一個(gè)新的CopySheet方法用于復(fù)制表。
處理工作表命名的樣式,如上所述。
調(diào)用Sheets快捷方法Add添加新的工作表或插入方法,用以插入工作表到組件的SheetViewCollection。
示例:
下面是CopySheet方法的代碼:
C#
public FarPoint.Win.Spread.SheetView CopySheet(FarPoint.Win.Spread.SheetView sheet) { FarPoint.Win.Spread.SheetView newSheet = null; if (sheet != null ) { newSheet = FarPoint.Win.Serializer.LoadObjectXml(GetType(FarPoint.Win.Spread.SheetView), FarPoint.Win.Serializer.GetObjectXml(sheet, "CopySheet"), "CopySheet"); } return newSheet; }
VB
Public Function CopySheet(sheet As FarPoint.Win.Spread.SheetView) As FarPoint.Win.Spread.SheetView Dim newSheet as FarPoint.Win.Spread.SheetView = Nothing If Not IsNothing(sheet) Then newSheet = FarPoint.Win.Serializer.LoadObjectXml(GetType(FarPoint.Win.Spread.SheetView), FarPoint.Win.Serializer.GetObjectXml(sheet, "CopySheet"), "CopySheet") End If Return newSheet End Function