タイトル : エクセルをコピーし、行の高さも複写出来ますか? 投稿日 : 2005/04/03(Sun) 21:42 投稿者 : 匿名希望
[OSのVer]:Windows 2000 XP [VBのVer]:VB.NET 2003 下記の様にコピーをしていて、プロセスもきちんと終了しますが、 エクセルの行の高さまでは複写出来ません。 以前VB6 でコーディングしていた時は Rows で複写して、行の高さも複写出来ましたが、 .NET での複写は Range 又は _Default を使用した方がいいとのアドバイスを受けましたので、 取り込んでみたのですが…どうにか、行の高さまで複写出来る方法のアドバイスを 頂けないでしょうか? Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim xlApp As Excel.Application Dim xlsSheet As Excel.Worksheet Dim xlsBooks As Excel.Workbooks Dim xlsBook As Excel.Workbook Dim xlsSheets As Excel.Sheets Dim objCells As Excel.Range Dim objRows As Excel.Range Dim R1, R2 As Excel.Range Dim RCopy As Excel.Range Dim RPaste As Excel.Range xlApp = New Excel.Application xlsBooks = xlApp.Workbooks xlsBook = xlsBooks.Open("c:\Test.xls") xlsSheets = xlsBook.Worksheets xlsSheet = xlsSheets.Item(1) objCells = xlsSheet.Cells R1 = DirectCast(objCells._Default(1, 1), Excel.Range) R2 = DirectCast(objCells._Default(4, 3), Excel.Range) RCopy = xlsSheet.Range(R1, R2) RCopy.Copy() RPaste = DirectCast(objCells._Default(6, 1), Excel.Range) RPaste.Insert() System.Runtime.InteropServices.Marshal.ReleaseComObject(R1) System.Runtime.InteropServices.Marshal.ReleaseComObject(R2) System.Runtime.InteropServices.Marshal.ReleaseComObject(RCopy) System.Runtime.InteropServices.Marshal.ReleaseComObject(RPaste) System.Runtime.InteropServices.Marshal.ReleaseComObject (objCells) 'Cells の開放 xlApp.Visible = True System.Runtime.InteropServices.Marshal.ReleaseComObject (xlsSheet) 'xlSheet の開放 System.Runtime.InteropServices.Marshal.ReleaseComObject (xlsSheets) 'xlSheets の開放 System.Runtime.InteropServices.Marshal.ReleaseComObject (xlsBook) 'xlBook の開放 System.Runtime.InteropServices.Marshal.ReleaseComObject (xlsBooks) 'xlBooks の開放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) 'xlApp を開放 End Sub |