AutoHotkey Community

It is currently May 26th, 2012, 5:03 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: February 21st, 2009, 11:59 am 
Offline

Joined: December 8th, 2006, 5:17 am
Posts: 248
Location: Sydney Australia
Hi all

Just thought I would share some code. It converts a CSV file into individual pages for printing. Might not be as elegant as it should be / could be but it does the job for me and may help others.

Improvements welcome.


Code:
inputfile = Document3.txt
Bank = CBA
filedelete %bank%*.html
;MSGBOX files should be deleted

; below is the number of items to a page
F9itemsPerPage = 30         ; this is the MOD
column1 = <th align="left">No.</th>
column2 = <th align="left">Client</th>
column3 = <th align="left">DRN</th>
column4 = <th align="left">TRAY-POCKET-POSITION</th>
column5 = <th align="left">ITEM AMT</th>
column6 = <th align="left">TRC</th>
column7 = <th align="left">ACCT</th>
column8 = <th align="left">BSB</th>
column9 = <th align="left">SER</th>
column10 = <th align="left">EAD</th>
column11 = <th align="left">Reason</th>
column12 = <th align="left">Who</th>
report_time = %A_Now%
starttime = %A_Now%


Loop Read, %inputfile%
{
   ; workout the number of columns to span for the footer messages
   If A_Index = 1
   {
   ; read the file and get first line
   ; work out the number of fields in 1st line
   StringSplit, firstlinefields, A_LoopReadLine , `,
   
   ; the column span should be the number of fields in the csv plus the index
   columnspan := firstlinefields0 + 1
   }
   
   ; change the variable F9itemsPerPage to suit. Below breaks the original file into files of that variable.
   If (Mod(A_Index - 1, F9itemsPerPage) = 0)
      {
      filename++                     ; increment the file number in this loop
      fileOut = %Bank%_%report_time%_%filename%.html

; add the html header and opening table tables
FileAppend,
(
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>%site_name% AHK SSP Items for %processingdate%</title>
<style type="text/css">
<!--
table.ahkstyle th, table.ahkstyle td `{
  font-size : 75`%;
  font-family : Arial, Helvetica, sans-serif;
  vertical-align: top;
  `}
  .footer `{font-size: xx-small`}
-->
</style>
</head>
<body bgcolor="white" text="black" link="black" vlink="black" alink="red">
<div align="center"><h4><br>AHK Suspense Pool Items Report for %Bank% <br>Processing Date %processingdate% for %site_name%<br>Page # %filename%</h4></div>
<table width="90`%" border="1" align="center" cellspacing="1" cellpadding="1" class ="ahkstyle">
<tr bgcolor="#B2AD96">%column1%%column2%%column3%%column4%%column5%%column6%%column7%%column8%%column9%%column10%%column11%%column12%</tr>
),%fileOut%   

; add the rows to the table
      }
      FileAppend, % "<tr>`n<td><div align=left>" . A_Index . "</td>`n" , %fileOut%               ; open the TR & TD tags, append the loop number as record number on report
            Loop, Parse, A_LoopReadLine, CSV
            {
               If A_LoopField =               ; if the field is empty, insert a non breaking space ie &nbsp; so the empty Table data cell prints correctly
                  FileAppend, % "<td>" . "&nbsp;" . "</td>`n",%fileout%
               Else
                  {
                  if A_LoopField is number      ; right align NUMBER fields. Left align TEXT fields
                     FileAppend, % "<td><div align=right>" . A_LoopField . "</td>`n",%fileout%            ; close TD tag and start new TD
                  Else
                     FileAppend, % "<td><div align=left>" . A_LoopField . "</td>`n",%fileout%            ; close TD tag and start new TD
                  }
            }
         FileAppend, </tr>`n,%fileout%            ; close TR tag and start new line
         num_items=%A_Index%                     ; keep a count of number of items in a variable called num_items
      }

; now add the action messages at footer of page.
Loop %filename%
{
FileAppend,
(
<tr><td colspan="%columnspan%">
<strong>Day1 Staff - PLEASE NOTE: - YOUR MESSAGE HERE:</strong>
<br>(1) YOUR MESSAGE HERE.
<br>(2) YOUR MESSAGE HERE.
</td></tr>
<tr><td colspan="%columnspan%">YOUR MESSAGE HERE:</td></tr>
<tr><td colspan="%columnspan%">Number of AHK SSP items is : <strong>%num_items%</strong>.</td></tr>
), %Bank%_%report_time%_%A_Index%.html

; now close the table, body & html tags
FileAppend,
(
</table>
<div align="center"><span class="footer">Report Created at %report_time%</span></div>
</body>
</html>
), %Bank%_%report_time%_%A_Index%.html
}
endtime = %A_Now%
elapsedtime := endtime - starttime
Msgbox DONE`n%num_items% items in %filename% files processed in %elapsedtime% seconds`nEnd time was %endtime%`nStart time was %starttime%

_________________
Paul O


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2009, 9:22 am 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
very interesting, good example
I like also to make an output with ahk, calculation (column-size predefined), to have number at right margin with script non proportional ( Fixedsys)
Code:
127.00
  4.25


EDIT:
I've seen it's in your script already :)
Code:
                  if A_LoopField is number      ; right align NUMBER fields. Left align TEXT fields
                     FileAppend, % "<td><div align=right>" . A_LoopField . "</td>`n",%fileout%            ; close TD tag and start new TD
                  Else
                     FileAppend, % "<td><div align=left>" . A_LoopField . "</td>`n",%fileout%            ; close TD tag and start new TD




http://www.autohotkey.com/forum/topic14 ... t=rghdruck
I use this "dinosaurier" rghdruck.exe which allows also preview and
-add transparent picture and write on it
-write vertical
-draw rectangle and fill out

seems very easy
Code:
  Fileappend,$ANSI`r`n,%F1%
  Fileappend,$DO USEFONT %AFONT%`,14`,9`r`n,%F1%                        ;font height width
  Fileappend,~>006~`r`n,%F1%                                            ;left margin
  Fileappend,~%DistanceBetweenLines%~`r`n,%F1%                          ;distance between lines
  Fileappend,~S~~1~          http://www.profan.de  RGHDRUCK   ~D.xx.xxx~ - ~Z:xx~       - ~#~ -`r`n,%F1%  ;date
  Fileappend,$DO RECTANGLE 100`,30`,607`,435`r`n,%F1%                   ;rectangle xyL  xyR
  Fileappend,$DO LOADSIZEDBMP %picturex1%`, 170`,80`,270`,250`r`n,%F1%  ;add picture
  ;----------  vertikal ------------
  Fileappend,~L~`r`n,%F1%                                           ;Vertikal
  Fileappend,$DO MOVETO 0`,80`r`n,%F1%                              ;move X Y
  Fileappend,~*commentA41~`r`n,%F1%                                 ;comment
  Fileappend,~F~%A41%~f~`r`n,%F1%                                   ;write vertical bold     
  Fileappend,~P~`r`n,%F1%                                           ;Horizontal normal
  Fileappend,$DO USEBRUSH 5`,2`r`n,%F1%                              ;fill diagonal green
  Fileappend,$DO RECTANGLE 40`,250`,400`,400`r`n,%F1%                ;rectangle
  Fileappend,$DO USEPEN 2`,1`,4`r`n,%F1%                             ;lineart thick color
  Fileappend,$DO LINE 40`,410`,400`,410`r`n,%F1%                     ;LINE from to




I should use html , never learned, maybe should learn here (I'm beginning with your example)
http://de.selfhtml.org/css/eigenschaften/schrift.htm


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group