Last updated:
0 purchases
protect
protect #
Protect is a flutter and dart library for applying and removing password protection on excel files.
Table of Contents #
Installing
Usage
Imports
Read xlsx file
Read xlsx file from Asset Folder
Apply password on xlsx file
Remove password on xlsx file
Saving xlsx file
Also checkout our other libraries
Donate (Be the First one)
Lets Get Started #
1. Depend on it #
Add this to your package's pubspec.yaml file:
dependencies:
protect: ^1.0.0
copied to clipboard
2. Install it #
You can install packages from the command line:
with pub:
$ pub get
copied to clipboard
with Flutter:
$ flutter packages get
copied to clipboard
3. Import it #
Now in your Dart code, you can use:
import 'package:protect/protect.dart';
copied to clipboard
Usage #
Imports #
import 'dart:io';
import 'package:protect/protect.dart';
copied to clipboard
Read XLSX File #
var file = "Path_to_pre_existing_Excel_File/excel_file.xlsx";
var unprotectedExcelBytes = await File(file).readAsBytes();
or
//var protectedExcelBytes = await File(file).readAsBytes();
copied to clipboard
Read XLSX from Flutter's Asset Folder #
import 'package:flutter/services.dart' show ByteData, rootBundle;
/* Your blah blah code here */
ByteData data = await rootBundle.load("assets/existing_excel_file.xlsx");
var bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
var unprotectedExcelBytes = await File(file).readAsBytes();
or
//var protectedExcelBytes = await File(file).readAsBytes();
copied to clipboard
Apply password protection on XLSX File #
///
/// Applying password protection
/// where `unprotectedExcelBytes` is the bytes of unprotected excel
///
ProtectResponse encryptedResponse = await Protect.encryptUint8List(unprotectedUint8List, '[email protected]');
var data;
if (encryptedResponse.isDataValid) {
data = encryptedResponse.processedBytes;
} else {
print('Excel file used for applying password over it is corrupted');
}
copied to clipboard
Remove password protection on XLSX File #
///
/// Applying password protection
/// where `protectedUint8List` is the bytes of encrypted excel
///
ProtectResponse decryptedResponse = await Protect.decryptUint8List(protectedUint8List, '[email protected]');
var data;
if (decryptedResponse.isDataValid) {
data = decryptedResponse.processedBytes;
} else {
print('Either password is wrong for opening the excel file or the Excel file is corrupted');
}
copied to clipboard
Saving XLSX File #
// Save the Changes in file
var outputPath = '/Path_to_excel_folder/form_encrypted_file.xlsx';
await File(outputPath)
..create(recursive: true)
..writeAsBytes(data);
copied to clipboard
Donate #
Help me speed up my build time..... 🔎 Help me buy Macbook Pro 16 M1 Max !!
Paypal
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.