Пример #1
0
        public static string ToString(Table table, TableContainType tableContainType)
        {
            java.io.StringWriter stringWriter = new java.io.StringWriter();
            try
            {
                technology.tabula.writers.Writer writer = null;
                switch (tableContainType)
                {
                case TableContainType.CSV:
                    writer = new CSVWriter();
                    break;

                case TableContainType.Json:
                    writer = new JSONWriter();
                    break;

                case TableContainType.TSV:
                    writer = new TSVWriter();
                    break;

                default:
                    writer = new JSONWriter();
                    break;
                }

                writer.write(stringWriter, table);
            }
            catch
            {
                return(string.Empty);
            }
            return(stringWriter.toString());
        }
Пример #2
0
        public static bool ToFile(string filePath, Table table, TableContainType tableContainType)
        {
            FileInfo _csvfilesave = new FileInfo(filePath);

            if (!Directory.Exists(_csvfilesave.DirectoryName))
            {
                Directory.CreateDirectory(_csvfilesave.DirectoryName);
            }

            java.io.File outputFile = new java.io.File(filePath);

            BufferedWriter bufferedWriter = null;

            try
            {
                var fileWriter = new OutputStreamWriter(new FileOutputStream(outputFile.getAbsoluteFile()), "UTF-8");
                bufferedWriter = new BufferedWriter(fileWriter);

                outputFile.createNewFile();

                technology.tabula.writers.Writer writer = null;
                switch (tableContainType)
                {
                case TableContainType.CSV:
                    writer = new CSVWriter();
                    break;

                case TableContainType.Json:
                    writer = new JSONWriter();
                    break;

                case TableContainType.TSV:
                    writer = new TSVWriter();
                    break;

                default:
                    writer = new JSONWriter();
                    break;
                }

                writer.write(bufferedWriter, table);
            }
            catch
            {
                return(false);
            }
            return(true);
        }