 |
|
 |
please send me a zip file? i want to see how it works..
thanks your information.
|
|
|
|
 |
|
|
 |
|
 |
Good Morning,
The reason I have prefaced this with "again" is that although I have found numerous articles on this in Code Project, I have yet to see this problem resolved with a clear answer or a suggestion as to what the problem might be (or I cannot find it). So, it's my turn in the barrel...I am trying to add an Excel reference (seems simple enough) to my application (VS 2010), and I have tried to add it from both the .NET (Microsoft.Office.Excel) and COM tabs (Microsoft.Office.Interop.Excel) under Add Reference. I have tried each individually and both simultaneously and each time I get the familiar error (Error 1 The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?). This was done as per the instructions of a great article on Code Project by Geek13 that begins with the code
Excel.ApplicationClass ExcelApp = new Excel.ApplicationClass();
The article heading is as follows:
Exporting a DataGridView to Excel in .NET 2.0 (C# code)
Author: Geek13
If there is some other prerequisite that I need or (???), please let me know. Thank you for your attention....Pat
|
|
|
|
 |
|
 |
I cannot find this to add the reference. The closest I have is Microsoft Office 12.0 Object Libary. Doesn't seem to work.
When trying to create an object of the ApplicationClass in the Excel namespace as you show -
Excel.ApplicationClass ExcelApp = new Excel.ApplicationClass();
i get this error:
"The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?)"
i am a beginer and this is my first code.
please help,
thanks, Boosh.
|
|
|
|
 |
|
 |
I Used This Code But It Does Not Transfers The Data Of My DataGrid View It Just Tranfers The Rows and Columns Of My DataGrid View.
|
|
|
|
 |
|
 |
Try using :
ExcelApp.Cells[i+1, j+1] = row.Cells[j].FormattedValue.ToString();
instead of:
ExcelApp.Cells[i+1, j+1] = row.Cells[j].ToString();
DaveTheCaver
|
|
|
|
 |
|
|
 |
|
 |
Please elaborate which technology!
|
|
|
|
 |
|
 |
It's very usefull!
Another c#/VB.net excel component Spire.XLS,I wish it may inspire you more.
|
|
|
|
 |
|
 |
pclion
|
|
|
|
 |
|
 |
el codigo fue perfecto para lo que necesitaba, pero tuve que hacer una dos pequeñas correcciones
en row.Cell[j].ToString() lo reemplace por value, y tuve que poner un control para los valores nulos.
y en mi caso particular elegi como directorio para guardar el archivo el desktop.
Aca dejo el codigo completo:
private void ExportToExcel()
{
ApplicationClass appExcel = new ApplicationClass();
appExcel.Application.Workbooks.Add(Type.Missing);
appExcel.Columns.ColumnWidth = 50;
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
DataGridViewRow row = dataGridView1.Rows[i];
for (int j = 0; j < row.Cells.Count; j++)
{
if (row.Cells[j].Value == null)
appExcel.Cells[i + 1, j + 1] = "";
else
appExcel.Cells[i + 1, j + 1] =row.Cells[j].Value.ToString();
}
}
string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
appExcel.ActiveWorkbook.SaveCopyAs(folder+"\\ListaViajes.xls");
appExcel.ActiveWorkbook.Saved = true;
appExcel.Application.Quit();
}
|
|
|
|
 |
|
 |
hello
I have used Office 12.0
Add Reference:
Microsoft Excel 12.0 Object Library
Microsoft Office 12.0 Object Library
but:
in this line of code:
ExcelApp.Application.Workbooks.Add(Type.Missing);
error:
Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
can any one help me ?
|
|
|
|
 |
|
 |
step1 :
- C:\Program Files\Microsoft Office\OFFICE11 copy file excel.exe to C:\Program Files\Microsoft Office\OFFICE11\1033 and replace with xllex.dll
step 2: run again app
have fun!
|
|
|
|
 |
|
 |
I don't have the file excel.exe in the library "C:\Program Files\Microsoft Office\OFFICE11"
what i need to do?
|
|
|
|
 |
|
 |
may be error for not set Culture in en-US.
for solve use:
1) Befor any thing set Culture for en-US like :
CultureInfo oldCI = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
2) Do any things!
3) Return to old Culture
if(oldCI != null)
Thread.CurrentThread.CurrentCulture = oldCI;
|
|
|
|
 |
|
 |
I found it informative as another way of handling things. Yes you need excel, however that was the part of article was transporting information from Grid to Excel. For those that marked it a 1 or a 2, the Article served it's perpose.
/////////////////
Groucho Marx
Those are my principals, if you don't like them… I have others.
|
|
|
|
 |
|
 |
The code works fine, but when I open the file that was saved, two Excel workbooks open - one with the name I supplied and the other with a name given by Excel. The two workbooks have identical data. How can I make that only one workbook is created?
|
|
|
|
 |
|
 |
Actually i did not get this problem.. Can you tell me exactly what you tried to do??
|
|
|
|
 |
|
 |
I wanted the headers and I am not a big fan of the i/j loops so I went with this instead:
foreach (DataGridViewColumn column in ReportDataGridView.Columns)
{
excelApp.Cells(1, column.Index + 1) = column.HeaderText;
}
foreach (DataGridViewRow row in ReportDataGridView.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
excelApp.Cells(cell.RowIndex + 2, cell.ColumnIndex + 1) = cell.Value.ToString;
}
}
|
|
|
|
 |
|
 |
I cannot find this to add the reference. The closest I have is Microsoft Office 12.0 Object Libary. Doesn't seem to work. Please help.
|
|
|
|
 |
|
 |
Hi Kim,
Which version of .net you are using? MS Office 12.0 object library should also work i think. What is the problem you are facing?
|
|
|
|
 |
|
 |
Also you can need 'Microsoft.Office.Interop.Excel' from '.NET' tab
|
|
|
|
 |
|
 |
i have the same problem.
i add the ‘Microsoft Office 11.0 Object Library’ reference and the Microsoft.Office.Interop.Excel and when i try to write 'Excel.ApplicationClass' the visual c# mark it like it is an error.
do i need to add 'Using'?
help please.
Boosh
|
|
|
|
 |
|
 |
This solution is very slow for more than 5000 rows
|
|
|
|
 |
|
 |
You should check this solution: http://www.codeproject.com/KB/office/FastExcelExporting.aspx
|
|
|
|
 |