Esempio n. 1
0
        /// <summary>
        /// Находит текст в документе и заменяет его, если найдено. ВНИМАНИЕ! К искомой строке добавляются квадратные скобки []
        /// </summary>
        /// <param name="ws">Лист Excel</param>
        /// <param name="findStr">Искомый текст</param>
        /// <param name="replaceStr">Заменяющий текст</param>
        public static void FindAndReplaceText(this Excel.ExcelWorksheet ws, string findStr, string replaceStr)
        {
            string str = string.Format("[{0}]", findStr);
            int    rowIndex, columnIndex;

            if (ws.Cells.FindText(str, true, true, out rowIndex, out columnIndex))
            {
                ws.Cells[rowIndex, columnIndex].Value = replaceStr;
            }
        }
Esempio n. 2
0
        public void ExportFillProvisalRegister(IList <Customer> customers, GemBox.Spreadsheet.ExcelWorksheet sheet, ref int stt)
        {
            var activeRow = 1;

            foreach (var customer in customers)
            {
                sheet.Cells[activeRow, 0].Value = stt.ToString();
                stt++;
                customer.Fullname = customer.Fullname ?? "";
                sheet.Cells[activeRow, 1].Value = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(customer.Fullname.ToLower());

                var birthday = "";
                try
                {
                    birthday = customer.Birthday.Value.ToString("dd/MM/yyyy");
                }
                catch (Exception) { }
                sheet.Cells[activeRow, 2].Value = birthday;

                sheet.Cells[activeRow, 3].Value = "D";

                var isMale = false;
                try
                {
                    isMale = customer.IsMale.Value;
                }
                catch (Exception) { }

                if (isMale)
                {
                    sheet.Cells[activeRow, 4].Value = "M";
                }
                else
                {
                    sheet.Cells[activeRow, 4].Value = "F";
                }

                var maquoctich = "";
                try
                {
                    maquoctich = customer.Nationality.AbbreviationCode;
                }
                catch (Exception) { }
                sheet.Cells[activeRow, 5].Value = maquoctich;
                sheet.Cells[activeRow, 6].Value = customer.Passport;

                sheet.Cells[activeRow, 7].Value  = ((BookingRoom)customer.BookingRooms[0]).Room != null ? ((BookingRoom)customer.BookingRooms[0]).Room.Name : "";
                sheet.Cells[activeRow, 8].Value  = ((BookingRoom)customer.BookingRooms[0]).Book.StartDate.ToString("dd/MM/yyyy");
                sheet.Cells[activeRow, 9].Value  = ((BookingRoom)customer.BookingRooms[0]).Book.EndDate.ToString("dd/MM/yyyy");
                sheet.Cells[activeRow, 10].Value = ((BookingRoom)customer.BookingRooms[0]).Book.EndDate.ToString("dd/MM/yyyy");
                sheet.Cells[activeRow, 10].Value = customer.NguyenQuan;
                activeRow++;
            }
        }