Ejemplo n.º 1
0
        public static void AddForeignAddress(Address address)
        {
            XSSFWorkbook hssfwb = ExcelReader_NPOI.OpenXLSX("ForeignAddressList.xlsx", false);
            ISheet       sheet  = hssfwb.GetSheet("Sheet1");

            int numberOfRows = sheet.LastRowNum;

            for (int i = 0; i <= sheet.LastRowNum; i++)
            {
                if (sheet.GetRow(i) != null)
                {
                    if (sheet.GetRow(i).GetCell(0).StringCellValue == address.PostCode)
                    {
                        break;
                    }
                }

                if (i == sheet.LastRowNum)
                {
                    sheet.CreateRow(i + 1); //Creating Row Overwrites whole row
                    sheet.GetRow(i + 1).CreateCell(0).SetCellValue(address.PostCode);
                    sheet.GetRow(i + 1).CreateCell(1).SetCellValue(address.Road);
                    sheet.GetRow(i + 1).CreateCell(2).SetCellValue(address.Town);
                    sheet.GetRow(i + 1).CreateCell(3).SetCellValue(address.Latitude);
                    sheet.GetRow(i + 1).CreateCell(4).SetCellValue(address.Longitude);
                }
            }
            ExcelReader_NPOI.WriteXLSX(hssfwb, "ForeignAddressList.xlsx");
            totalAddresses.Add(address);
        }
Ejemplo n.º 2
0
        public static void AddCustomerToCount(Address address)
        {
            XSSFWorkbook hssfwb = ExcelReader_NPOI.OpenXLSX("Customers.xlsx", false);
            ISheet       sheet  = hssfwb.GetSheet("Sheet1");

            int numberOfRows = sheet.LastRowNum;

            for (int i = 0; i <= sheet.LastRowNum; i++)
            {
                if (sheet.GetRow(i) != null)
                {
                    if (sheet.GetRow(i).GetCell(0).StringCellValue == address.Number && sheet.GetRow(i).GetCell(1).StringCellValue == address.Road)
                    {
                        int count = (int)sheet.GetRow(i).GetCell(2).NumericCellValue;
                        sheet.GetRow(i).GetCell(2).SetCellValue(count + 1);
                        break;
                    }
                }

                if (i == sheet.LastRowNum)
                {
                    sheet.CreateRow(i + 1); //Creating Row Overwrites whole row
                    sheet.GetRow(i + 1).CreateCell(0).SetCellValue(address.Number);
                    sheet.GetRow(i + 1).CreateCell(1).SetCellValue(address.Road);
                    sheet.GetRow(i + 1).CreateCell(2).SetCellValue(0);
                    sheet.GetRow(i + 1).CreateCell(3).SetCellValue(address.PhoneNumber);
                }
            }
            ExcelReader_NPOI.WriteXLSX(hssfwb, "Customers.xlsx");
        }
Ejemplo n.º 3
0
        public static void AddToRecentOrder(OrderDetails orderDetails)
        {
            XSSFWorkbook hssfwb = null;

            try
            {
                hssfwb = ExcelReader_NPOI.OpenXLSX("OrderLog.xlsx", false);
            }
            catch (IOException)
            {
                Debug.WriteLine("File in use? Cannot open file.");
                return;
            }
            ISheet  sheet   = hssfwb.GetSheet("Sheet1");
            Address address = orderDetails.CurrentAddress;
            var     items   = orderDetails.ItemBasket.Items;

            int lastRow = sheet.LastRowNum;

            sheet.CreateRow(lastRow + 1);
            if (address == null)
            {
                sheet.GetRow(lastRow + 1).CreateCell(0).SetCellValue("N/A");
                sheet.GetRow(lastRow + 1).CreateCell(1).SetCellValue("Pick up order");
                sheet.GetRow(lastRow + 1).CreateCell(2).SetCellValue("N/A");
            }
            else
            {
                sheet.GetRow(lastRow + 1).CreateCell(0).SetCellValue(address.Number);
                sheet.GetRow(lastRow + 1).CreateCell(1).SetCellValue(address.Road);
                sheet.GetRow(lastRow + 1).CreateCell(2).SetCellValue(address.PhoneNumber);
            }

            sheet.GetRow(lastRow + 1).CreateCell(3).SetCellValue(DateTime.Now);

            for (int i = 4; i < items.Count; i++)
            {
                IItem currentItem = items[i - 4];
                sheet.GetRow(lastRow + 1).CreateCell(i).SetCellValue(currentItem.EnglishName + " " + currentItem.ChineseName);
            }

            ExcelReader_NPOI.WriteXLSX(hssfwb, "OrderLog.xlsx");
        }