Hi Everyone,
I have datagridview in that 17 columns are text columns and 5 columns are Image columns,when I'm trying to export whole gridview data's along with images to EXCEL,getting "HRESULT: 0x800A03EC" Error..While debugging the code I'm getting the error on image column not able to export..
Can anybody help us to resolve this issue..
Here is my code which i used: - private void btnexportexcel_Click(object sender, EventArgs e)
-
{
-
try
-
{
-
SaveFileDialog savefile = new SaveFileDialog();
-
savefile.Filter = "Excel (*.xls)|*.xls";
-
if (savefile.ShowDialog() == DialogResult.OK)
-
{
-
if (!savefile.FileName.Equals(string.Empty))
-
{
-
FileInfo finfo = new FileInfo(savefile.FileName);
-
if (finfo.Extension.Equals(".xls"))
-
{
-
Excel.Application xlApp;
-
Excel.Workbook xlWorkBook;
-
Excel.Worksheet xlWorkSheet;
-
object misValue = System.Reflection.Missing.Value;
-
-
xlApp = new Excel.Application();
-
xlWorkBook = xlApp.Workbooks.Add(misValue);
-
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);
-
int i = 0;
-
int j = 0;
-
-
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
-
{
-
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
-
{
-
DataGridViewCell cell = dataGridView1[j, i];
-
xlWorkSheet.Cells.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
-
xlWorkSheet.Columns.AutoFit();
-
-
if (cell.Value.GetType() == typeof(Bitmap))
-
{
-
string image =Convert.ToString(dataGridView1.CurrentRow.Cells[i].Value);
-
Excel.Range oRange = (Excel.Range)xlWorkSheet.Cells[i + 1, j + 1];
-
float Left = (float)((double)oRange.Left);
-
float Top = (float)((double)oRange.Top);
-
const float ImageSize = 32;
-
xlWorkSheet.Shapes.AddPicture(image, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, ImageSize, ImageSize);
-
oRange.RowHeight = ImageSize + 2;
-
}
-
else
-
{
-
xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
-
}
-
-
}
-
}
-
-
xlWorkBook.SaveAs(savefile.FileName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue,
-
Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
-
xlWorkBook.Close(true, misValue, misValue);
-
xlApp.Quit();
-
-
releaseObject(xlWorkSheet);
-
releaseObject(xlWorkBook);
-
releaseObject(xlApp);
-
-
MessageBox.Show("Excel file created , you can find the file " + savefile.FileName);
-
-
}
-
else
-
{
-
MessageBox.Show("Invalid file type");
-
}
-
}
-
else
-
{
-
MessageBox.Show("You did pick a location " + "to save file to");
-
}
-
}
-
}
-
-
catch (Exception ex)
-
{
-
MessageBox.Show("Exception Occured", ex.Message);
-
}
-
}
0 2025 Sign in to post your reply or Sign up for a free account.
Similar topics
by: chemdawg |
last post by:
I"m Having a problem Sharing data between access Microsoft® Excel. I
need to populate the databases in a flash by linking and updating the
excel sheets.
|
by: michb |
last post by:
I need to export data from access to an excel database to calculate times and wages for the week but the code
that I entered doesn't seem to like either me or the database!
I need it to go to one...
|
by: bienwell |
last post by:
Hi,
I have a question about exporting data from datagrid control into Excel file
in ASP.NET. On my Web page, I have a linkbutton "Export data". This link
will call a Sub Function to perform...
|
by: Sridhar |
last post by:
Hi,
I am having trouble renaming the excel sheet while exporting to excel.
we have a datagrid that contains some analytical data. I have the name to the
excel file as "temp.xls" inside the code....
|
by: jonas |
last post by:
I have a series of arrays that I would like to send to excel for display and processing
After spending most of the evening google I cant find anything out there that gives an example to what I...
|
by: deedi |
last post by:
Hi,
I've a problem with exporting my query results into excel. When the rows returned are less, export to excel is happening without any issues. When there is large number of rows, IE is...
|
by: lenniekuah |
last post by:
Hi Friends,
I need your help. Please help me.
I am trying to retrieve data from Excel Spreadsheet to fill the DataGridView for display prior to updating SQL SERVER with individual DataGridView...
|
by: balaji04 |
last post by:
Hi,
I've a problem with exporting my query results into excel. When the rows returned are less, export to excel is happening without any issues. When there is large number of rows, IE is showing...
|
by: leelaprasad9999 |
last post by:
hi i'm trying to export datagridview data with image to excel , i'm using the below code, but image cannot be displayed.
Microsoft.Office.Interop.Excel.Application ExcelApp = new...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |