掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
csvファイルに罫線を引きたいのですが・・・ (ID:4214)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
バージョンがかかれていないので、Delphi7Pro+Office2000の環境での実現方法です。 procedure PasteStringsToExcel(Sheet: TExcelWorksheet; Row, Col: Integer; StringList: TStringList); var CellList: TStringList; strarr: array of array of String; RowCount, ColCount: integer; R,C: integer; begin CellList := TStringList.Create; CellList.CommaText := StringList[0]; RowCount := StringList.Count; ColCount := CellList.Count; SetLength(strarr, RowCount, ColCount); for R := 0 to RowCount - 1 do begin CellList.CommaText := StringList[R]; for C := 0 to ColCOunt - 1 do begin if C < CellList.Count then strarr[R,C] := CellList[C] else strarr[R,C] := ''; end; end; CellList.Free; Sheet.Range[Sheet.Cells.Item[Row, Col], Sheet.Cells.Item[Row + RowCount - 1, Col + ColCount - 1]].Value := strarr; SetLength(strarr, 0, 0); end; このような関数を用意して、次のように呼べばできます。 procedure TForm1.Button1Click(Sender: TObject); var StringList: TStringList; begin StringList := TStringList.Create; StringList.LoadFromFile(ExtractFilePath(Application.ExeName) + 'test.txt'); ExcelApplication1.Connect; ExcelApplication1.Visible[0] := True; ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(Null, 0)); ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets['Sheet1'] as _Worksheet); ExcelWorksheet1.Activate; PasteStringsToExcel(ExcelWorksheet1, 2, 1, StringLIst); end; QueryTables.Addを使ってみたのですが、うまくいきませんでした。 Macroを呼ぶ方が簡単かもしれません。 # 未確認です
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.