myChart = xlCharts.Add(0, 0, 600, 450)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim rowsTotal, colsTotal As Short Dim I, j, iC As Short System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor Dim xlApp As New Microsoft.Office.Interop.Excel.Application Dim excelBook As Microsoft.Office.Interop.Excel.Workbook = xlApp.Workbooks.Add Dim excelWorksheet As Microsoft.Office.Interop.Excel.Worksheet = CType(excelBook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet) Dim excelWorksheet2 As Microsoft.Office.Interop.Excel.Worksheet = CType(excelBook.Worksheets(2), Microsoft.Office.Interop.Excel.Worksheet) ' Define a title for the message box. Dim title = "Exportation" ' Display the message box and save the response, Yes or No. Dim response = MsgBox("Exportation des données, veuillez patienter.", , title) Try xlApp.Visible = True rowsTotal = Form2.DataGridView1.RowCount - 1 colsTotal = Form2.DataGridView1.Columns.Count - 1 With excelWorksheet .Name = "Données" .Cells.Select() .Cells.Delete() For iC = 0 To colsTotal .Cells(1, iC + 1).Value = Form2.DataGridView1.Columns(iC).HeaderText .Cells(1, iC + 1).Interior.ColorIndex = 3 Next With excelWorksheet.Cells.Range(excelWorksheet.Cells(1, 1), excelWorksheet.Cells(1, colsTotal + 1)) .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom).Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom).ColorIndex = 0 .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeRight).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeRight).Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeRight).ColorIndex = 0 .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft).Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft).ColorIndex = 0 End With For I = 0 To rowsTotal - 1 For j = 0 To colsTotal .Cells(I + 2, j + 1).value = Form2.DataGridView1.Rows(I).Cells(j).Value Next j Next I With excelWorksheet.Cells.Range(excelWorksheet.Cells(2, 1), excelWorksheet.Cells(rowsTotal + 1, colsTotal + 1)) .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom).Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom).ColorIndex = 0 .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeRight).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeRight).Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeRight).ColorIndex = 0 .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft).Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft).ColorIndex = 0 .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideHorizontal).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideHorizontal).Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideHorizontal).ColorIndex = 0 .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideVertical).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideVertical).Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin .Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideVertical).ColorIndex = 0 End With .Rows("1:1").Font.FontStyle = "Bold" .Rows("1:1").Font.Size = 10 .Cells.Columns.AutoFit() '.Cells.Select() '.Cells.EntireColumn.AutoFit() End With 'create chart Dim chartPage As Microsoft.Office.Interop.Excel.Chart ' Dim xlCharts As Microsoft.Office.Interop.Excel.ChartObjects Dim myChart As Microsoft.Office.Interop.Excel.ChartObject Dim chartRange As Microsoft.Office.Interop.Excel.Range msgbox("jusque là ça marche nickel ensuite ça plante sur myChart = .ChartObjects.Add(0, 0, 600, 450)") excelWorksheet2.Select() With excelWorksheet2 .Name = "Graphe" myChart = .ChartObjects.Add(0, 0, 600, 450) End With ' With excelWorksheet.Cells.Range(excelWorksheet.Cells(1, 1), excelWorksheet.Cells(1, colsTotal + 1)) '.Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideVertical).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous '.Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideVertical).Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin '.Cells.Borders(Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideVertical).ColorIndex = 0 'End With Dim misValue As Object = System.Reflection.Missing.Value xlApp = New Microsoft.Office.Interop.Excel.Application excelBook = xlApp.Workbooks.Add(misValue) ' xlCharts = excelWorksheet2.ChartObjects ' myChart = excelWorksheet2.ChartObjects.Add(0, 0, 600, 450) chartPage = myChart.Chart chartRange = excelWorksheet.Range(excelWorksheet.Cells(1, 3), excelWorksheet.Cells(rowsTotal + 1, colsTotal + 1)) chartPage.SetSourceData(Source:=chartRange, PlotBy:=Microsoft.Office.Interop.Excel.XlRowCol.xlColumns) chartPage.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLine Dim NameFile As String If cyclename = "" Or cycleshort = "" Then If Directory.Exists(Application.StartupPath.ToString() & "\" & "enregistrement manuel") = False Then Directory.CreateDirectory(Application.StartupPath.ToString() & "\" & "enregistrement manuel") End If NameFile = Application.StartupPath.ToString() & "\" & "enregistrement manuel" & "\" & "_axe" & axe & "_manu" & "_" & Date.Now.Hour & "h" & Date.Now.Minute & ".xls" If File.Exists(NameFile) Then NameFile = Application.StartupPath.ToString() & "\" & "enregistrement manuel" & "\" & "_axe" & axe & "_manu" & "_" & Date.Now.Hour & "h" & Date.Now.Minute & "min" & Date.Now.Second & ".xls" End If Else If Directory.Exists(Application.StartupPath.ToString() & "\" & cyclename) = False Then Directory.CreateDirectory(Application.StartupPath.ToString() & "\" & cyclename) End If NameFile = (Application.StartupPath.ToString() & "\" & cyclename & "\" & cycleshort & "_axe" & axe & "_auto" & "_" & Date.Now.Hour & "h" & Date.Now.Minute & ".xls") If File.Exists(NameFile) Then NameFile = Application.StartupPath.ToString() & "\" & cyclename & "\" & cycleshort & "_axe" & axe & "_auto" & "_" & Date.Now.Hour & "h" & Date.Now.Minute & "min" & Date.Now.Second & ".xls" End If End If excelWorksheet2.Cells(1, 1).select() excelWorksheet2.SaveAs(NameFile) excelBook.Close(False) ' xlApp.Quit() releaseObject(xlApp) releaseObject(excelBook) releaseObject(excelWorksheet) ' MsgBox("Excel file created , you can find the file" & Chr(13) & NameFile) Dim style = MsgBoxStyle.MsgBoxSetForeground MsgBox("Exportation terminée avec succès.", style) Catch ex As Exception MsgBox("Export Excel Error " & ex.Message) Finally 'RELEASE ALLOACTED RESOURCES System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default xlApp = Nothing End Try Return (True)