No video

How to export datagridview to excel in c# windows application

  Рет қаралды 66,582

Csharp Space

Csharp Space

Күн бұрын

Here I will explain how to export datagridview to excel in c# windows application. Export datagridview to excel with column headers.C# datagridview export to excel with formatting
~-~~-~~~-~~-~
Please watch: "How to Perform Global Exception Handling in ASP.NET CORE MVC"
• How to Perform Global ...
~-~~-~~~-~~-~

Пікірлер: 117
@vietthole7217
@vietthole7217 4 жыл бұрын
I made it. Thanks bro.😍👍
@alawal_kabir
@alawal_kabir 3 жыл бұрын
Nice Tutorial. Thanks a lot.
@jackhuynh9847
@jackhuynh9847 2 жыл бұрын
Thank you very much, it worked!
@alejandromonroy8726
@alejandromonroy8726 4 жыл бұрын
Thank you so much , it worked :)
@motivation9822
@motivation9822 4 жыл бұрын
My program is giving me an error on this line Pdftable.AddCell(new Phrase(Cell.Value.ToString(),text)); Its saying Object reference not set to an instance of an object
@KaS95PeR
@KaS95PeR Жыл бұрын
thanks man!
@WhiteCoder
@WhiteCoder Жыл бұрын
Thank You So Much....
@thonginh5082
@thonginh5082 4 жыл бұрын
thank you for this video
@nadunsilv
@nadunsilv 5 жыл бұрын
It works thank you, bro!!
@radhikagharote1261
@radhikagharote1261 4 жыл бұрын
Only the the first column name is visible other columns are not visible But the rows are visible
@pauloherculano9243
@pauloherculano9243 6 жыл бұрын
Hey Bro, I'm having this issue "System.NullReferenceException: 'Object reference not defined for an instance of an object. System.Windows.Forms.DataGridViewCell.Value.get retorned null." in this line "worksheet.Cells[i+2,j+1] = produtoDataGridView.Rows[i].Cells[j].Value.ToString();" Could you help me pls?
@radhikagharote1261
@radhikagharote1261 4 жыл бұрын
Same here . If you have found the solution please let me know
@shujanaqvi2668
@shujanaqvi2668 4 жыл бұрын
@@radhikagharote1261 anyone found it?
@radhikagharote1261
@radhikagharote1261 4 жыл бұрын
@@shujanaqvi2668 try this for loop: For(int i = 0; i
@shujanaqvi2668
@shujanaqvi2668 4 жыл бұрын
@@radhikagharote1261 oh its working thank you
@tanasitlikitchol5170
@tanasitlikitchol5170 2 жыл бұрын
@@radhikagharote1261 it works, thank you
@rasulvalipoor7125
@rasulvalipoor7125 2 жыл бұрын
It was greatly explained, thank you, how we use border on it
@mahmoudalhussain9291
@mahmoudalhussain9291 3 жыл бұрын
thanks for ur video , can u explain why you use type.missing more than one time ?
@ga7853
@ga7853 4 жыл бұрын
The Sound is very low, could not hear you even with my volume so high, you should play it yourself and see if you can hear it, but I was able to follow because the video was clear and you moved the mouse reasonably to follow.
@CsharpSpace
@CsharpSpace 4 жыл бұрын
Sorry for slow volume but now in my new videos volume is clear
@philipharrisona4496
@philipharrisona4496 6 жыл бұрын
worksheet = workbook.Sheets["Sheet1"]; worksheet = workbook.ActiveSheet; error in these lines Error 1 Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Excel._Worksheet'. An explicit conversion exists (are you missing a cast?) C:\Users\Dhivya\Desktop\FaceRecProOV\MakeRegistered.cs 105 25 MultiFaceRec
@liga_production
@liga_production 5 жыл бұрын
worksheet = workbook.Sheets[1]; Hope will help
@Ram7188
@Ram7188 5 жыл бұрын
@@liga_production I am facing the same issue but it not resolve yet. worksheet = workbook.Sheets[1]; worksheet = workbook.ActiveSheet;
@liga_production
@liga_production 5 жыл бұрын
@@Ram7188 hello. you may have already solved this problem, but here is my code. And it worked. (sry for my English. Check the code in the next post.)
@liga_production
@liga_production 5 жыл бұрын
@@Ram7188 if (dataGridView1.Rows.Count > 0) { Microsoft.Office.Interop.Excel.Application xcelApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workbook = xcelApp.Workbooks.Add(Type.Missing); Microsoft.Office.Interop.Excel.Worksheet worksheet = null; worksheet = workbook.Sheets[1]; worksheet = workbook.ActiveSheet; worksheet.Name = "CustomerDetail"; for (int i = 1; i < dataGridView1.Columns.Count + 1; i++) { worksheet.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText; } for (int i = 0; i < dataGridView1.Rows.Count; i++) { for (int j = 0; j < dataGridView1.Columns.Count; j++) { worksheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString(); } } xcelApp.Columns.AutoFit(); var saveFileDialoge = new SaveFileDialog(); saveFileDialoge.FileName = "Вывод"; saveFileDialoge.DefaultExt = ".xlsx"; if (saveFileDialoge.ShowDialog() == DialogResult.OK) { workbook.SaveAs(saveFileDialoge.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } xcelApp.Quit(); }
@simoneesposito2293
@simoneesposito2293 5 жыл бұрын
Ottimo good
@Tigrandav
@Tigrandav 4 жыл бұрын
Thank you for video, how can I expoert excel from datagridview with formating.
@MrLongAnimations
@MrLongAnimations 6 жыл бұрын
Thank you so much!! But you have video :"How to import excel to datagridview in c# windows application" ?
@noppawinsrikulchayanan3395
@noppawinsrikulchayanan3395 6 жыл бұрын
Thank you very much!!
@CsharpSpace
@CsharpSpace 6 жыл бұрын
+Noppawin SRIKULCHAYANAN welcome
@nguvanbachhoa3547
@nguvanbachhoa3547 5 жыл бұрын
I have problem in these lines: XLSaveAsAccessMode error : The type or namespace name 'XLSaveAsAccessMode' does not exist in the namespace 'Microsoft.Office.Interop.Excel' (are you missing an assembly reference?) CAN YOU HELP ME!
@CsharpSpace
@CsharpSpace 5 жыл бұрын
You need to add this reference(Microsoft.office.interope.Excel )in your project .
@techlife97415
@techlife97415 Жыл бұрын
worksheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString(); in here it says below problem. System.NullReferenceException: 'Object reference not set to an instance of an object.'
@CsharpSpace
@CsharpSpace Жыл бұрын
I think no data is present at this row and cell in dataGridView, So this error may occurred
@novifadhilah_f1411
@novifadhilah_f1411 6 ай бұрын
you can change it to --------> Convert.ToString(worksheet.Cells[i + 2, j + 1] = memberDataGridView.Rows[i].Cells[j].Value);
@moxmed5539
@moxmed5539 3 жыл бұрын
how to export only checked rows if there is checkbox
@King-Merlin
@King-Merlin 5 жыл бұрын
Hi iwanted to ask, is this also compatible with WPF gridview in C#
@kshitijsaxena8272
@kshitijsaxena8272 4 жыл бұрын
How to append the excel sheet data if excel is already existing
@sheetalkedar1156
@sheetalkedar1156 7 жыл бұрын
i want to save image to excel sheet using c# . any solution????? plz help ...!!
@surajshinde9258
@surajshinde9258 6 жыл бұрын
Thanks
@ganeshgavali9971
@ganeshgavali9971 6 жыл бұрын
Exception thrown: 'System.ArgumentOutOfRangeException' in mscorlib.dll
@reubenmwangikibara4434
@reubenmwangikibara4434 4 жыл бұрын
very great channel... would you minf helpin in exporting to pdf
@CsharpSpace
@CsharpSpace 4 жыл бұрын
ok I will upload in next video
@marlondumdumaya3409
@marlondumdumaya3409 6 жыл бұрын
hello, Im having a problem int the codes, "Object reference not set to an instance of an object." in "sheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString();"
@CsharpSpace
@CsharpSpace 6 жыл бұрын
+Marlon Dumdumaya I think something is missing in your code, try to debug your code with breakpoint
@marlondumdumaya3409
@marlondumdumaya3409 6 жыл бұрын
hello, my codes is now running, I just unchecked the properties of datagridview1 (enable delete, enable editing, enable adding) thats all. Thank You for reply :) have a good day
@marlondumdumaya3409
@marlondumdumaya3409 6 жыл бұрын
but another question, Can I add a progress bar on it? progress bar will serve as the process of exporting
@fadyemad5345
@fadyemad5345 5 жыл бұрын
@@marlondumdumaya3409 thanks you helped me
@CsharpSpace
@CsharpSpace 5 жыл бұрын
Welcome
@user-xg7hi5mh3g
@user-xg7hi5mh3g 4 жыл бұрын
thank you so much ,how i can check if the Sheet is empty or not
@CsharpSpace
@CsharpSpace 4 жыл бұрын
you can can count rows when you export excel.
@muhammadresturamadhan6129
@muhammadresturamadhan6129 4 жыл бұрын
my project is problem with the error code is : An unhandled exception of type 'System.InvalidCastException' at here > Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing); can you fix this problem as soon as possible ... thanks for ur tutorial :)
@user-ff1vr4bf9g
@user-ff1vr4bf9g 4 ай бұрын
what is wrong System. Argument Out of range Exception ?!
@cybelmaloon8397
@cybelmaloon8397 5 жыл бұрын
Sir, I have this error could you lend me a hand for this error "System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index' "
@CsharpSpace
@CsharpSpace 5 жыл бұрын
I think your have loop that goes outside datagrid view total column length
@cybelmaloon8397
@cybelmaloon8397 5 жыл бұрын
@@CsharpSpace Thanks a lot sir i already notice the error :D
@cybelmaloon8397
@cybelmaloon8397 5 жыл бұрын
and I already solve it thanks a lot to this video.
@lahcenjaber9901
@lahcenjaber9901 4 жыл бұрын
@@cybelmaloon8397 how do you slove it beo i have the same problem and i can't fix it
@md.nurulhuda9752
@md.nurulhuda9752 5 жыл бұрын
Do I can show a preview instead of direct save dialogue????
@aitezazbilal3796
@aitezazbilal3796 5 жыл бұрын
You can use the function app.visible = true, which will open the excel file without saving it. No need to do save dialogue part.
@martylofttv4871
@martylofttv4871 6 жыл бұрын
Hello, i have a problem. Where can i find the Microsoft Excel 15.0 Object Library. I'm using C# 2010 Express. My system has error. It says, Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX)) and the other one is Check the error code properly of the exception to determine the HRESULT returned by the COM object. Please help me. Thank you!
@CsharpSpace
@CsharpSpace 6 жыл бұрын
+samartino sta maria right click on reference and click to add reference and then it will popup reference manager, her you will select COM tab and select libraries now here you can find Microsoft Excel 15.0 Object library
@martylofttv4871
@martylofttv4871 6 жыл бұрын
Csharp Space i already click it but there is no microsoft excel 15.0 object library. I tried the other like microsoft office 15.0 object library but still the error is the same. If i dont have microsoft excel it is posible to download it? I look one by one into my COM but there is no microsoft excel sir. I hope you can help me. Thank you very much.
@CsharpSpace
@CsharpSpace 6 жыл бұрын
Check this link for reference : www.codeproject.com/Questions/587538/Howplustoplusaddplusmicrosoftplusexcelplus-plus
@martylofttv4871
@martylofttv4871 6 жыл бұрын
Csharp Space Ok, thank you very much
@CsharpSpace
@CsharpSpace 6 жыл бұрын
+samartino sta maria welcome
@KeijiJohnLibadisos
@KeijiJohnLibadisos 4 жыл бұрын
no microsoft.office in my VS
@rzikiyassir7402
@rzikiyassir7402 7 жыл бұрын
thank you so much for this video please i want import information from Excel to my database can you help me please and thanks again
@CsharpSpace
@CsharpSpace 7 жыл бұрын
yes how can I help you?
@rzikiyassir7402
@rzikiyassir7402 7 жыл бұрын
I have a file Excel filled with information and I would like to import this information to my database reverse what you've done in this video
@CsharpSpace
@CsharpSpace 7 жыл бұрын
You can find step to step description and Source code here: tutorialslink.com/Articles/How-to-import-excel-data-in-MS-SQL-server-database-in-Aspnet-MVC/1
@rzikiyassir7402
@rzikiyassir7402 7 жыл бұрын
thank you so so much, i wish you success (y)
@CsharpSpace
@CsharpSpace 7 жыл бұрын
welcome
@yeremiawijaya7456
@yeremiawijaya7456 4 жыл бұрын
why when i close the app it didnt stop debug??
@CsharpSpace
@CsharpSpace 4 жыл бұрын
I think app is still running in background
@GoodGuy374
@GoodGuy374 6 жыл бұрын
if you try to overwrite the name on same folder, it will show rewrite warning twice. :(
@CsharpSpace
@CsharpSpace 6 жыл бұрын
ok I will check
@toratoura3
@toratoura3 5 жыл бұрын
the code is not correct.
@luisafernandapinedadelaoss2173
@luisafernandapinedadelaoss2173 6 жыл бұрын
hola tengo un ERROR en esta linea de codigo HELP sheet.Cells [i + 2, j + 1] = dataGridView1.Rows [i] .Cells [j] .Value.ToString ();"
@lrobertj
@lrobertj 6 жыл бұрын
LUISA FERNANDA PINEDA DE LA OSSA tengo en mismo problema, pudiste corregirlo
@luisafernandapinedadelaoss2173
@luisafernandapinedadelaoss2173 6 жыл бұрын
si correo y envio codigo completo
@adamdante11
@adamdante11 6 жыл бұрын
I have the same error, can you send me a correct code?
@tanitalu
@tanitalu 6 жыл бұрын
tanialagosolmos@gmail.com no logro arreglar esta linea, favor ayudame :(
@juliocampos8085
@juliocampos8085 5 жыл бұрын
luisa responde por aca para que todos los que tengan ese error puedan solucionarlo
@richardmelvingarcia771
@richardmelvingarcia771 6 жыл бұрын
saves only 4 rows?
@CsharpSpace
@CsharpSpace 6 жыл бұрын
no this fetch all rows from datagridview
@juanfernandezbernt9105
@juanfernandezbernt9105 6 жыл бұрын
i have the same issue, only 4 rows are shown
@mirzamehran4017
@mirzamehran4017 5 жыл бұрын
@@CsharpSpace why
@TheWebjunky007
@TheWebjunky007 6 жыл бұрын
sound lvl is not very loud
@McNabbhead
@McNabbhead 6 жыл бұрын
Funny, I was thinking it was too quiet, especially because I had to turn the volume up after the ad that showed beforehand.
@TheWebjunky007
@TheWebjunky007 6 жыл бұрын
D1D2 i ment not very loud
@sarimkhan9459
@sarimkhan9459 4 жыл бұрын
Can you tell me how to save the file directly to desktop through code?
@CsharpSpace
@CsharpSpace 4 жыл бұрын
You can set path of your desktop location to output file
@neyleencaraballo9398
@neyleencaraballo9398 6 жыл бұрын
Thank you so much!!! But I need help with the next: " code : " worksheet = workbook.Sheets["Sheet1"];" present the next error"Additional information: El índice no es válido. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))".
@egordavidovich7276
@egordavidovich7276 6 жыл бұрын
you fixsed this bag?
@guilhermequirino4593
@guilhermequirino4593 6 жыл бұрын
Use index instead: workSheet = workBook.Sheets[1];
@Jvkomusic
@Jvkomusic 6 жыл бұрын
Lo resolviste?
@shehzadbhatti1361
@shehzadbhatti1361 5 жыл бұрын
Hey Bro, I'm having this issue "System.NullReferenceException: 'Object reference not defined for an instance of an object. System.Windows.Forms.DataGridViewCell.Value.get retorned null." in this line "worksheet.Cells[i+2,j+1] = produtoDataGridView.Rows[i].Cells[j].Value.ToString();" Could you help me pls?
@shehzadbhatti1361
@shehzadbhatti1361 5 жыл бұрын
i found the error thanks
@CsharpSpace
@CsharpSpace 5 жыл бұрын
try to debug the code and find the value for i variable, I think it going outside range.
@user-zx5pm2rv4h
@user-zx5pm2rv4h 5 жыл бұрын
@@shehzadbhatti1361 how u solved, tell me?
@ShalukaHettiarachchi
@ShalukaHettiarachchi 5 жыл бұрын
@@user-zx5pm2rv4h try this for second for loop -> for (int i = 0; i < dataGridView1.Rows.Count-1; i++)
Export DataGridView To Excel In c# Windows Application Step By Step
12:17
C# Tutorial - Generate Excel Report in C# | FoxLearn
10:07
Fox Learn
Рет қаралды 14 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН
لااا! هذه البرتقالة مزعجة جدًا #قصير
00:15
One More Arabic
Рет қаралды 52 МЛН
When you discover a family secret
00:59
im_siowei
Рет қаралды 15 МЛН
Fortunately, Ultraman protects me  #shorts #ultraman #ultramantiga #liveaction
00:10
Introducing Python in Excel
19:01
Leila Gharani
Рет қаралды 1,5 МЛН
Intro to the CsvHelper Library for C#
27:12
IAmTimCorey
Рет қаралды 26 М.
Export Data to Excel File | C# | WinForms
16:18
How To 365
Рет қаралды 2,1 М.
Load Data From Excel to DataGridView in C# Windows Form Application
9:09
How to write Excel files in C#
7:20
Darren Does Everything
Рет қаралды 31 М.
Export DataGridView Data to Excel in C#
2:22
Tk CODE
Рет қаралды 6 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН