Advertisement
Guest User

Untitled

a guest
Nov 15th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.19 KB | None | 0 0
  1. import std.stdio;
  2. import std.string;
  3. import std.file;
  4.  
  5. int main(){
  6.     char[] inputFile;
  7.     char[] outputFile;
  8.     write("CSV file > ");
  9.     readln(inputFile);
  10.     string csv = readText(chomp(inputFile));
  11.     string[] rows = csv.split("\n");
  12.     string output = "<head><style>table, tr, td{border: none;border-collapse: collapse;} td{padding:30px;} .none{background-color:#e5e5e5;} .forest{background-color:#007D00;} .plains{background-color:#148743;} .water{background-color:#0060C0;}</style></head><body style='padding:0;margin:0'><table>";
  13.     foreach(int i, string row; rows){
  14.         string[] values = row.split(",");
  15.         output ~= "<tr>";
  16.         foreach(int j, string value; values){
  17.             if(cmp(value, "0") == 0){
  18.                 //plains #148743
  19.                 output ~= "<td class='plains'></td>";
  20.             } else if (cmp(value, "1") == 0){
  21.                 //water #0060C0
  22.                 output ~= "<td class='water'></td>";
  23.             } else if (cmp(value, "2") == 0){
  24.                 //forest #007D00
  25.                 output ~= "<td class='forest'></td>";
  26.             } else {
  27.                 //none #ffffff
  28.                 output ~= "<td class='none'></td>";
  29.             }
  30.         }
  31.         output ~= "</tr>";
  32.     }
  33.     output ~= "</table></body>";
  34.     write("Output file > ");
  35.     readln(outputFile);
  36.     std.file.write(chomp(outputFile), output);
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement