Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
K

KaurGurpreet

@KaurGurpreet
About
Posts
33
Topics
13
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Context help in silverlight 4
    K KaurGurpreet

    Hi, I am using silverlight 4. How can i display context sensitive help?

    Gurpreet

    WPF question help

  • Com Exception - excel
    K KaurGurpreet

    Yes setting it back restores the behaviour but while export process is on... it is not good that any other excel file cannot be acessed.

    Gurpreet

    C# com

  • Com Exception - excel
    K KaurGurpreet

    Finally some solution which works :) But still while my code is executing, I cannot open any other excel file... which is not good :( If I look at the behaviour of Visual Studio (when I export my work list to excel), it works perfectly fine... no error and I can open the other excel too... So whats wrong with my code... Is there any other better way to export?

    Gurpreet

    C# com

  • Com Exception - excel
    K KaurGurpreet

    I tried like below but it does not solve the problem :(

    _objWorkSheet.Cells[row, column] = cell1;

    Gurpreet

    C# com

  • Com Exception - excel
    K KaurGurpreet

    Oh! But I am getting this evevytime i try to do so My environment is: Visual Studio 2010 Excel - 2008 Here is the detailed error:

    System.Runtime.InteropServices.COMException (0x800AC472): Exception from HRESULT: 0x800AC472
    at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
    at Microsoft.Office.Interop.Excel.Range.set_Value2(Object )
    at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in c:\documents and settings\kaurrgur\my documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 77
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    Gurpreet

    C# com

  • Com Exception - excel
    K KaurGurpreet

    I tried... but I still get the same error (exception from HRESULT: 0x800AC472) While the code in for loop is executing, you need to open any other excel file and click on randon cells.

    Gurpreet

    C# com

  • Com Exception - excel
    K KaurGurpreet

    Exception from HRESULT: 0x800AC472

    Gurpreet

    C# com

  • Com Exception - excel
    K KaurGurpreet

    A simple code to export data to excel

    public partial class Form1 : Form
    {

    Microsoft.Office.Interop.Excel.Application \_objAppln;
    Workbook \_objWorkBook;
    Workbooks \_objWorkBooks;
    Worksheet \_objWorkSheet;
    
    
    public Form1()
    {
      InitializeComponent();
      InitializeExcelObjectModel();
    }
    
    ~Form1()
    {
      DisposeExcelObjects();
    }
    
    void SaveExcel()
    {
    
      \_objAppln.DisplayAlerts = false;//Since, we are using SaveFileDialog's overwrite prompt(control is on view). 
      
      \_objWorkBook.SaveAs("C:\\\\tmp.xls",
        XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, false, Type.Missing, XlSaveAsAccessMode.xlNoChange,
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
      \_objWorkBook.Close(true, "C:\\\\tmp.xls", false);
      \_objAppln.DisplayAlerts = true;//restore back for other display alerts 
    }
    
    private void InitializeExcelObjectModel()
    {
    
      \_objAppln = new Microsoft.Office.Interop.Excel.Application(); // To initialize excel file   
      //\_objAppln.Visible = true; 
      if (\_objAppln != null)
      {
        \_objWorkBooks = \_objAppln.Workbooks;
        \_objWorkBook = \_objWorkBooks.Add(Type.Missing); // To add workbook with sheets in excel file         
        \_objWorkSheet = (Worksheet)\_objAppln.ActiveSheet; // To get the current active sheet in excel file              
    
      }
    }
    
    public void DisposeExcelObjects()
    {
    
      System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkSheet);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkBook);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkBooks);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objAppln);
      \_objWorkSheet = null; \_objWorkBooks = null; \_objWorkBooks = null; \_objAppln = null;
    }
    
    private void button1\_Click(object sender, EventArgs e)
    {
    
      Range objRange=null;
      string cell1 = string.Empty, cell2 = string.Empty;
      string\[\] chars = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T" };
    
    
      for (int row = 1; row < 1000; row++)
      {
        for (int column = 0; column < 20; column++)
        {
          cell1 = chars\[column\] + row.ToString();
          objRange = \_objWorkSheet.get\_Range(cell1, cell1);
          objRange.Value2 = cell1;
          
          
        }
      }
      System.Runtime.Int
    
    C# com

  • Excel Exception from HRESULT: 0x800AC472
    K KaurGurpreet

    I have created a simple application to show the problem:

    namespace WindowsFormsApplication1
    {
    public partial class Form1 : Form
    {

    Microsoft.Office.Interop.Excel.Application \_objAppln;
    Workbook \_objWorkBook;
    Workbooks \_objWorkBooks;
    Worksheet \_objWorkSheet;
    
    
    public Form1()
    {
      InitializeComponent();
      InitializeExcelObjectModel();
    }
    
    ~Form1()
    {
      DisposeExcelObjects();
    }
    
    void SaveExcel()
    {
    
      \_objAppln.DisplayAlerts = false;//Since, we are using SaveFileDialog's overwrite prompt(control is on view). 
      
      \_objWorkBook.SaveAs("C:\\\\tmp.xls",
        XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, false, Type.Missing, XlSaveAsAccessMode.xlNoChange,
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
      \_objWorkBook.Close(true, "C:\\\\tmp.xls", false);
      \_objAppln.DisplayAlerts = true;//restore back for other display alerts 
    }
    
    private void InitializeExcelObjectModel()
    {
    
      \_objAppln = new Microsoft.Office.Interop.Excel.Application(); // To initialize excel file   
      //\_objAppln.Visible = true; 
      if (\_objAppln != null)
      {
        \_objWorkBooks = \_objAppln.Workbooks;
        \_objWorkBook = \_objWorkBooks.Add(Type.Missing); // To add workbook with sheets in excel file         
        \_objWorkSheet = (Worksheet)\_objAppln.ActiveSheet; // To get the current active sheet in excel file              
    
      }
    }
    
    public void DisposeExcelObjects()
    {
    
      System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkSheet);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkBook);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkBooks);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objAppln);
      \_objWorkSheet = null; \_objWorkBooks = null; \_objWorkBooks = null; \_objAppln = null;
    }
    
    private void button1\_Click(object sender, EventArgs e)
    {
      string cell1 = string.Empty, cell2 = string.Empty;
      string\[\] chars = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T" };
    
    
      for (int row = 1; row < 1000; row++)
      {
        for (int column = 0; column < 20; column++)
        {
          cell1 = chars\[column\] + row.ToString();
          Range objRange = \_objWorkSheet.get\_Range(cell1, cell1);
          objRange.Value2 = cell1;
          System.Runtime.Interop
    
    C# help csharp

  • Excel Exception from HRESULT: 0x800AC472
    K KaurGurpreet

    Excel Exception from HRESULT: 0x800AC472 I am exporting data to excel thru C# code. while export is in progress, if I open any excel file (not necessariliy the one being created), I get the above error. Earlier I was exporting on a background thread, but after reading various comments on google, I removed the background thread but the problem still exists.

    Gurpreet

    C# help csharp

  • how to destroy window handle
    K KaurGurpreet

    I do not want to show them all at once. At a time say 100 are visible but after the user changes the input I need to show other 100. But how do a ensure that the handle is destroyed for previous ones?

    Gurpreet

    C# question help tutorial

  • how to destroy window handle
    K KaurGurpreet

    I have a user control (composed of 10 text boxes). on certain user inputs -> multiple rows of above user control are added to a form. After certain amount of operation, I start getting error - cannot create window handle. How do I need to clear window handle? Shouldn't it be automatically disposed?

    Gurpreet

    C# question help tutorial

  • Locking excel file while writing
    K KaurGurpreet

    I need to add rows to that sheet. How can I change it to readonly?

    Gurpreet

    C# tutorial

  • Locking excel file while writing
    K KaurGurpreet

    No I am not using file stream. This is how I open and use _objAppln = new Excel.Application(); // To initialize excel file //_objAppln.Visible = true; if (_objAppln != null) { _objWorkBooks = _objAppln.Workbooks; _objWorkBook = _objWorkBooks.Add(Type.Missing); // To add workbook with sheets in excel file _objWorkSheet = (Excel.Worksheet)_objAppln.ActiveSheet; // To get the current active sheet in excel file .... Excel.Range objRange = _objWorkSheet.get_Range(columnName + _currentRowIndex, LastColumnName + _currentRowIndex); objRange.Value2 = GroupName; ... _objWorkBook.SaveAs(_fileName, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, false, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

    Gurpreet

    C# tutorial

  • Locking excel file while writing
    K KaurGurpreet

    I need to support Office 2005 as well so MultiUserEditing flag will not help. also MultiUserEditing is readonly property so I cannot set it :( Also, protection property will not help in this case :(

    Gurpreet

    C# tutorial

  • Locking excel file while writing
    K KaurGurpreet

    Hi all, I need to know how to either prevent anyone from open an excel file when it's open by my application and written to or only let the file being opened write-protected during the write session.

    Gurpreet

    C# tutorial

  • Securing a web method
    K KaurGurpreet

    Could you provide me some example / code snippet to do that.

    Gurpreet

    C# question

  • Image on specific tree node
    K KaurGurpreet

    I am looking for showing image only on specific node. That does not work in this way. It shows image for all nodes or none.

    Gurpreet

    C# question data-structures

  • Image on specific tree node
    K KaurGurpreet

    In the treeview, I want to display an image only on few nodes (not all). How do I do this?

    Gurpreet

    C# question data-structures

  • Installing web service on windows 2008
    K KaurGurpreet

    I am getting the following error while installing the web service on windows 2008 server: "Error 1001. Error executing command. No mapping between account names and security id" The installer works perfect on windows 2003 server. I have migrated my installer from visual studio 2005 to VS 2010.

    Gurpreet

    C# visual-studio csharp sysadmin security help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups