Forum Discussion

srixon's avatar
srixon
Occasional Contributor
2 months ago

Unable to open an Excel Data Source since file is Protected from Editing (Protected View)

We are encountering an issue that is disrupting our ability to automate using an Excel Data Source.  When we download the file, it comes in 'Protected View' mode, which means you have to first open it, check the box to 'Enable Editing', and then close it before ReadyAPI will parse it.

Has anyone else encountered this and is there a fix?  I searched through the community and the only thing I could find a fix for was for password protected files. 

 

I asked AI and there may be a way to get around it using Groovy, but we'd prefer to use the out of the box Data Source solution and Data Loops from ReadyAPI.

@Grab(group='org.apache.poi', module='poi-ooxml', version='5.2.3')
@Grab(group='org.apache.poi', module='poi-ooxml-schemas', version='5.2.3')

import org.apache.poi.ss.usermodel.*
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import java.io.FileInputStream

// Path to the Excel file that is protected from editing
def filePath = "path/to/protected-file.xlsx"

// Open the Excel file
FileInputStream fis = new FileInputStream(filePath)
XSSFWorkbook workbook = new XSSFWorkbook(fis)

// Parse the workbook as usual
Sheet sheet = workbook.getSheetAt(0)  // Access the first sheet

// Iterate through rows and cells
sheet.each { Row row ->
    row.each { Cell cell ->
        print "${cell.toString()} \t"
    }
    println()
}

workbook.close()
fis.close()

 

 

No RepliesBe the first to reply