Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.string;
- import std.file;
- int main(){
- char[] inputFile;
- char[] outputFile;
- write("CSV file > ");
- readln(inputFile);
- string csv = readText(chomp(inputFile));
- string[] rows = csv.split("\n");
- 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>";
- foreach(int i, string row; rows){
- string[] values = row.split(",");
- output ~= "<tr>";
- foreach(int j, string value; values){
- if(cmp(value, "0") == 0){
- //plains #148743
- output ~= "<td class='plains'></td>";
- } else if (cmp(value, "1") == 0){
- //water #0060C0
- output ~= "<td class='water'></td>";
- } else if (cmp(value, "2") == 0){
- //forest #007D00
- output ~= "<td class='forest'></td>";
- } else {
- //none #ffffff
- output ~= "<td class='none'></td>";
- }
- }
- output ~= "</tr>";
- }
- output ~= "</table></body>";
- write("Output file > ");
- readln(outputFile);
- std.file.write(chomp(outputFile), output);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement