Spread Studio for .NET使用教程:復制并插入工作表
用戶可以復制和插入一個工作表到同一個Spread組件或窗體中的另一個Spread組件。沒有內置工作表復制方式,但是可以使用下面的代碼方法輕松創建自己的CopySheet方法。復制一個表并將之插入到組件中,只需創建一個新的方法,命名為CopySheet,如下所示,然后使用SheetViewCollection類中的Add或者Insert方法。
在調用CopySheet之后,使用SheetViewCollection.Add或SheetViewCollection.Insert把它插入到一個Spread組件(相同的一個或一個不同的一個)。
也會在工作表中復制所有的形狀。
應該注意,以這種方式復制工作表也會復制工作表中的NamedStyleCollection,并在集合中創建單獨的NamedStyle對象,獨立于復制,不能與復制工作表的原NamedStyleCollection共享。如果你想保持命名風格共享,您可以將您想要分享的NamedStyleCollection分配到副本的NamedStyles屬性。這可以通過簡單的將NamedStyleCollection分配給一個變量,然后設置NamedStyles屬性為Nothing(null in C#),然后復制,然后分配變量回到NamedStyles屬性。
Spread Designer可以用來在設計時復制和粘貼一個工作表。右鍵單擊設計器中工作表標簽圖標彈出復制,剪切,粘貼菜單。這個SpreadActions類有剪貼復制,剪切,粘貼的選項。
》》》免費下載Spread Studio for .NET最新版
使用代碼:
創建一個新的CopySheet方法用于復制表。
處理工作表命名的樣式,如上所述。
調用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