Compartilhar via


Como: Alterar a formatação em linhas da planilha que contém Selecionadodas células

Se aplica a

As informações contidas neste tópico se aplicam apenas às especificado Ferramentas do Visual Studio para o Office projetos e as versões do Microsoft Office.

Tipo de Projeto

  • Projetos de nível de documento

  • Projetos de nível de aplicativo

Versão do Microsoft Office

  • O Excel 2003

  • O Excel 2007

For more information, see Recursos disponíveis pelo aplicativo e o tipo de projeto.

Você pode alterar a fonte de uma linha inteira que contém uma célula Selecionadoda para que o texto seja negrito.

Para tornar a linha atual em negrito e o anteriormente em negrito linha normal

  1. declare um Estático variável para manter o controle da linha Selecionadoda anteriormente.

    Static previousRow As Integer = 0
    
    static int previousRow = 0;
    
  2. Recupere uma referência para a célula atual usando a propriedade ActiveCell.

    Dim currentCell As Excel.Range = Me.Application.ActiveCell
    
    Excel.Range currentCell = this.Application.ActiveCell;
    
  3. Estilo da linha atual negrito usando a propriedade EntireRow da célula Ativo.

    currentCell.EntireRow.Font.Bold = True
    
    currentCell.EntireRow.Font.Bold = true; 
    
  4. Garantir que o valor atual de previousRow não seja 0.Um 0 (zero) indica que esse é na Primeiro vez por meio desse código.

    If previousRow <> 0 Then
    
    if (previousRow != 0)
    
  5. Verifique se a linha atual é diferente de a linha anterior.

    If currentCell.Row <> previousRow Then
    
    if (currentCell.Row != previousRow)
    
  6. Recuperar uma referência a um intervalo que representa a linha que foi Selecionadoda anteriormente e conjunto que linha não seja negrito.

    Dim rng As Excel.Range = DirectCast(ws.Rows(previousRow), Excel.Range)
    rng.EntireRow.Font.Bold = False
    
    Excel.Range rng = (Excel.Range)ws.Rows[previousRow, missing];
    rng.EntireRow.Font.Bold = false;
    
  7. Armazene a linha atual, o que pode tornar-se a linha anterior na Avançar passagem.

    previousRow = currentCell.Row
    
    previousRow = currentCell.Row;
    

O exemplo a seguir mostra Concluir método.

Exemplo

Private Sub BoldCurrentRow(ByVal ws As Excel.Worksheet)

    ' Keep track of the previously bolded row.
    Static previousRow As Integer = 0

    ' Work with the current active cell.
    Dim currentCell As Excel.Range = Me.Application.ActiveCell

    ' Bold the current row.
    currentCell.EntireRow.Font.Bold = True

    ' If a pass has been done previously, make the old row not bold.
    ' Make sure previousRow is not 0 (otherwise this is your first pass through).
    If previousRow <> 0 Then

        ' Make sure the current row is not the same as the previous row.
        If currentCell.Row <> previousRow Then

            Dim rng As Excel.Range = DirectCast(ws.Rows(previousRow), Excel.Range)
            rng.EntireRow.Font.Bold = False
        End If
    End If

    ' Store the new row number for the next pass.
    previousRow = currentCell.Row
End Sub
// Keep track of the previously bolded row.
static int previousRow = 0;

private void BoldCurrentRow(Excel.Worksheet ws)
{
    // Work with the current active cell.
    Excel.Range currentCell = this.Application.ActiveCell;

    // Bold the current row.
    currentCell.EntireRow.Font.Bold = true; 

    // If a pass has been done previously, make the old row not bold.
    // Make sure previousRow is not 0 (otherwise this is your first pass through).
    if (previousRow != 0)

        // Make sure the current row is not the same as the previous row.
        if (currentCell.Row != previousRow)
        {
            Excel.Range rng = (Excel.Range)ws.Rows[previousRow, missing];
            rng.EntireRow.Font.Bold = false;
        }

    // Store the new row number for the next pass.
    previousRow = currentCell.Row;
}

Consulte também

Tarefas

Como: Aplicar estilos a intervalos em pastas de trabalho

Como: Copiar dados e formatação entre planilhas

Conceitos

Trabalhando com planilhas

Noções básicas sobre parâmetros opcionais in Office Solutions