How to export datagridview to excel in c# windows application

Поділитися
Вставка
  • Опубліковано 1 гру 2024

КОМЕНТАРІ • 117

  • @vietthole7217
    @vietthole7217 5 років тому +1

    I made it. Thanks bro.😍👍

  • @motivation9822
    @motivation9822 4 роки тому +1

    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

  • @jackhuynh9847
    @jackhuynh9847 2 роки тому

    Thank you very much, it worked!

  • @WhiteCoder
    @WhiteCoder Рік тому

    Thank You So Much....

  • @alawal_kabir
    @alawal_kabir 3 роки тому

    Nice Tutorial. Thanks a lot.

  • @alejandromonroy8726
    @alejandromonroy8726 5 років тому +1

    Thank you so much , it worked :)

  • @pauloherculano9243
    @pauloherculano9243 6 років тому +2

    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 роки тому +1

    Only the the first column name is visible other columns are not visible
    But the rows are visible

  • @mahmoudalhussain9291
    @mahmoudalhussain9291 3 роки тому

    thanks for ur video ,
    can u explain why you use type.missing more than one time ?

  • @KaS95PeR
    @KaS95PeR Рік тому

    thanks man!

  • @ga7853
    @ga7853 5 років тому

    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  5 років тому

      Sorry for slow volume but now in my new videos volume is clear

  • @nadunsilv
    @nadunsilv 5 років тому +1

    It works thank you, bro!!

  • @thonginh5082
    @thonginh5082 4 роки тому

    thank you for this video

  • @Tigrandav
    @Tigrandav 4 роки тому

    Thank you for video, how can I expoert excel from datagridview with formating.

  • @rasulvalipoor7125
    @rasulvalipoor7125 2 роки тому

    It was greatly explained, thank you, how we use border on it

  • @philipharrisona4496
    @philipharrisona4496 6 років тому +1

    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 років тому +1

      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 років тому +3

      @@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();

      }

  • @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 років тому +1

      You need to add this reference(Microsoft.office.interope.Excel )in your project .

  • @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 :)

  • @MrLongAnimations
    @MrLongAnimations 7 років тому

    Thank you so much!! But you have video :"How to import excel to datagridview in c# windows application" ?

  • @kshitijsaxena8272
    @kshitijsaxena8272 5 років тому

    How to append the excel sheet data if excel is already existing

  • @King-Merlin
    @King-Merlin 5 років тому

    Hi iwanted to ask, is this also compatible with WPF gridview in C#

  • @انامسلموكفى
    @انامسلموكفى 5 років тому

    thank you so much ,how i can check if the Sheet is empty or not

    • @CsharpSpace
      @CsharpSpace  5 років тому

      you can can count rows when you export excel.

  • @sheetalkedar1156
    @sheetalkedar1156 7 років тому

    i want to save image to excel sheet using c# . any solution????? plz help ...!!

  • @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

  • @moxmed5539
    @moxmed5539 3 роки тому

    how to export only checked rows if there is checkbox

  • @Artlife97415
    @Artlife97415 2 роки тому +1

    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  2 роки тому

      I think no data is present at this row and cell in dataGridView, So this error may occurred

    • @novifadhilah_f1411
      @novifadhilah_f1411 9 місяців тому

      you can change it to --------> Convert.ToString(worksheet.Cells[i + 2, j + 1] = memberDataGridView.Rows[i].Cells[j].Value);

  • @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 6 років тому

      @@marlondumdumaya3409 thanks you helped me

    • @CsharpSpace
      @CsharpSpace  6 років тому

      Welcome

  • @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.

  • @noppawinsrikulchayanan3395
    @noppawinsrikulchayanan3395 7 років тому

    Thank you very much!!

    • @CsharpSpace
      @CsharpSpace  7 років тому

      +Noppawin SRIKULCHAYANAN welcome

  • @cybelmaloon8397
    @cybelmaloon8397 6 років тому

    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  6 років тому

      I think your have loop that goes outside datagrid view total column length

    • @cybelmaloon8397
      @cybelmaloon8397 6 років тому

      @@CsharpSpace Thanks a lot sir i already notice the error :D

    • @cybelmaloon8397
      @cybelmaloon8397 6 років тому +1

      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

  • @GoodGuy374
    @GoodGuy374 6 років тому

    if you try to overwrite the name on same folder, it will show rewrite warning twice. :(

  • @simoneesposito2293
    @simoneesposito2293 5 років тому

    Ottimo good

  • @kiraroria
    @kiraroria 4 роки тому

    why when i close the app it didnt stop debug??

    • @CsharpSpace
      @CsharpSpace  4 роки тому

      I think app is still running in background

  • @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 6 років тому

      luisa responde por aca para que todos los que tengan ese error puedan solucionarlo

  • @ganeshgavali9971
    @ganeshgavali9971 6 років тому

    Exception thrown: 'System.ArgumentOutOfRangeException' in mscorlib.dll

  • @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 років тому +1

      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 років тому +1

      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

  • @surajshinde9258
    @surajshinde9258 6 років тому

    Thanks

  • @KeijiJohnLibadisos
    @KeijiJohnLibadisos 4 роки тому

    no microsoft.office in my VS

  • @richardmelvingarcia771
    @richardmelvingarcia771 6 років тому

    saves only 4 rows?

  • @toratoura3
    @toratoura3 5 років тому

    the code is not correct.

  • @sarimkhan9459
    @sarimkhan9459 5 років тому

    Can you tell me how to save the file directly to desktop through code?

    • @CsharpSpace
      @CsharpSpace  5 років тому

      You can set path of your desktop location to output file

  • @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

  • @NasrAlmasqari
    @NasrAlmasqari 7 місяців тому

    what is wrong
    System. Argument Out of range Exception
    ?!

  • @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))".

  • @shehzadbhatti1361
    @shehzadbhatti1361 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?

    • @shehzadbhatti1361
      @shehzadbhatti1361 6 років тому

      i found the error thanks

    • @CsharpSpace
      @CsharpSpace  6 років тому

      try to debug the code and find the value for i variable, I think it going outside range.

    • @نجودخالد-ك1ذ
      @نجودخالد-ك1ذ 6 років тому

      @@shehzadbhatti1361 how u solved, tell me?

    • @ShalukaHettiarachchi
      @ShalukaHettiarachchi 5 років тому +1

      @@نجودخالد-ك1ذ try this for second for loop -> for (int i = 0; i < dataGridView1.Rows.Count-1; i++)