Change the Excel icon

Asked

Viewed 138 times

1

Hello, I start apologizing, I’m not from C or C++, but I really need a help that can be given by as much as the other, I work with Excel solutions modeling the XML interface, I created an application and I’m using an executable in C to openla, this already cuts that initial presentation of Microsoft Excel and the focus goes back to my system, but I would like to customize completely, for this, I would like the executable besides opening the spreadsheet also modified its icon, so that the icon that appears in the taskbar is the symbol of my application, if anyone can help me I am very grateful, follow the code I used to create the executable:

using System; 
using System.Collections.Generic; 
using System.Reflection; 
using System.Threading; 
using System.Windows.Forms; 

static class Program 
{ 
// variáveis de instãncia 
static object oExcel = null; 
static object oBooks = null; 
static object oBook = null; 
static object oMissing = System.Reflection.Missing.Value; 
static System.Globalization.CultureInfo ci = Thread.CurrentThread.CurrentCulture; 

[STAThread] 
static void Main() 
{ 
    string CaminhoDoArquivo = @"C:\Caminho\Para\Seu\Arquivo\Excel\ExcelComMacros.xlsm"; 

    if (ExcelEstaInstalado()) 
    { 
        try 
        { 
            if (System.IO.File.Exists(CaminhoDoArquivo)) 
            { 
                AbrirArquivo(CaminhoDoArquivo); 
            } 
            else 
            { 
                MessageBox.Show(string.Format("O arquivo {0} não foi encontrado", CaminhoDoArquivo)); 
            } 
        } 
        catch (System.IO.IOException) 
        { 
            MessageBox.Show("Erro de acesso ao arquivo. Verifique o arquivo de configuração ou as permissões de pasta"); 
        } 
    } 
    else 
    { 
        MessageBox.Show("Não foi possível encontrar a instalação do Microsoft Excel no seu computador"); 
    } 

    Application.Exit(); 
} 

private static void AbrirArquivo(string caminhoDoArquivo) 
{ 
    object oFileName = caminhoDoArquivo; 
    oExcel = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application")); 
    oExcel.GetType().InvokeMember("AutomationSecurity", BindingFlags.SetProperty, null, oExcel, new object[] { 1 }, ci); 
    oExcel.GetType().InvokeMember("Visible", BindingFlags.SetProperty, null, oExcel, new object[] { true }, ci); 
    oBooks = oExcel.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, oExcel, null, ci); 
    oBook = oBooks.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, oBooks, new object[] { oFileName, oMissing, false }, ci); 
} 

public static bool ExcelEstaInstalado() 
{ 
    Type officeType = Type.GetTypeFromProgID("Excel.Application"); 

    if (officeType == null) 
    { 
        return false; 
    } 
    else 
    { 
        return true; 
    } 
} 
}

1 answer

0

The best way would be to create a shortcut of your spreadsheet, right-click on properties and change the icon, when you invoke the spreadsheet by c# vc will give the shortcut path, I’m not sure if it’s going to work out but it’s worth a try

  • Changing the shortcut icon does not help because the original Excel icon is appearing on the taskbar, I need a way to change the original icon so that the custom icon appears on the taskbar.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.