将MS Word API转换为Aspose Word API

时间:2014-03-17 07:59:20

标签: excel excel-vba aspose aspose-cells vba

您能否提供使用Aspose Word将以下VB代码转换为VB.NET的代码?

 Dim os AS Excel.Worksheet
 oS.Range("A55", "S55").Select()
 oS.Application.Selection.Copy()
 oS.Application.Selection.Insert(Shift:=Excel.XlDirection.xlDown)

所有人和最好的祝福者。

1 个答案:

答案 0 :(得分:1)

在操作Excel文件时,您似乎对Aspose.Cells API的代码感兴趣而不是Aspose.Words API。

好吧,根据您的共享代码,您将获得一系列单元格,使用“Shift Cells Down”选项复制相同选定位置的单元格。您可以将其转换为Aspose.Cells代码,如下所示:

'Open the Source Excel file
Dim workbook As New Workbook("C:\Test_File.xlsx")

'get cells collection of first worksheet
Dim cells As Cells = workbook.Worksheets(0).Cells


'get the source range to copy
Dim sourceRange As Range = cells.CreateRange("A55:S55")

'Insert the range below the source range 
Dim ca As CellArea = CellArea.CreateCellArea("A56", "S56")
cells.InsertRange(ca, ShiftType.Down)

' Move Source Range one Row down as Copy process has Shift Cells Down option selected
' this is only required if you have a named range and want it shifted as in Excel   
sourceRange.MoveTo(55, 0)

'create destination range
Dim destinationRange As Range = cells.CreateRange("A55:S55")

'Copy the source range data to desitnation range (newly inserted range)
destinationRange.Copy(sourceRange)

'save the resultant file
workbook.Save("C:\Test_Out.xlsx")

希望上面的代码可以帮助您实现。