帳票 - 印刷
プレビュー画面を表示せずに印刷を実行したい
プレビュー画面を表示せずに印刷を実行する場合、PrintPreviewクラスの
printDialogDirectメソッドを利用します。
【記述例】
PrintPreview.printDialogDirect([PrintFormDocumentオブジェクト],[プリンタ名]);
他、印刷ページ数や印刷部数の指定も可能です。
PCに登録されているプリンタ一覧からプリンタを選択したい場合は、Applicationクラスの
getPrinterListメソッドで取得します。
[ 印刷実行画面 ]
Form form1 { height = 477; width = 547; Label label1 { x = 92; y = 30; width = 328; height = 27; value = "出力先プリンタをダブルクリックで選択してください。"; verticalAlign = ALIGN_MIDDLE; horizontalAlign = ALIGN_CENTER; } FlexView flexview1 { x = 86; y = 80; width = 358; height = 238; cursorLineColor = "#ffaaffff"; cursorColor = "#ffaaffff"; FlexRecord rec { FlexLabel flexlabel1 { title = "選択"; width = 100; horizontalAlign = ALIGN_CENTER; verticalAlign= ALIGN_CENTER; } FlexLabel flexlabel2{ title = "プリンタ名"; width = 250; } } function onDoubleClicked(e) { #1列目のデータクリア var row = getRow(); while( !row.end ) { row.flexlabel1.value = ""; row.MoveNext(); } #ダブルクリックされたセルに●をつける e.row.flexlabel1.value = "●"; } } Button buttonPrintDialogDirect { x = 88; y = 341; width = 356; height = 77; title = "選択されたプリンタへ印刷"; function onTouch(e) { #印刷する帳票のレイアウトを取得 ^.get("Printform1.crs"); #プリンタ名 var printerName = ""; #選択されたプリンタ名を取得 var row = ^.flexview1.getRow(); while( !row.end ) { if(row.flexlabel1.value == "●"){ printerName = row.flexlabel2.value; break; } row.MoveNext(); } #プレビューせずに印刷 PrintPreview.printDialogDirect(^.printform1.printDocument(), printerName); } } if (!Application.DESIGNTIME) { #PC内のプリンタ一覧取得 var pritList = Application.getPrinterList(); #一覧をCsvDocumentに格納しさらにFlexViewへ表示 var printl_doc = new CsvDocument(); printl_doc << pritList; #データの置き換え printl_doc.replace(0,0,"●","0==1"); printl_doc.replace(0,0,"","0==0"); #一覧をFlexViewへ表示 flexview1 << printl_doc; } }
[ 帳票レイアウト ]
PrintForm printform1 { width = 800; height = 1043; visible = false; var h_bg= new Color(0xffc0c0c0); var h_fk = new Font("MS UI Gothic", 20, true, false, false, false); TextField textfield1 { x = 79; y = 31; width = 648; height = 64; value = "出席者名簿"; border = BORDER_PLANE; horizontalAlign = ALIGN_CENTER; verticalAlign = ALIGN_MIDDLE; font = new Font("MS UI Gothic", 22, true, false, false, false); } PrintRegion printregion1 { x = 79; y = 127; width = 648; height = 886; border = BORDER_PLANE; PrintHeader printheader1 { width = 648; height = 48; bgColor = h_bg; HeaderField headerfield1 { width = 174; height = 48; title = "氏名"; verticalAlign = ALIGN_MIDDLE; horizontalAlign = ALIGN_CENTER; font = h_fk; } HeaderField headerfield2 { x = 130; y = 0; width = 68; height = 48; title = "年齢"; verticalAlign = ALIGN_MIDDLE; horizontalAlign = ALIGN_CENTER; font = h_fk; } HeaderField headerfield3 { x = 245; y = 0; width = 241; height = 48; title = "住所"; verticalAlign = ALIGN_MIDDLE; horizontalAlign = ALIGN_CENTER; font = h_fk; } HeaderField headerfield4 { x = 337; y = 0; width = 158; height = 48; title = "電話番号"; verticalAlign = ALIGN_MIDDLE; horizontalAlign = ALIGN_CENTER; font = h_fk; } } PrintRecord printrecord1[]{ x = 16; y = 72; width = 631; height = 48; TextField textfield1 { verticalAlign = ALIGN_MIDDLE; font = h_fk; } TextField textfield2 { verticalAlign = ALIGN_MIDDLE; font = h_fk; horizontalAlign = ALIGN_CENTER; } TextField textfield3 { verticalAlign = ALIGN_MIDDLE; font = h_fk; } TextField textfield4 { verticalAlign = ALIGN_MIDDLE; font = h_fk; } } } if (!Application.DESIGNTIME) { # ここに初期化処理を記述してください。 printform1.printregion1.printrecord1 << csv(氏名,年齢,住所,電話番号) { 伊藤博文,44,山口県○○○,xxx-xx-xxx 黒田清隆,47,鹿児島県○○○,xxx-xx-xxx 山縣有朋,51,山口県○○○,xxx-xx-xxx 松方正義,56,鹿児島県○○○,xxx-xx-xxx 大隈重信,60,佐賀県○○○,xxx-xx-xxx 桂太郎,53,山口県○○○,xxx-xx-xxx 西園寺公望,56,京都府○○○,xxx-xx-xxx 山本權兵衞,60,鹿児島県○○○,xxx-xx-xxx 寺内正毅,64,山口県○○○,xxx-xx-xxx 原敬,62,岩手県○○○,1xxx-xx-xxx 高橋是清,67,東京都〇〇〇,xxx-xx-xxx 加藤友三郎,61,広島県〇〇〇,xxx-xx-xxx 清浦奎吾,73,熊本県〇〇〇,xxx-xx-xxx 加藤高明,64,愛知県〇〇〇,xxx-xx-xxx 若槻禮次郎,59,島根県〇〇〇,xxx-xx-xxx 田中義一,63,山口県〇〇〇,xxx-xx-xxx 濱口雄幸,59,高知県〇〇〇,xxx-xx-xxx 犬養毅,76,岡山県〇〇〇,xxx-xx-xxx 齋藤實,73,岩手県〇〇〇,xxx-xx-xxx 岡田啓介,66,福井県〇〇〇,xxx-xx-xxx }; } }
Biz-Collections Bizの宝箱 トップへ
Biz/Browser DT・Biz/Designer DT TIPS集 トップへ