/// <summary> /// 默认生成模板样式 /// </summary> public void FormatTamplate() { ws = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet); Microsoft.Office.Interop.Excel.Range rang = (Microsoft.Office.Interop.Excel.Range)ws.get_Range("B1", "G1"); rang.Select(); rang.Merge(false); rang = (Microsoft.Office.Interop.Excel.Range)ws.get_Range("B2", "G2"); rang.Select(); rang.Merge(false); rang = (Microsoft.Office.Interop.Excel.Range)ws.get_Range("B3", "G3"); rang.Select(); rang.Merge(false); ws.Cells.set_Item(1, 1, "输出表"); ws.Cells.set_Item(2, 1, "表名称"); ws.Cells.set_Item(3, 1, "备注"); ws.Cells.set_Item(3, 2, this._tableName); ws.Cells.set_Item(4, 1, "字段编号"); ws.Cells.set_Item(4, 2, "字段"); ws.Cells.set_Item(4, 3, "数据元素"); ws.Cells.set_Item(4, 4, "长度"); ws.Cells.set_Item(4, 5, "小数位"); ws.Cells.set_Item(4, 6, "类型"); ws.Cells.set_Item(4, 7, "字段含义"); ws.Columns.AutoFit(); }
public void Exportar() { if (dgv_Ventas.Rows.Count > 0) { CargarTodoDataGridView(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Value = "Nombre de Caja"; CR.Font.Bold = "TRUE"; CR.Font.Size = "11"; CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 2]; CR.Value = "Nombre de Documento"; CR.Font.Bold = "TRUE"; CR.Font.Size = "11"; CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 3]; CR.Value = "Tipo de Pago"; CR.Font.Bold = "TRUE"; CR.Font.Size = "11"; CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 4]; CR.Value = "Cliente"; CR.Font.Bold = "TRUE"; CR.Font.Size = "11"; CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 5]; CR.Value = "Empresa"; CR.Font.Bold = "TRUE"; CR.Font.Size = "11"; CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 6]; CR.Value = "Numero de Documento"; CR.Font.Bold = "TRUE"; CR.Font.Size = "14"; CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 7]; CR.Value = "Fecha de Venta"; CR.Font.Bold = "TRUE"; CR.Font.Size = "11"; CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 8]; CR.Value = "Total de Venta"; CR.Font.Bold = "TRUE"; CR.Font.Size = "11"; CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); } else { MessageBox.Show("No hay Registros Para Exportar"); return; } }
private void btn_exportToExcel_Click(object sender, RoutedEventArgs e) { if (listView_ExcelList.SelectedItem == null) { Xceed.Wpf.Toolkit.MessageBox.Show("Please select an excel invoice before trying to export", "", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (iud.Text == String.Empty || txtBox_Column.Text == String.Empty) { Xceed.Wpf.Toolkit.MessageBox.Show("Please make sure you have entered a column and row value", "", MessageBoxButton.OK, MessageBoxImage.Information); return; } int index = findAlphabetIndexNumber(); dg.SelectAllCells(); dg.ClipboardCopyMode = DataGridClipboardCopyMode.ExcludeHeader; ApplicationCommands.Copy.Execute(null, dg); dg.UnselectAllCells(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object missingValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; Console.WriteLine(listView_ExcelList.SelectedItem.ToString()); xlWorkBook = xlexcel.Workbooks.Open(System.Environment.CurrentDirectory + "\\Excel\\" + listView_ExcelList.SelectedItem.ToString()); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); //index to paste at.. Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[iud.Value, index]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); }
public void ExportInExcel(DataGridView dg) { try { if (dg.Rows.Count <= 0) { MessageBox.Show("Rien à exporter, tableau vide", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { copyAlltoClipboard(dg); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); } } catch (Exception ex) { MessageBox.Show("Erreur lors de l'export en excel : \n" + ex.Message); } }
private void button4_Click(object sender, EventArgs e) { copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xl = new Application(); xl.Visible = true; xlWorkBook = xl.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets .get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[3, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); xlWorkSheet.Cells[1, 1] = "Заявки по месяцам --- "; xlWorkSheet.Cells[2, 2] = "Год"; xlWorkSheet.Cells[2, 3] = "Месяц"; xlWorkSheet.Cells[2, 4] = "Населенный пункт"; xlWorkSheet.Cells[2, 5] = "Статус"; xlWorkSheet.Cells[2, 6] = "Дата установки статуса"; }
//ADATOK EXPORTÁLÁSA gomb: private void bnExportData_Click(object sender, EventArgs e) { if (dgvCarSearch.Rows.Count == 0) { MessageBox.Show("Az adattábla üres, keressen rá előbb egy vagy több modellre"); } else { try { copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnproductoMasVendido_Click(object sender, EventArgs e) { List <Reporte_Ventas> listaVentas = new List <Reporte_Ventas>(); listaVentas = ReportesDao.ListadoProductosMasVendidos(); if (listaVentas.Count > 0) { foreach (var item in listaVentas) { dataGridView3.Rows.Add(item.DescripcionProducto, item.ProductoMasVendido); } } dataGridView3.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; dataGridView3.MultiSelect = true; dataGridView3.SelectAll(); DataObject dataObj = dataGridView3.GetClipboardContent(); if (dataObj != null) { Clipboard.SetDataObject(dataObj); } Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); }
private void btnExportarComprasProveedores_Click(object sender, EventArgs e) { List <Reporte_Proveedores> listaComprasAProveedores = new List <Reporte_Proveedores>(); listaComprasAProveedores = ReportesDao.BuscarMovimientoStock(); if (listaComprasAProveedores.Count > 0) { foreach (var item in listaComprasAProveedores) { string Fecha = item.Fecha.ToShortDateString(); dataGridView2.Rows.Add(Fecha, item.Proveedor, item.Remito); } } dataGridView2.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; dataGridView2.MultiSelect = true; dataGridView2.SelectAll(); DataObject dataObj = dataGridView2.GetClipboardContent(); if (dataObj != null) { Clipboard.SetDataObject(dataObj); } Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); }
private void toolStripButton1_Click(object sender, EventArgs e) { copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); //xlexcel.Columns.AutoFit(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[2, 1]; for (int j = 0; j < dgv_inv.Columns.Count; ++j) { xlWorkSheet.Cells[1, j + 1] = dgv_inv.Columns[j].HeaderText; } CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); xlexcel.Columns.AutoFit(); }
public void ConvertCsvToExcel_MicrosoftOfficeInteropExcel() { StringBuilder content = new StringBuilder(); content.AppendLine("param1\tparam2\tstatus"); content.AppendLine("0.5\t10\tpassed"); content.AppendLine("10\t20\tfail"); using (TemporaryFile xlsxFile = new TemporaryFile(".xlsx")) { Clipboard.SetText(content.ToString()); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); // for excel visibility //xlexcel.Visible = true; // Creating a new workbook xlWorkBook = xlexcel.Workbooks.Add(misValue); // Putting Sheet 1 as the sheet you want to put the data within xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); // creating the range Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.Paste(CR, false); xlWorkSheet.SaveAs(xlsxFile.FileName); xlexcel.Quit(); Console.WriteLine("Created file {0}", xlsxFile.FileName); } }
private void btnExcelCopy_Click(object sender, EventArgs e) { try { copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); string basePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string fileName = wp + "_" + txtFileName.Text + txtMonthYear.Text + "NoFormat"; if (multipleRP == "") {//single RP //MessageBox.Show(multipleRP); fileName = wp + "_" + txtRP.Text + location + txtMonthYear.Text + "NoFormat"; } string path = Path.Combine(basePath, fileName); xlWorkBook.SaveAs(path); } catch (Exception er) { MessageBox.Show(er.Message); } }
private void btnExportExcel_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application(); object Missing = Type.Missing; Microsoft.Office.Interop.Excel.Workbook workbook = Excel.Workbooks.Add(Missing); Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1]; int StartCol = 1; int StartRow = 1; for (int j = 0; j < dgVeriler.Columns.Count; j++) { Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[StartRow, StartCol + j]; myRange.Value2 = dgVeriler.Columns[j].HeaderText; } StartRow++; for (int i = 0; i < dgVeriler.Rows.Count; i++) { for (int j = 0; j < dgVeriler.Columns.Count; j++) { try { Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[StartRow + i, StartCol + j]; myRange.Value2 = dgVeriler[j, i].Value == null ? "" : dgVeriler[j, i].Value; myRange.Select(); } catch (Exception) { MessageBox.Show("Aktarım Yapılırken Hata Oluştu", "Aktarım Hatası", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } Excel.Visible = true; }
/// /// Métodos /// //exporta lista para excel private void ExportarExcel() { //seleciona toda a gridview e copia-a dataGridBilhetes.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; dataGridBilhetes.MultiSelect = true; dataGridBilhetes.SelectAll(); DataObject dataObj = dataGridBilhetes.GetClipboardContent(); if (dataObj != null) { Clipboard.SetDataObject(dataObj); } //abre o excel e cola a lista Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); xlexcel.Columns.AutoFit(); xlexcel.Rows.AutoFit(); xlexcel.Visible = true; }
private void btnExport_Click(object sender, EventArgs e) { try { if (DgvResult.Rows.Count > 0) { copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); } else { MessageBox.Show("Process the file first", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } }
private void buttonSaveToExcel_Click(object sender, EventArgs e) { dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; dataGridView1.SelectAll(); #region outsourcingc code to export excel sheet DataObject dataObj = dataGridView1.GetClipboardContent(); if (dataObj != null) { Clipboard.SetDataObject(dataObj); } Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); #endregion dataGridView1.Select(); }
/// <summary> /// Exporta a excel un datagridview /// </summary> /// <param name="datagrid"> DataGrid que se desea exportar</param> public static void ConvertirExcel(DataGridView datagrid) { datagrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; datagrid.MultiSelect = true; datagrid.SelectAll(); DataObject dataObj = datagrid.GetClipboardContent(); if (dataObj != null) { Clipboard.SetDataObject(dataObj); } Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); xlWorkSheet.Columns.AutoFit(); }
private void btnExport_Click(object sender, EventArgs e) { if (ordersTable.RowCount != 0) { try { copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); } catch (Exception err) { MessageBox.Show("Error: " + err); } finally { ordersTable.DataSource = Functions.showTableSales().DefaultView; } } else { MessageBox.Show("None to export"); } }
private void btnExcel_Click(object sender, EventArgs e) { dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; dataGridView1.MultiSelect = true; dataGridView1.SelectAll(); DataObject dataObj = dataGridView1.GetClipboardContent(); if (dataObj != null) { Clipboard.SetDataObject(dataObj); } //Open an excel instance and paste the copied data Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); }
private void btnExcel_Click(object sender, EventArgs e) { try { DialogResult dr = MessageBox.Show("You must have Microsoft Excel installed on your PC," + " Do you want to continue exporting?", "Export to Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); } else { //do nothing } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnExport_Click(object sender, EventArgs e) { if (cmbCompany.SelectedValue.ToString() == "COMP021") { //GENERATE TEXT FILE FOR SMART createSMARTtxtFile(); } else { //NOT SMART copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); } btnExport.Enabled = false; }
private void button1_Click(object sender, EventArgs e) { if (grdDatos.Rows.Count > 1) { using (new CursorWait()) { try { this.UI_GV_CopyData(this.grdDatos); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object valores = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(valores); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range cr = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; cr.Select(); xlWorkSheet.PasteSpecial(cr, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); }catch (Exception ex) { ELog.save("ERROR AL ENVIAR A EXCEL", ex); } } } else { MessageBox.Show("Debe seleccionar un Almacen", "No hay almacen", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button4_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Visible = true; object Missing = Type.Missing; Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Add(Missing); Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1]; int StartCol = 1; int StartRow = 1; for (int j = 0; j < dataGridView1.Columns.Count; j++) { Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[StartRow, StartCol + j]; myRange.Value2 = dataGridView1.Columns[j].HeaderText; } StartRow++; for (int i = 0; i < dataGridView1.Rows.Count; i++) { for (int j = 0; j < dataGridView1.Columns.Count; j++) { Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[StartRow + i, StartCol + j]; myRange.Value2 = dataGridView1[j, i].Value == null ? "" : dataGridView1[j, i].Value; myRange.Select(); } } }
private void btnExcel_Click(object sender, EventArgs e) { { copyAlltoClipboard(); try { Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); } catch (Exception ex) { RadMessageBox.Show(this, ex.Message, "JPCS Registration", MessageBoxButtons.OK, RadMessageIcon.Error); } } }
public void ExportarAExcel(DataGridView dgv) { if (dgv.Rows.Count > 0) { dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; dgv.MultiSelect = true; dgv.SelectAll(); DataObject dataObj = dgv.GetClipboardContent(); if (dataObj != null) { Clipboard.SetDataObject(dataObj); } dgv.MultiSelect = false; dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable; Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object valor = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(valor); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); } else { MessageBox.Show("NO SE ENCONTRARON REGISTROS PARA EXPORTAR!", "MSJ DE ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ExcelBtn_Click(object sender, EventArgs e) { if (TxtUrl.Text == "")//En caso que no se ha seleccionado nada { MessageBox.Show("Please upload a PDF file first !!"); } else if (dataGridView1.Rows.Count == 0) { MessageBox.Show("Please run the app to get rows to convert to excel file !!"); } else { copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlexcel.Cells[1, 2].EntireColumn.NumberFormat = "000000"; xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); } }
public void exportToExcel(System.Windows.Controls.DataGrid grid, string fileName = "Excel") { try { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Excel Documents (*.xls)|*.xls"; sfd.FileName = fileName + ".xls"; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // Copy DataGridView results to clipboard copyAlltoClipboard(grid); object misValue = System.Reflection.Missing.Value; Microsoft.Office.Interop.Excel.Application xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.DisplayAlerts = false; // Without this you will get two confirm overwrite prompts Microsoft.Office.Interop.Excel.Workbook xlWorkBook = xlexcel.Workbooks.Add(misValue); Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); // Format column D as text before pasting results, this was required for my data Microsoft.Office.Interop.Excel.Range rng = xlWorkSheet.get_Range("D:D").Cells; rng.NumberFormat = "@"; // Paste clipboard results to worksheet range Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); // For some reason column A is always blank in the worksheet. ¯\_(ツ)_/¯ // Delete blank column A and select cell A1 Microsoft.Office.Interop.Excel.Range delRng = xlWorkSheet.get_Range("A:A").Cells; delRng.Delete(Type.Missing); xlWorkSheet.get_Range("A1").Select(); // Save the excel file under the captured location from the SaveFileDialog xlWorkBook.SaveAs(sfd.FileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlexcel.DisplayAlerts = true; xlWorkBook.Close(true, misValue, misValue); xlexcel.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlexcel); // Clear Clipboard and DataGridView selection System.Windows.Clipboard.Clear(); // roomsGrid.ClearSelection(); // Open the newly saved excel file if (File.Exists(sfd.FileName)) { System.Diagnostics.Process.Start(sfd.FileName); } } } catch (Exception e) { System.Windows.MessageBox.Show(e.ToString()); } }
private void metroTile2_Click(object sender, EventArgs e) { DataGridViewCell cell = null; foreach (DataGridViewCell selectedCell in GridView.SelectedCells) { cell = selectedCell; break; } if (cell != null) { copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); } else { MetroMessageBox.Show(this, "No Data Found!", "RVL Systems", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button14_Click(object sender, EventArgs e) { button13_Click(null, null); DataView dv = new DataView(); dv.Table = dsRep.Tables[0]; if (DgvRep.RowCount == 0) { return; } string appProgID = "Excel.Application"; Type excelType = Type.GetTypeFromProgID(appProgID); object xlapp1 = Activator.CreateInstance(excelType); object workbooks = xlapp1.GetType().InvokeMember("Workbooks", System.Reflection.BindingFlags.GetProperty, null, xlapp1, null); object[] args = new object[1]; args[0] = "C:\\cis\\Сервис\\Отчет по занесению смет.xlt"; //Пробуем открыть книгу //Application xlapp = (Application)xlapp1; Microsoft.Office.Interop.Excel.Workbook WrkBk = (Microsoft.Office.Interop.Excel.Workbook)workbooks.GetType().InvokeMember("Add", System.Reflection.BindingFlags.InvokeMethod, null, workbooks, args); Microsoft.Office.Interop.Excel.Worksheet WrkSht = (Microsoft.Office.Interop.Excel.Worksheet)WrkBk.Sheets["Отчет"]; Microsoft.Office.Interop.Excel.Application ExlApp; ExlApp = (Microsoft.Office.Interop.Excel.Application)xlapp1; ExlApp.Visible = true; Microsoft.Office.Interop.Excel.Range rngActive = (Microsoft.Office.Interop.Excel.Range)WrkSht.Cells[2, 1]; rngActive.Select(); rngActive.get_Offset(-1, 1).Value2 = Login.Text.ToString(); rngActive.get_Offset(0, 1).Value2 = "Отчет по занесению смет по ПСС-4 в программу АО. C 22." + (Convert.ToInt16(MM.Text) < 11 ? "0" : "") + (Convert.ToInt16(MM.Text) - 1).ToString() + " - 20." + (Convert.ToInt16(MM.Text) < 10 ? "0" : "") + MM.Text.ToString(); for (int i = 0; i < 38; i++) { if (i >= dv.Count) { break; } rngActive.get_Offset(i + 3, 1).Value2 = dv[i][1]; rngActive.get_Offset(i + 3, 2).Value2 = dv[i][2]; rngActive.get_Offset(i + 3, 3).Value2 = dv[i][3]; } for (int i = 38; i < 76; i++) { if (i >= dv.Count) { break; } rngActive.get_Offset(i + 3 - 38, 1 + 4).Value2 = dv[i][1]; rngActive.get_Offset(i + 3 - 38, 2 + 4).Value2 = dv[i][2]; rngActive.get_Offset(i + 3 - 38, 3 + 4).Value2 = dv[i][3]; } WrkSht = null; WrkBk = null; /*ExlApp.Quit();*/ ExlApp = null; GC.Collect(); }
public void TransferringDatagridviewtoExcel(DataGridView dataGridView, string FileName) { try { DialogResult dialogResult = MessageBox.Show("Kayıtları Excel'e Aktarılsın mı?", "Excel Aktarma", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Excel Documents (*.xls)|*.xls"; sfd.FileName = FileName + ".xls"; if (sfd.ShowDialog() == DialogResult.OK) { copyAlltoClipboard(dataGridView); object misValue = System.Reflection.Missing.Value; Microsoft.Office.Interop.Excel.Application xlexcel = new Microsoft.Office.Interop.Excel.Application(); xlexcel.DisplayAlerts = false; Microsoft.Office.Interop.Excel.Workbook xlWorkBook = xlexcel.Workbooks.Add(misValue); Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range rng = xlWorkSheet.get_Range("D:D").Cells; rng.NumberFormat = "@"; Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); Microsoft.Office.Interop.Excel.Range delRng = xlWorkSheet.get_Range("A:A").Cells; delRng.Delete(Type.Missing); xlWorkSheet.get_Range("A1").Select(); xlWorkBook.SaveAs(sfd.FileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlexcel.DisplayAlerts = true; xlWorkBook.Close(true, misValue, misValue); xlexcel.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlexcel); Clipboard.Clear(); dataGridView.ClearSelection(); if (File.Exists(sfd.FileName)) { System.Diagnostics.Process.Start(sfd.FileName); } } } } catch (Exception) { MessageBox.Show("Excel'e Aktarılma Sırasında Hata Oluştu."); } }
//设置指定单元格边框 range——单元格 public static void SetCellBorder(Microsoft.Office.Interop.Excel.Range range) { range.Select(); range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlDiagonalDown].LineStyle = (object)(-4142); range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlDiagonalUp].LineStyle = (object)(-4142); range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft].LineStyle = (object)(1); range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeRight].LineStyle = (object)(1); range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom].LineStyle = (object)(1); range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeTop].LineStyle = (object)(1); }
/// <summary> /// 如果字段的类型是结构体,则需要分开处理 /// </summary> /// <param name="dt"></param> /// <param name="rowsOffset"></param> /// <param name="colsOffset"></param> private void ParseStructToExcel(DataTable dt, ref int rowsOffset, int colsOffset) { foreach (DataRow row in dt.Rows) { if (row["DataType"].ToString() == "STRUCTURE") { String structurName = row["DataTypeName"].ToString(); String Documentation = row[FuncFieldText.DOCUMENTATION].ToString(); if (_parsedStructure.Contains(structurName)) { return; } DataTable dt2 = m_function.FunctionMeta.StructureDetail[structurName]; if (dt2 != null) { if (dt2.Rows.Count > 0) { _parsedStructure.Add(structurName); range = (Microsoft.Office.Interop.Excel.Range)ws.get_Range(ws.Cells[rowsOffset - 4, colsOffset + 1], ws.Cells[rowsOffset - 4, colsOffset + 5]); range.Select(); range.Merge(false); range = (Microsoft.Office.Interop.Excel.Range)ws.get_Range(ws.Cells[rowsOffset - 3, colsOffset + 1], ws.Cells[rowsOffset - 3, colsOffset + 5]); range.Select(); range.Merge(false); range = (Microsoft.Office.Interop.Excel.Range)ws.get_Range(ws.Cells[rowsOffset - 2, colsOffset + 1], ws.Cells[rowsOffset - 2, colsOffset + 5]); range.Select(); range.Merge(false); ws.Cells.set_Item(rowsOffset - 4, colsOffset - 1, "STRUCTURE"); ws.Cells.set_Item(rowsOffset - 4, colsOffset, "结构"); ws.Cells.set_Item(rowsOffset - 3, colsOffset, "名称"); ws.Cells.set_Item(rowsOffset - 2, colsOffset, "备注"); ws.Cells.set_Item(rowsOffset - 4, colsOffset + 1, structurName); ws.Cells.set_Item(rowsOffset - 3, colsOffset + 1, Documentation); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 0, "字段编号"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 1, "字段"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 2, "数据类型"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 3, "长度"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 4, "小数位"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 5, "短文本"); ParseTypeDefinitionToExcel(dt2, rowsOffset, colsOffset); rowsOffset += dt2.Rows.Count + 7; } } } else if (row["DataType"].ToString() == "TABLE") { String tableName = row["DataTypeName"].ToString(); String Documentation = row[FuncFieldText.DOCUMENTATION].ToString(); if (_parsedTable.Contains(tableName)) { return; } DataTable dt2 = m_function.FunctionMeta.StructureDetail[tableName]; if (dt2 != null) { if (dt2.Rows.Count > 0) { _parsedTable.Add(tableName); range = (Microsoft.Office.Interop.Excel.Range)ws.get_Range(ws.Cells[rowsOffset - 4, colsOffset + 1], ws.Cells[rowsOffset - 4, colsOffset + 5]); range.Select(); range.Merge(false); range = (Microsoft.Office.Interop.Excel.Range)ws.get_Range(ws.Cells[rowsOffset - 3, colsOffset + 1], ws.Cells[rowsOffset - 3, colsOffset + 5]); range.Select(); range.Merge(false); range = (Microsoft.Office.Interop.Excel.Range)ws.get_Range(ws.Cells[rowsOffset - 2, colsOffset + 1], ws.Cells[rowsOffset - 2, colsOffset + 5]); range.Select(); range.Merge(false); ws.Cells.set_Item(rowsOffset - 4, colsOffset - 1, "TABLE"); ws.Cells.set_Item(rowsOffset - 4, colsOffset, "表"); ws.Cells.set_Item(rowsOffset - 3, colsOffset, "名称"); ws.Cells.set_Item(rowsOffset - 2, colsOffset, "备注"); ws.Cells.set_Item(rowsOffset - 4, colsOffset + 1, tableName); ws.Cells.set_Item(rowsOffset - 3, colsOffset + 1, Documentation); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 0, "字段编号"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 1, "字段"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 2, "数据类型"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 3, "长度"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 4, "小数位"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 5, "短文本"); ParseTypeDefinitionToExcel(dt2, rowsOffset, colsOffset); rowsOffset += dt2.Rows.Count + 7; } } } } }
/// <summary> /// 处理固定的4个参数表 /// </summary> /// <param name="dt"></param> /// <param name="name"></param> /// <param name="rowsOffset"></param> /// <param name="colsOffset"></param> private void ParseParameterList(DataTable dt, String name, int rowsOffset, int colsOffset) { range = (Microsoft.Office.Interop.Excel.Range)ws.get_Range(ws.Cells[rowsOffset - 2, colsOffset + 1], ws.Cells[rowsOffset - 2, colsOffset + 8]); range.Select(); range.Merge(false); ws.Cells.set_Item(rowsOffset - 2, colsOffset - 1, "PARAMETERLIST"); ws.Cells.set_Item(rowsOffset - 2, colsOffset, name); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 0, "字段编号"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 1, "字段"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 2, "数据类型"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 3, "类型名称"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 4, "长度"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 5, "小数位"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 6, "默认值"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 7, "必输"); ws.Cells.set_Item(rowsOffset - 1, colsOffset + 8, "短文本"); if (dt.Rows.Count > 0) { ParseParameterlistToExcel(dt, rowsOffset, colsOffset); } }