public override bool Equals(object obj) { if (obj == null) { return(false); } if (object.ReferenceEquals(this, obj)) { return(true); } UploadingExcelParameters other = obj as UploadingExcelParameters; if (other == null) { return(false); } return(this.FilePath == other.FilePath && this.SheetIndex == other.SheetIndex && this.ColumnWithNames == other.ColumnWithNames && this.ColumnWithLinks == other.ColumnWithLinks && this.RowBegin == other.RowBegin && this.RowEnd == other.RowEnd); }
private ProcessorParameters GetProcessorParameters() { if (this.OpenedExcelFile == null) { throw new Exception("Файл не загружен"); } Office.ExcelSheet selectedSheet = OpenedExcelFile.Sheets.FirstOrDefault(a => a.Index == Convert.ToInt32(cmbSheets.SelectedValue)); string columnWithNames = checkbUseNames.Checked ? cmbNames.Text : null; string columnWithLinks = cmbLinks.Text; int rowBegin = Convert.ToInt32(txtBeginRow.Text); int rowEnd = Convert.ToInt32(txtEndRow.Text); if (rowBegin < 1 || rowBegin > selectedSheet.LastCell.Row || rowEnd < rowBegin || rowEnd > selectedSheet.LastCell.Row) { throw new Exception("Указан неверный диапазон строк"); } UploadingExcelParameters excel = new Office.UploadingExcelParameters(OpenedExcelFile.Path, selectedSheet.Index, columnWithNames, columnWithLinks, rowBegin, rowEnd); excel.IncludeLinkToCell = this.chkLinkToCell.Checked; ProcessorParameters param = new ProcessorParameters(excel); param.UploadDirectory = txtPictureFolderName.Text.Trim(); param.UploadDirection = rbSaveLocal.Checked ? UploadDirection.LOCAL : UploadDirection.FTP; return(param); }
public List <PictureItem> GetPhotoItems(UploadingExcelParameters excelInfo) { this.OpenedExcelFile = excelInfo.FilePath; try { InitializeExcelApplication(); this.xlWorkBook = IExcelProcessor.OpenWorkbook(this.xlApp, excelInfo.FilePath); this.xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets[excelInfo.SheetIndex]; List <PictureItem> Items = new List <PictureItem>(); for (int i = excelInfo.RowBegin; i <= excelInfo.RowEnd; i++) { string picName = null; if (!string.IsNullOrEmpty(excelInfo.ColumnWithNames)) { if (xlWorkSheet.Range[excelInfo.ColumnWithNames + i].Value != null) { picName = xlWorkSheet.Range[excelInfo.ColumnWithNames + i].Value.ToString().Trim(); } } if (string.IsNullOrEmpty(picName)) { picName = Guid.NewGuid().ToString(); } PictureItem item = new PicturesUploader.PictureItem(i, picName); Uri url = GetUrlFromCell(xlWorkSheet.Range[excelInfo.ColumnWithLinks + i]); if (url == null) { item.Error = new Exception("Не найдена ссылка в ячейке"); } else { item.Address = url; } Items.Add(item); } return(Items); } finally { xlWorkBook.Close(); ExitExcelApplication(); } }
internal ProcessorParameters(Office.UploadingExcelParameters excelInfo) { this.ExcelInfo = excelInfo; this.ImageResizeSettings = new ImageResizer.ResizeSettings(); if (PicturesUploader.Properties.Settings.Default.NewImageSize == 0) { this.ImageResizeSettings.ScaleMode = ImageResizer.ScaleMode.None; } else { this.ImageResizeSettings.ScaleMode = ImageResizer.ScaleMode.DownscaleOnly; this.ImageResizeSettings.ResizeMode = ImageResizer.ResizeMode.MaxSides; var size = ImageResizer.ImageSize.GetDefaults().FirstOrDefault(a => a.ID == PicturesUploader.Properties.Settings.Default.NewImageSize); this.ImageResizeSettings.Height = size.Size.Height; this.ImageResizeSettings.Width = size.Size.Width; } }
public void UpdatePhotoItems(IEnumerable <PictureItem> items, UploadingExcelParameters excelInfo) { try { InitializeExcelApplication(); this.xlWorkBook = IExcelProcessor.OpenWorkbook(this.xlApp, excelInfo.FilePath); this.xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets[excelInfo.SheetIndex]; var sheetInfo = GetSheetInfo(this.xlWorkSheet); string targetColumn = ExcelStatic.GetColumnName(sheetInfo.LastCell.Column + 1); foreach (var item in items) { if (item.Error == null) { string link = (item.Address.Scheme == Uri.UriSchemeFile) ? item.Address.LocalPath : item.Address.AbsoluteUri; string val = excelInfo.IncludeLinkToCell ? link : "Фото"; xlWorkSheet.Hyperlinks.Add(Anchor: xlWorkSheet.Range[targetColumn + item.RowIndex], Address: link, TextToDisplay: val); } else { xlWorkSheet.Range[targetColumn + item.RowIndex].Value = item.Error.Message; } } xlWorkBook.Save(); xlWorkBook.Close(); ExitExcelApplication(); } catch { if (xlWorkBook != null) { xlWorkBook.Close(); } if (xlApp != null) { ExitExcelApplication(); } throw; } }