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); }
private void cmbSheets_SelectedValueChanged(object sender, EventArgs e) { int i = Convert.ToInt32(cmbSheets.SelectedValue); Office.ExcelSheet sh = OpenedExcelFile.Sheets.FirstOrDefault(a => a.Index == i); lblNumberOfColumns.Text = $"Столбцов: {sh.LastCell.Column}"; lblNumberOfRows.Text = $"Строк: {sh.LastCell.Row}"; cmbLinks.DataSource = ExcelStatic.GetColumnNames(sh.LastCell.Column); cmbNames.DataSource = ExcelStatic.GetColumnNames(sh.LastCell.Column); txtBeginRow.Text = "2"; txtEndRow.Text = sh.LastCell.Row.ToString(); }
public ExcelWorkBookInfo ReadExcelFileInfo(string path) { try { Excel.Workbook xlWorkBook = OpenExcelFile(path); Excel.Sheets xlWorkSheets = xlWorkBook.Sheets; ExcelWorkBookInfo result = new ExcelWorkBookInfo(path); foreach (Excel.Worksheet sheet in xlWorkSheets) { ExcelSheet s = GetExcelSheetInfo(sheet); result.Sheets.Add(s); } xlWorkBook.Close(); Release(xlWorkSheets); Release(xlWorkBook); ExitExcelApplication(); return(result); } catch (Exception ex) { try { if (xlApp != null) { ExitExcelApplication(); } } finally { ReleaseUnmanaged(); throw ex; } } }