locked
Load Datagrid with Excel file in Windows Mobile6.0 RRS feed

  • Question

  • Hello,

    I am developing a windows mobile application  . Is it possible to load an datagrid which is inside an windows mobile6.0 with excel file.
    Tuesday, December 8, 2009 10:03 AM

All replies

  • Hi Siva,


    I have seen your same query here. Did it not solve your problem?

    http://social.msdn.microsoft.com/Forums/en-US/windowsmobiledev/thread/24236d19-bdf2-4986-b95f-9a61b4d09946


    Regards,
    Malleswar
    Tuesday, December 8, 2009 11:09 AM
  • Hi Malleswar,


    Yes i did according to your previous reply and links where usefull for me.I did something like this,

    first i created a excel file and then loaded all the data present in grid into excel file,after this i need to print this excel file,but intially windows mobile6.0

    does not support print option.

    But now i got some idea Excel mobile which is present in Windows mobile provides an option for save as so now i can save it into my local machine and then use interop
    and give for printing.

    But some issues are there while exporting the grid data into excel file i am not able to get column values i mean only column headers  are mapping text inside the column headers is not loading.



    Regards,

    Tuesday, December 8, 2009 1:54 PM
  • Hi, here i am exporting datagrid data into excel file
    private void Print_Click(object sender, EventArgs e) 
    { DataTable datatable = new DataTable();
     datatable = (DataTable)gridList.DataSource;
     Excel.Application xlApp; 
    Excel.Workbook xlWorkBook;
     Excel.Worksheet xlWorkSheet; 
    object misValue = System.Reflection.Missing.Value; 
    xlApp = new Excel.ApplicationClass(); 
    xlWorkBook = xlApp.Workbooks.Add(misValue); 
    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); 
    int i , j = 0;
     for (i = 0; i <= datatable.Rows.Count-1; i++) 
    { 
    for (j = 0; j <= datatable.Columns.Count - 1; j++)
     { gridList.DataSource = datatable;
     DataGridCell cell =(DataGridCell) gridList[j, i];
     xlWorkSheet.Cells[i + 1, j + 1] = cell;
     } } 
    xlWorkBook.SaveAs(@"C:\My Documents\Excel Files\Book1.XLS", 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 c:\\order.xls"); }
     private void releaseObject(object obj)
     { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
     obj = null;
     } } 

    But on click of this event i am getting an exception in this line
    xlApp = new Excel.ApplicationClass(); as COM object with CLSID '{00024500-0000-0000-C000-000000000046}' cannot be created due to the following error: Class not registered . I have gone this link and tried to solve this exception but still i get the same exception "http://blog.crowe.co.nz/archive/2006/03/02/589.aspx" .I am Working in Windows 2003 server and Microsoft Excel 2007
    Wednesday, December 9, 2009 10:49 AM