コード例 #1
0
        public static LiteDatabase CreateTestDatabase(string path)
        {
            if (File.Exists(TEST_DATABASE_FILE))
            {
                File.Delete(TEST_DATABASE_FILE);
            }

            if (File.Exists(TEST_DATABASE_LOG_FILE))
            {
                File.Delete(TEST_DATABASE_LOG_FILE);
            }

            var db = new LiteDatabase(TEST_DATABASE_FILE);

            var workbookParser = new WorkbookParser(db);
            var listFiles      = Directory.GetFiles(path, "*.xls");

            foreach (var listFile in listFiles)
            {
                workbookParser.ParseTo(listFile, db);
            }

            var dbProducer = new ApplicantsDatabaseProducer();

            dbProducer.WriteDbInfo(db);

            return(db);
        }
コード例 #2
0
        /**
         * Constructor
         *
         * @param w The workbook to interrogate
         * @param out The output stream to which the CSV values are written
         * @param encoding The encoding used by the output stream.  Null or
         * unrecognized values cause the encoding to default to UTF8
         * @exception java.io.IOException
         */
        public EscherDrawingGroup(Workbook w, TextWriter os, string encoding)
        {
            if (encoding == null || encoding != "UnicodeBig")
            {
                encoding = "UTF8";
            }

            try
            {
                WorkbookParser wp = (WorkbookParser)w;

                DrawingGroup dg = wp.getDrawingGroup();

                if (dg != null)
                {
                    EscherDisplay ed = new EscherDisplay(dg, os);
                    ed.display();
                }

                os.WriteLine();
                os.WriteLine();
                os.Flush();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #3
0
        /**
         * A factory method which takes input an excel file and reads input the contents.
         *
         * @exception IOException
         * @exception BiffException
         * @param file the excel 97 spreadsheet to parse
         * @param ws the settings for the workbook
         * @return a workbook instance
         */
        public static Workbook getWorkbook(FileInfo file, WorkbookSettings ws)
        {
            Stream fis = new FileStream(file.FullName, FileMode.Open);

            // Always close down the input stream, regardless of whether or not the
            // file can be parsed.  Thanks to Steve Hahn for this
            CSharpJExcel.Jxl.Read.Biff.File dataFile = null;

            try
            {
                dataFile = new CSharpJExcel.Jxl.Read.Biff.File(fis, ws);
            }
            catch (IOException e)
            {
                throw e;
            }
            catch (BiffException e)
            {
                throw e;
            }
            finally
            {
                fis.Close();
            }

            Workbook workbook = new WorkbookParser(dataFile, ws);

            workbook.parse();

            return(workbook);
        }
コード例 #4
0
        /// <summary> A factory method which takes in an excel file and reads in the contents.
        ///
        /// </summary>
        /// <exception cref=""> IOException
        /// </exception>
        /// <exception cref=""> BiffException
        /// </exception>
        /// <param name="filename">the excel 97 spreadsheet to parse
        /// </param>
        /// <param name="ws">the settings for the workbook
        /// </param>
        /// <returns> a workbook instance
        /// </returns>
        public static Workbook getWorkbook(string filename, WorkbookSettings ws)
        {
            FileStream fis = new FileStream(filename, FileMode.Open, FileAccess.Read);

            // Always close down the input stream, regardless of whether or not the
            // file can be parsed.  Thanks to Steve Hahn for this
            NExcel.Read.Biff.File dataFile = null;

            try
            {
                dataFile = new NExcel.Read.Biff.File(fis, ws);
            }
            catch (Exception e)
            {
                fis.Close();
                throw e;
            }

            fis.Close();

            Workbook workbook = new WorkbookParser(dataFile, ws);

            workbook.parse();

            return(workbook);
        }
コード例 #5
0
        /**
         * A factory method which takes input an excel file and reads input the contents.
         *
         * @param inStream an open stream which inStream the the excel 97 spreadsheet to parse
         * @param ws the settings for the workbook
         * @return a workbook instance
         * @exception IOException
         * @exception BiffException
         */
        public static Workbook getWorkbook(Stream inStream, WorkbookSettings ws)
        {
            CSharpJExcel.Jxl.Read.Biff.File dataFile = new CSharpJExcel.Jxl.Read.Biff.File(inStream, ws);

            Workbook workbook = new WorkbookParser(dataFile, ws);

            workbook.parse();

            return(workbook);
        }
コード例 #6
0
        /// <summary> A factory method which takes in an excel file and reads in the contents.
        ///
        /// </summary>
        /// <exception cref=""> IOException
        /// </exception>
        /// <exception cref=""> BiffException
        /// </exception>
        /// <param name="is">an open stream which is the the excel 97 spreadsheet to parse
        /// </param>
        /// <param name="ws">the settings for the workbook
        /// </param>
        /// <returns> a workbook instance
        /// </returns>
        public static Workbook getWorkbook(Stream stream, WorkbookSettings ws)
        {
            NExcel.Read.Biff.File dataFile = new NExcel.Read.Biff.File(stream, ws);

            Workbook workbook = new WorkbookParser(dataFile, ws);

            workbook.parse();

            return(workbook);
        }
コード例 #7
0
        /**
         * Imports any names defined on the source sheet to the destination workbook
         */
        private void importNames()
        {
            WorkbookParser   fromWorkbook = (WorkbookParser)fromSheet.getWorkbook();
            WritableWorkbook toWorkbook   = toSheet.getWorkbook();
            int fromSheetIndex            = fromWorkbook.getIndex(fromSheet);

            CSharpJExcel.Jxl.Read.Biff.NameRecord[] nameRecords = fromWorkbook.getNameRecords();
            string[] names = toWorkbook.getRangeNames();

            for (int i = 0; i < nameRecords.Length; i++)
            {
                CSharpJExcel.Jxl.Read.Biff.NameRecord.NameRange[] nameRanges = nameRecords[i].getRanges();

                for (int j = 0; j < nameRanges.Length; j++)
                {
                    int nameSheetIndex = fromWorkbook.getExternalSheetIndex(nameRanges[j].getExternalSheet());

                    if (fromSheetIndex == nameSheetIndex)
                    {
                        string name = nameRecords[i].getName();
                        if (System.Array.BinarySearch(names, name) < 0)
                        {
                            toWorkbook.addNameArea(name,
                                                   toSheet,
                                                   nameRanges[j].getFirstColumn(),
                                                   nameRanges[j].getFirstRow(),
                                                   nameRanges[j].getLastColumn(),
                                                   nameRanges[j].getLastRow());
                        }
                        else
                        {
                            //logger.warn("Named range " + name + " is already present in the destination workbook");
                        }
                    }
                }
            }
        }