====== CSV2Dokuwiki ====== I wrote a small Java-Programm, to convert Spreadsheet-Data into DokuWiki's table syntax. Feel free to leave a comment on my [[users:slartidan:discussion|discussion-page]]. Feel free to use and distribute - but of course I no warranty - if your PC breaks don't sue me. ===== Code ===== import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.regex.Pattern; /** * Converts CSV input (tab separated) into DokuWiki's table syntax * * Tip: mark your data in Spreadsheet-Program and copy-paste it into the console * * @author slartidan * */ public class TableConvert { private static final String PATTERN_START_QUOTATION = "(^|.*\t)\"((?:\"\"|[^\"])*)"; private static final String PATTERN_END_QUOTATION = "(^|.*\t)((?:\"\"|[^\"])*)\"(\t.*|$)"; private static final int MODE_STANDARD = 0; private static final int MODE_IN_QUOTATION = 1; public static void main(String[] args) throws IOException { System.out.println("CSV2DokuWiki - type your tab separated CSV here:"); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); Pattern startQuotation = Pattern.compile(PATTERN_START_QUOTATION); Pattern endOuotation = Pattern.compile(PATTERN_END_QUOTATION); int mode = MODE_STANDARD; String line; StringBuffer output = new StringBuffer(); while ((line = reader.readLine()) != null) { if ("".equals(line)) break; // empty line signalizes end of input if (mode == MODE_IN_QUOTATION) { // closing Quotation? if (endOuotation.matcher(line).matches()) { mode = MODE_STANDARD; line = line.replaceAll(PATTERN_END_QUOTATION, "1ドル2ドル3ドル"); } } else { // lines (not in quotation) start with " | " line = "\t"+line; } // starting Quotation? if (startQuotation.matcher(line).matches()) { mode = MODE_IN_QUOTATION; line = line.replaceAll(PATTERN_START_QUOTATION, "1ドル2ドル"); } // remove unnessesary quotation marks String old = new String(); while (!old.equals(line)) { old = line; line = line.replaceAll("(^|\t)\"((?:\"\"|[^\"])*)\"(\t|$)", "1ドル2ドル3ドル"); } // normalize escaped quotation marks line = line.replaceAll("\"\"", "\""); // pipes instead of tabs line = line.replaceAll("\\t", " | "); // breaks in Quotations become \\ if (mode == MODE_IN_QUOTATION) { line += "\\\\ "; } else { line += " |\n"; } // save line line = line.replaceAll("^ ", ""); output.append(line); } // print output System.out.println(output); } } ===== Tip ===== To paste the copied table from your spreadsheet program into the Windows Prompt-Window (''cmd.exe'') and to mark and copy it from there use the system menu (ALT-SPACE -> EDIT). ===== Download Binaries ===== All binaries were compiled with Java 1.6. You should have [[http://www.java.com|Java]] 1.6 JRE (runtime environment) or higher installed on your system. * [[http://home.arcor.de/hibr/cvs2dw/cvs2dw.jar|cvs2dw.jar]] (all Java platforms) * [[http://home.arcor.de/hibr/cvs2dw/cvs2dw.exe|cvs2dw.exe]] (Microsoft Windows)

AltStyle によって変換されたページ (->オリジナル) /