掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
DataGridView をエクセルに出力 (ID:147613)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
VB2010で DataGridView のデータの必要な列のデータのみ、エクセルの所定のセルへ出力したいと考えているのです。またExcelのバージョンが 社内に2000、2003、2007と3種類存在しています。 現在以下のような構文でexcelに出力はできたのですが、Excelを閉じたあと、普通にエクスプローラなどから開こうとしたら開けません。 何が原因なのでしょうか? また今回Excel2000で試しているのでが、2003や2007の場合もこの方法でできますか? 'エクセル表示 Dim xlApp As Excel.Application = Nothing Dim xlBook As Excel.Workbook = Nothing Dim xlSheet As Excel.Worksheet = Nothing Dim xlChart As Excel.Chart = Nothing Try xlApp = CType(CreateObject ("Excel.Application"),Excel.Application) xlApp.Workbooks.Add() xlBook = xlApp.Workbooks(1) xlSheet = xlBook.Worksheets(1) xlSheet.Range("A1").Value = "出力データ1" xlSheet.Range("B1").Value = "出力データ2" xlSheet.SaveAs("D:\Test.xls") '名前をつけて保存 'Excelの表示 xlApp.Visible = True ' オブジェクトを解放します。 xlSheet = Nothing xlBook = Nothing xlApp = Nothing Catch ex As Exception If Not IsNothing(xlBook) Then xlBook.Close() If Not IsNothing(xlApp) Then xlApp.Quit() End Try
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.