1
I am exporting data to an Excel spreadsheet and am unable to use Autofit, someone could help me?
Code:
public void exportarExcel(InformacaoDB info, string nomeArquivo)
{
    Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
    Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
    Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
    object misValue = System.Reflection.Missing.Value;
    xlWorkBook = xlApp.Workbooks.Add(misValue);
    xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    xlWorkSheet.Cells[1, 1] = "Cliente";
    xlWorkSheet.Cells[1, 2] = "Nome do Servidor";
    xlWorkSheet.Cells[1, 3] = "Uso de Processamento (%)";
    xlWorkSheet.Cells[1, 4] = "Uso de Armazenamento (%)";
    xlWorkSheet.Cells[2, 1] = info.Cliente;
    xlWorkSheet.Cells[2, 2] = info.NomeServidor;
    xlWorkSheet.Cells[2, 3] = info.UsoProcessamento;
    xlWorkSheet.Cells[2, 4] = info.UsoArmazenamento;
}
C# has no
AutoFit. It is likely that the used API has, but there is nothing in your code that indicates this. Can you give more information? I found this: https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.autofit.aspx– Maniero
I wanted to format Excel cells by code C#, type Alignment, width and auto height, those things.
– Thiago Beltrame
@Thiagobeltrame I believe you can solve the problem the way I posted in the answer
– mateusalxd