GARANTIR DESCONTO

Fórum Planilha Excel #334428

08/12/2006

0

Alguém sabe como eu posso proteger as células de uma planilha através do Delphi? Eu preciso criar uma planilha com vários produtos e manda-la a um fornecedor para que ele preencha. Só que ele não pode modificar o conteúdo a não ser a coluna de valor...
Essa possibilidade existe?

Desde já agradeço
Marcelo


Marcelo_mileris

Marcelo_mileris

Responder

Posts

11/12/2006

Marcelo_mileris

Seguinte... encontrei a solução (Parcial) porém a mesma não aplica a proteção

  Excel.Cells.Select; // Seleciona a planilha
  Excel.Cells.Locked := False; // Retira a proteção
  Excel.Cells.FormulaHidden := False; // Retira a proteção
  Excel.Cells.Locked := True;
  Excel.Cells.FormulaHidden := True;
  Excel.WorkBooks.Protect(´senha´,True,True);


Alguém sabe onde tem um material sobre Delphi e Excel? Nem que seja em inglês


Responder

Gostei + 0

12/12/2006

Marcelo_mileris

OK Gente... já consegui resolver....


Responder

Gostei + 0

13/12/2006

Helio Nascimento

marcelo_mileris

Poste aqui a sua solução.
Obrigado/Hélio


Responder

Gostei + 0

13/12/2006

Marcelo_mileris

Está ai a solução...

var
  Excel : OleVariant;
  X : Integer;
begin
  Excel := CreateOleObject(´Excel.Application´);
  Excel.Visible := False;
  Excel.WorkBooks.Add;

  // -> ATIVA PADRÃO BRANCO NA PLANILHA
  Excel.Cells.Select;
  Excel.Cells.Interior.ColorIndex := 2;
  Excel.Cells.Interior.Pattern := xlSolid;
  Excel.Cells.Interior.PatternColorIndex := xlAutomatic;

  // -> PREFEITURA MUNICIPAL
  Excel.ActiveCell.FormulaR1C1 := ´PREFEITURA MUNICIPAL´;
  Excel.Range[´A1´,´K1´].MergeCells := True;
  Excel.Range[´A1´,´K1´].HorizontalAlignment := xlCenter;
  Excel.Range[´A1´,´K1´].Font.Bold := True;
  Excel.Range[´A1´,´K1´].Font.Underline := True;
  Excel.Range[´A1´,´K1´].Font.Size := 14;

  // -> SECRETARIA
  Excel.Range[´A2´,´K2´].Select;
  Excel.ActiveCell.FormulaR1C1 := ´Secretaria Municipal de Administração e Recursos Humanos´;
  Excel.Range[´A2´,´K2´].MergeCells := True;
  Excel.Range[´A2´,´K2´].HorizontalAlignment := xlCenter;
  Excel.Range[´A2´,´K2´].Font.Bold := True;
  Excel.Range[´A2´,´K2´].Font.Size := 10;

  // -> COTAÇÃO DE PREÇOS
  Excel.Range[´A4´,´K4´].Select;
  Excel.ActiveCell.FormulaR1C1 := ´COTAÇÃO DE PREÇOS´;
  Excel.Range[´A4´,´K4´].MergeCells := True;
  Excel.Range[´A4´,´K4´].HorizontalAlignment := xlCenter;
  Excel.Range[´A4´,´K4´].Font.Bold := True;
  Excel.Range[´A4´,´K4´].Font.Size := 10;

  Excel.Cells.Select; // Seleciona a planilha
  Excel.Cells.Locked := False; // Retira a proteção
  Excel.Cells.FormulaHidden := False; // Retira a proteção

  Excel.Range[´A1´,´K4´].Select; // Seleciona as Células
  Excel.Selection.Locked := True; // Ativa Proteção
  Excel.Selection.FormulaHidden := True; // Ativa Proteção

  Excel.ActiveSheet.Protect(´senha´, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True);

  Excel.ActiveWorkbook.SaveAs(´C:\Teste.xls´);

  Excel.ActiveWorkBook.Close;



Responder

Gostei + 0

13/12/2006

Helio Nascimento

marcelo_mileris

Obrigaduuuuuu.

Sds/Hélio


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar