VB.NET Tutorial - How to Export DataGridView to excel | FoxLearn

VB.NET Tutorial - How to Export DataGridView to excel | FoxLearn

Fox Learn

3 года назад

37,446 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Tuan Nguyen
Tuan Nguyen - 18.08.2023 01:11

I am using Visual studio 2022
I have this
Using workbook As XLWorkbook = New XLWorkbook
workbook.Worksheets.Add(Me.DataGridView1.DataSource, "NameOfSheetInExcel")
workbook.SaveAs(sfd.FileName)
and it says workbook is not defined. and and it does not know what XLWorkbook is. It suggests to change to ExcelWorkbook but that still does not work. I do have Imports Excel Interloop.
Please help

Ответить
Abhay Mohite
Abhay Mohite - 05.01.2023 18:24

In my case i am not getting any search results for closedxml package in package manager. What should I do?

Ответить
Hassan DAMIRI
Hassan DAMIRI - 02.11.2022 21:10

Thanks a lot
I'm extremely grateful

Ответить
Владимир Лионов
Владимир Лионов - 04.10.2022 10:12

Спасибо большое! Очень благодарен 😊

Ответить
Jim Man.
Jim Man. - 08.08.2022 21:08

Thank you so much!!!

Ответить
nice0kid
nice0kid - 21.06.2022 11:03

C# Cdoe :)


using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "Excel Workbook|*.xlsx" })
{
if (sfd.ShowDialog() == DialogResult.OK)
{
try
{

////This To get from gridview after meniplation
DataTable dt = new DataTable();
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
dt.Columns.Add(col.Name);
}

foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataRow dRow = dt.NewRow();
foreach (DataGridViewCell cell in row.Cells)
{
dRow[cell.ColumnIndex] = cell.Value;
}
dt.Rows.Add(dRow);
}

using (XLWorkbook workbook = new XLWorkbook())
{
workbook.Worksheets.Add(dt,"Employee Report");
workbook.SaveAs(sfd.FileName);
}

MessageBox.Show("You have successfully exported your data to an excel file.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

}

Ответить
DEBESMSCAT TV
DEBESMSCAT TV - 12.05.2022 14:58

hi, I'm using SQL server and when I print the excel file there is no data on it. Can you help me solve this, please?

Ответить
Hajar
Hajar - 24.04.2022 20:36

the file downloaded is emty. whhhy ??

Ответить
trekvrx400
trekvrx400 - 21.03.2022 00:40

Hi thks for this tutorial, but is not working to me, is saying that XLWorkbook is not defined

Ответить
Robin San Diego
Robin San Diego - 31.12.2021 04:16

Hi there, thanks for this tutorial. Just a quick question, how do we export data for filtered searched populating in the datagridview?

Ответить
Randa El Guenouni
Randa El Guenouni - 07.09.2021 19:07

please what if the collumn of the datagridview are created manually what do we write inside the worksheets.add ()

Ответить
Victor Joaquín
Victor Joaquín - 13.12.2020 04:41

Falto que exporte el titulo

Ответить
Eduardo Bonilla
Eduardo Bonilla - 11.12.2020 18:53

Hi Thanks for this tutorial, do you know any way to do this on .NET 5 thanks

Ответить
Ahmad Ridho Syaugi
Ahmad Ridho Syaugi - 11.12.2020 15:30

How if using mc access data base And export to excel ?

Ответить
Sami Dool
Sami Dool - 11.12.2020 13:50

Did u stop publishing c#

Ответить
Dominik R
Dominik R - 11.12.2020 09:08

Finally vb .net

Ответить