掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
AndroidでデータFileをstringgridに表示 (ID:148372)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
> Android.Content.contextにOpenFileOutput&Inputがあるそうですが それによる方法は知りませんが、出来たとしてもAndroidのみでの動作となってしまうので、 TStringListによる通常の読み込みではどうですか? function TForm1.LoadCsvFileGrid( const ASG : TStringGrid; const AFilePath : String ) : Boolean; var SL : TStringList; SS : TStringList; Row, Col : Integer; lc1 : Integer; begin if Not FileExists( AFilePath ) then Exit( FALSE ); SL := TStringList.Create; SS := TStringList.Create; try SL.LoadFromFile( AFilePath ); if SL.Count = 0 then Exit( FALSE ); for Row := 0 to SL.Count - 1 do begin SS.Delimiter := ','; SS.QuoteChar := '"'; SS.CommaText := SL[ Row ]; if SS.Count <> 0 then begin ASG.RowCount := SL.Count; if ASG.ColumnCount < SS.Count then begin for lc1 := 0 to SS.Count - ASG.ColumnCount - 1 do begin ASG.AddObject( TStringColumn.Create( ASG ) ); end; end; for Col := 0 to SS.Count - 1 do begin ASG.Cells[ Col, Row ] := SS[ Col ]; end; end; end; finally SS.DisposeOf; SL.DisposeOf; end; Result := TRUE; end; function TForm1.SaveCsvFileGrid( const ASG : TStringGrid; const AFilePath : String ) : Boolean; var SL : TStringList; Data : TStringDynArray; Row, Col : Integer; begin if ( ASG.RowCount = 0 ) or ( ASG.ColumnCount = 0 ) then Exit( FALSE ); SL := TStringList.Create; try for Row := 0 to ASG.RowCount - 1 do begin SetLength( Data, ASG.ColumnCount ); for Col := 0 to ASG.ColumnCount - 1 do begin Data[ Col ] := ASG.Cells[ Col, Row ].QuotedString( '"' ); end; SL.Add( String.Join( ',', Data ) ); end; SL.SaveToFile( AFilePath, TEncoding.Unicode ); finally SL.DisposeOf; end; Result := TRUE; end; CSVデータに半角ダブルクオーテーションが含まれている場合、""という風になっていなければ正しく切り取れません。 そこら辺は工夫してみて下さい。 TStringGridのセル幅は、TStringColumn.Widthでコード内から変更できます。
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.