掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
EXCELの落しこみに関して (ID:10328)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
いろんな方法がありますが、 例えば var shokei,gokei:array[1..2] of Integer; //小計と合計 aRow:Integer; //行位置 bunrui:String; ・・・・・・・・・・・・・・・・・・・・・・・・・・・ //追加 gokei[1] := 0; gokei[2] := 0; aRow := 5; bunrui := ''; //ここまで FOR i := 1 TO Query1.RecordCount DO //RecordCountは保証されていないRDBMSもあるので //while Not Query1.Eofの方がお勧め begin //追加 if (bunrui<>Query1.Fields[0].AsString) then begin if bunrui <> '' then begin Cells.Item[aRow,1].Value:='小計'; Cells.Item[aRow,3].Value:=IntToStr(shokei[1]); Cells.Item[aRow,4].Value:=IntToStr(shokei[2]); Inc(aRow,2); end; bunrui := Query1.Fields[0].AsString; shokei[1] := 0; shokei[2] := 0; end else FOR j := 1 to Query1.Fields.Count DO begin Cells.Item[aRow,j].Value:=Query1.Fields[j-1].AsString; end; shokei[1] := shokei[1] + Query1.Fields[2].AsInteger; //AsIntegerはfieldの属性で変更して下さい。 shokei[2] := shokei[2] + Query1.Fields[3].AsInteger; gokei[1] := gokei[1] + Query1.Fields[2].AsInteger; gokei[2] := gokei[2] + Query1.Fields[3].AsInteger; Query1.Next; Inc(aRow); end; if (shokei[1] > 0) or (shokei[2] > 0) then begin Cells.Item[aRow,1].Value:='小計'; Cells.Item[aRow,3].Value:=IntToStr(shokei[1]); Cells.Item[aRow,4].Value:=IntToStr(shokei[2]); Inc(aRow,2); end; Cells.Item[aRow,1].Value:='合計'; Cells.Item[aRow,3].Value:=IntToStr(gokei[1]); Cells.Item[aRow,4].Value:=IntToStr(gokei[2]); 他にもSQLで小計・合計をすませておき、 プログラムでは取り出しだけということも出来ます。
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.