public void ColumnDetectorTest1TIAdapter()
        {
            string xlsxFile = Path.Combine(TestUtil.GetTestDataPath(), "fsin_2016_extract.xlsx");

            //IAdapter adapter = NpoiExcelAdapter.CreateAdapter(xlsxFile);
            // aspose do not want to read column widthes from this file, use aspose
            // fix it in the future (is it a bug in Npoi library?).

            IAdapter adapter = AsposeExcelAdapter.CreateAdapter(xlsxFile);

            ColumnOrdering ordering = ColumnDetector.ExamineTableBeginning(adapter);

            Assert.AreEqual(ordering.ColumnOrder.Count, 12);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.NameOrRelativeType].BeginColumn == 0);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.Occupation].BeginColumn == 1);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateType].BeginColumn == 2);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateOwnershipType].BeginColumn == 3);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateSquare].BeginColumn == 4);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateCountry].BeginColumn == 5);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.StatePropertyType].BeginColumn == 6);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.StatePropertySquare].BeginColumn == 7);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.StatePropertyCountry].BeginColumn == 8);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.Vehicle].BeginColumn == 9);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.DeclaredYearlyIncome].BeginColumn == 10);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.DataSources].BeginColumn == 11);
        }
Ejemplo n.º 2
0
        static IAdapter GetAdapter(string inputFile)
        {
            string extension = Path.GetExtension(inputFile).ToLower();

            switch (extension)
            {
            case ".htm":
            case ".html":
                if (HtmAdapter.CanProcess(inputFile))
                {
                    return(new HtmAdapter(inputFile));
                }
                else
                {
                    return(new AngleHtmlAdapter(inputFile, MaxRowsToProcess));
                }

            case ".pdf":
            case ".xhtml":
            case ".doc":
            case ".rtf":
            case ".toloka_json":
            case ".docx":
                return(GetCommonAdapter(inputFile));

            case ".xls":
            case ".xlsx":
                if (AdapterFamily == "aspose" || AdapterFamily == "prod")
                {
                    if (!AsposeLicense.Licensed && extension == ".xls")
                    {
                        throw new Exception("xls file format is not supported");
                    }

                    if (AsposeLicense.Licensed)
                    {
                        return(AsposeExcelAdapter.CreateAdapter(inputFile, MaxRowsToProcess));
                    }
                }
                else if (AdapterFamily == "npoi")
                {
                    return(NpoiExcelAdapter.CreateAdapter(inputFile, MaxRowsToProcess));
                }
                else
                {
                    return(null);
                }

                break;

            default:
                Logger.Error("Unknown file extension " + extension);
                return(null);
            }

            Logger.Error("Cannot find adapter for " + inputFile);
            return(null);
        }
        public void TwoRowHeaderEmptyTopCellTest2()
        {
            string   xlsxFile = Path.Combine(TestUtil.GetTestDataPath(), "customs-tworow-header.xls");
            IAdapter adapter  = AsposeExcelAdapter.CreateAdapter(xlsxFile);

            ColumnPredictor.InitializeIfNotAlready();
            ColumnOrdering ordering = ColumnDetector.ExamineTableBeginning(adapter);

            Assert.AreEqual(ordering.ColumnOrder.Count, 14);
            Assert.AreEqual(ordering.ColumnOrder[DeclarationField.Occupation].BeginColumn, 2);
        }
Ejemplo n.º 4
0
        public void XlsxTypeCTest()
        {
            string   xlsxFile       = Path.Combine(TestUtil.GetTestDataPath(), "c_sample.xlsx");
            IAdapter adapter        = AsposeExcelAdapter.CreateAdapter(xlsxFile);
            var      columnOrdering = ColumnDetector.ExamineTableBeginning(adapter);

            Smart.Parser.Lib.Parser parser      = new Smart.Parser.Lib.Parser(adapter);
            Declaration             declaration = parser.Parse(columnOrdering, false, null);
            string comments = "";
            string output   = DeclarationSerializer.Serialize(declaration, ref comments);
        }
        public void FixVehicleColumns()
        {
            string   xlsxFile = Path.Combine(TestUtil.GetTestDataPath(), "17497.xls");
            IAdapter adapter  = AsposeExcelAdapter.CreateAdapter(xlsxFile, -1);

            ColumnPredictor.InitializeIfNotAlready();

            ColumnOrdering ordering = ColumnDetector.ExamineTableBeginning(adapter);

            Assert.AreEqual(15, ordering.ColumnOrder.Count);
            Assert.IsTrue(ordering.ContainsField(DeclarationField.VehicleType));
            Assert.IsTrue(ordering.ContainsField(DeclarationField.VehicleModel));
            Assert.IsFalse(ordering.ContainsField(DeclarationField.Vehicle));
        }
        public void ColumnDetectorTest1()
        {
            string   xlsxFile = Path.Combine(TestUtil.GetTestDataPath(), "fsin_2016_extract.xlsx");
            IAdapter adapter  = AsposeExcelAdapter.CreateAdapter(xlsxFile);

            ColumnOrdering ordering = ColumnDetector.ExamineTableBeginning(adapter);

            Assert.AreEqual(ordering.ColumnOrder.Count, 12);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.NameOrRelativeType].BeginColumn == 0);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.Occupation].BeginColumn == 1);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateType].BeginColumn == 2);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateOwnershipType].BeginColumn == 3);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateSquare].BeginColumn == 4);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateCountry].BeginColumn == 5);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.StatePropertyType].BeginColumn == 6);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.StatePropertySquare].BeginColumn == 7);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.StatePropertyCountry].BeginColumn == 8);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.Vehicle].BeginColumn == 9);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.DeclaredYearlyIncome].BeginColumn == 10);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.DataSources].BeginColumn == 11);
        }
        public void EmptyRealStateTypeColumnDetectorTest1()
        {
            string   xlsxFile = Path.Combine(TestUtil.GetTestDataPath(), "rabotniki_podved_organizacii_2013.xlsx");
            IAdapter adapter  = AsposeExcelAdapter.CreateAdapter(xlsxFile);

            ColumnPredictor.InitializeIfNotAlready();
            ColumnOrdering ordering = ColumnDetector.ExamineTableBeginning(adapter);

            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.Number].BeginColumn == 0);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.NameOrRelativeType].BeginColumn == 1);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.Occupation].BeginColumn == 2);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateType].BeginColumn == 3);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateOwnershipType].BeginColumn == 4);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateSquare].BeginColumn == 5);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.OwnedRealEstateCountry].BeginColumn == 6);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.StatePropertyType].BeginColumn == 7);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.StatePropertySquare].BeginColumn == 8);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.StatePropertyCountry].BeginColumn == 9);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.Vehicle].BeginColumn == 10);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.DeclaredYearlyIncome].BeginColumn == 11);
            Assert.IsTrue(ordering.ColumnOrder[DeclarationField.DataSources].BeginColumn == 12);
        }
Ejemplo n.º 8
0
 public void XlsxTypeCTest()
 {
     string   xlsxFile = Path.Combine(TestUtil.GetTestDataPath(), "fsin_2016_extract.xlsx");
     IAdapter adapter  = AsposeExcelAdapter.CreateAdapter(xlsxFile);
 }