Esempio n. 1
0
        private void loadinfo()
        {
            int            i              = 0;
            clsExcelReader er             = new clsExcelReader();
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";//初始路径
            openFileDialog.Filter           = "文本文件|*.*|C#文件|*.cs|所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex      = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                er.FileName = openFileDialog.FileName;
            }
            er.SheetNumber = 1;

            if (er.OpenFileContinuously() == false)
            {
                label1.Text = er.ErrorString;
                return;
            }
            int iCount = er.RowCount;

            for (i = 0; i < iCount - 2; i++)
            {
                pork Pork = new pork();
                Pork.name = er.getTextInOneCell(i + 3, 20);
                string priceA = er.getTextInOneCell(i + 3, 7);
                if (priceA.IndexOf('-') == -1)
                {
                    Pork.price = Convert.ToDouble(er.getTextInOneCell(i + 3, 7));
                }

                else

                {
                    Pork.price = Convert.ToDouble(priceA.Substring(0, priceA.IndexOf('-')));
                }

                Pork.date = er.getTextInOneCell(i + 3, 18).Substring(0, 9);
                porklist.Add(Pork);
            }
            label1.Text = porklist.Count.ToString();
        }
Esempio n. 2
0
        private void loadinfo()
        {
            int i = 0;
            clsExcelReader er = new clsExcelReader();
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = "c:\\";//初始路径
            openFileDialog.Filter = "文本文件|*.*|C#文件|*.cs|所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                er.FileName = openFileDialog.FileName;
            }
            er.SheetNumber = 1;

            if (er.OpenFileContinuously() == false)
            {
                label1.Text = er.ErrorString;
                return;
            }
            int iCount = er.RowCount;
            for (i = 0; i < iCount - 2; i++)
            {
                pork Pork = new pork();
                Pork.name = er.getTextInOneCell(i + 3, 20);
                string priceA = er.getTextInOneCell(i + 3, 7);
                if (priceA.IndexOf('-') == -1)
                { Pork.price = Convert.ToDouble(er.getTextInOneCell(i + 3, 7)); }

                else

                { Pork.price = Convert.ToDouble(priceA.Substring(0, priceA.IndexOf('-'))); }

                Pork.date = er.getTextInOneCell(i + 3, 18).Substring(0, 9);
                porklist.Add(Pork);
            }
            label1.Text = porklist.Count.ToString();
        }