Raysefo

Raysefo

  • 1.8k
  • 174
  • 120.1k

Excel - How to make read Only?

Mar 26 2013 4:13 AM
Hi,

I would like to make this excel read only so that nobody can change its data. Is there a way to do it? 

'Excel
                Dim oXL As Excel.Application
                Dim oWB As Excel.Workbook
                Dim oSheet As Excel.Worksheet
                Dim oRange As Excel.Range

                '
Start Excel and get Application object.
                oXL
= New Excel.Application

               
' Set some properties
                oXL.Visible = False
                oXL.DisplayAlerts = False

                '
Get a new workbook.
                oWB
= oXL.Workbooks.Add

                oSheet
= oWB.Worksheets(2) ' Assuming there is > 1 sheet in the Workbook, get Sheet 2
                oSheet.Activate() '
Activate the Worksheet

               
' Get the active sheet
                oSheet = DirectCast(oWB.ActiveSheet, Excel.Worksheet)
                oSheet.Name = "Detay"

                '
Style
               
Dim style As Excel.Style = oSheet.Application.ActiveWorkbook.Styles.Add("NewStyle")
                style
.Font.Name = "Verdana"
                style
.Font.Size = 12
                style
.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black)
                style
.Interior.Pattern = Excel.XlPattern.xlPatternSolid
                style
.Font.Bold = True
                style
.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Orange)

               
'Headers
                oSheet.Range("A" + row_num.ToString + "").Value = "SNO"
                oSheet.Range("B" + row_num.ToString + "").Value = "ADISOYADI"
                '
oSheet.Range("C" + row_num.ToString + "").Value = "NOKTAADI"
                oSheet
.Range("C" + row_num.ToString + "").Value = "FIRMA"
                oSheet
.Range("D" + row_num.ToString + "").Value = "BÖLÜM"
                oSheet
.Range("E" + row_num.ToString + "").Value = "TARIH"
                oSheet
.Range("F" + row_num.ToString + "").Value = "ÇIKISSAATI"
                oSheet
.Range("G" + row_num.ToString + "").Value = "GIRISSAATI"
                oSheet
.Range("A" + row_num.ToString + ":G" + row_num.ToString + "").Font.Bold = True
                oSheet
.Range("A" + row_num.ToString + ":G" + row_num.ToString + "").Style = style

                row_num
= row_num + 1

               
'Calculate
                Calculate(row_num, oSheet, period, time1, time2, date1, date2, ekstra)

                '
Resize the columns
                oRange
= oSheet.Range(oSheet.Cells(1, 1), _
                          oSheet
.Cells(100, 7))
                oRange
.EntireColumn.AutoFit()

               
' Save the sheet and close
                oSheet = Nothing
                oRange = Nothing
                oWB.SaveAs("c:\GirisCikis\Giris-Çikis(" + date1 + " - " + date2 + ").xlsx")

                oWB.Close()
                oWB = Nothing
                oXL.Quit()

Answers (2)