Click here to Skip to main content
15,120,078 members
Home / Discussions / C#
   

C#

 
QuestionHow Linq determine the index of a list item? Pin
Alex Dunlop16-Aug-21 23:57
MemberAlex Dunlop16-Aug-21 23:57 
AnswerRe: How Linq determine the index of a list item? Pin
Richard Deeming17-Aug-21 0:09
mveRichard Deeming17-Aug-21 0:09 
QuestionC# interacting with Excel Pin
Ismael Oliveira 202116-Aug-21 14:15
MemberIsmael Oliveira 202116-Aug-21 14:15 
AnswerRe: C# interacting with Excel Pin
Richard Deeming16-Aug-21 22:36
mveRichard Deeming16-Aug-21 22:36 
GeneralRe: C# interacting with Excel Pin
Ismael Oliveira 202124-Aug-21 13:46
MemberIsmael Oliveira 202124-Aug-21 13:46 
AnswerRe: C# interacting with Excel Pin
Richard MacCutchan16-Aug-21 22:42
mveRichard MacCutchan16-Aug-21 22:42 
AnswerRe: C# interacting with Excel Pin
SpiveyC#7-Sep-21 2:44
MemberSpiveyC#7-Sep-21 2:44 
QuestionHow to merge cells in Excel using C# Pin
Ismael Oliveira 202112-Aug-21 13:43
MemberIsmael Oliveira 202112-Aug-21 13:43 
Hi.
I use C# in Visual Studio and use Forms. I need to generate an Excel file with merged columns. I tried the following code:
private void button1_Click(object sender, EventArgs e)
{
    string Arquivo = @"D:\Diversos\Antares\Relatório.xlsx";
    Excel.Application xlApp;
    Excel.Workbook xlWorkBook;
    Excel.Worksheet xlWorkSheet;
    object misValue = System.Reflection.Missing.Value;

    //Cria uma planilha temporária na memória do computador
    xlApp = new Excel.Application();
    xlWorkBook = xlApp.Workbooks.Add(misValue);
    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    xlWorkSheet.Range[ws.Cells[1, 1], ws.Cells[1, 4]].Merge();
    xlWorkSheet.Visible = XlSheetVisibility.xlSheetVisible;

    //incluindo dados
    xlWorkSheet.Cells[1, 1] = "Dados do cliente:";
    //            xlWorkSheet.Cells[1, 2] = textBox1.Text;
    //            xlWorkSheet.Cells[1, 3] = textBox2.Text;
    //            xlWorkSheet.Cells[1, 4] = textBox3.Text;

    //Salva o arquivo de acordo com a documentação do Excel.
    xlWorkBook.SaveAs(Arquivo, Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, misValue, misValue,
    Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
    xlWorkBook.Close(true, misValue, misValue);
    xlApp.Quit();

}

Of course, it's just a try and much code is missing, but the essencial is here. When I run this program I receive the message: "System.Runtime.InteropServices.COMException: 'Não há suporte para esta interface" The last piece of the message means "There's no support for this interface", at the line of the merge.
Can anyone help me solve this problem? If you have other suggestion on how to inteact with Excel, I'd appreciate it.
Thanks.

modified 12-Aug-21 18:54pm.

AnswerRe: How to merge cells in Excel using C# Pin
Richard MacCutchan12-Aug-21 22:35
mveRichard MacCutchan12-Aug-21 22:35 
GeneralRe: How to merge cells in Excel using C# Pin
Ismael Oliveira 202113-Aug-21 14:45
MemberIsmael Oliveira 202113-Aug-21 14:45 
GeneralRe: How to merge cells in Excel using C# Pin
Richard MacCutchan13-Aug-21 22:44
mveRichard MacCutchan13-Aug-21 22:44 
GeneralRe: How to merge cells in Excel using C# Pin
Ismael Oliveira 202114-Aug-21 13:46
MemberIsmael Oliveira 202114-Aug-21 13:46 
GeneralRe: How to merge cells in Excel using C# Pin
Richard MacCutchan14-Aug-21 22:09
mveRichard MacCutchan14-Aug-21 22:09 
QuestionPassing a variable from an string to a For loop Pin
Alex Dunlop12-Aug-21 0:55
MemberAlex Dunlop12-Aug-21 0:55 
AnswerRe: Passing a variable from an string to a For loop Pin
Pete O'Hanlon12-Aug-21 3:28
mvePete O'Hanlon12-Aug-21 3:28 
GeneralRe: Passing a variable from an string to a For loop Pin
harold aptroot12-Aug-21 3:42
Memberharold aptroot12-Aug-21 3:42 
AnswerRe: Passing a variable from an string to a For loop Pin
Richard Deeming12-Aug-21 3:48
mveRichard Deeming12-Aug-21 3:48 
AnswerRe: Passing a variable from an string to a For loop Pin
jsc4212-Aug-21 4:08
professionaljsc4212-Aug-21 4:08 
AnswerRe: Passing a variable from an string to a For loop Pin
Dave Kreskowiak12-Aug-21 4:32
mveDave Kreskowiak12-Aug-21 4:32 
AnswerRe: Passing a variable from an string to a For loop Pin
Gerry Schmitz12-Aug-21 5:13
mveGerry Schmitz12-Aug-21 5:13 
AnswerRe: Passing a variable from an string to a For loop Pin
OriginalGriff12-Aug-21 5:20
mveOriginalGriff12-Aug-21 5:20 
GeneralRe: Passing a variable from an string to a For loop Pin
Alex Dunlop12-Aug-21 7:16
MemberAlex Dunlop12-Aug-21 7:16 
GeneralRe: Passing a variable from an string to a For loop Pin
OriginalGriff12-Aug-21 7:36
mveOriginalGriff12-Aug-21 7:36 
GeneralRe: Passing a variable from an string to a For loop Pin
Alex Dunlop12-Aug-21 9:55
MemberAlex Dunlop12-Aug-21 9:55 
GeneralRe: Passing a variable from an string to a For loop Pin
OriginalGriff12-Aug-21 23:49
mveOriginalGriff12-Aug-21 23:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.