VBS脚本删除只读并添加只读

时间:2016-02-12 08:43:13

标签: vbscript

我对VBS脚本完全不熟悉。

我已设法打开我的Excel工作表并编写“新数据”并再次保存。 这段代码:

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\g46973\Desktop\test.xlsx")
set xlSht = objExcel.activesheet


objExcel.DisplayAlerts = False
xlSht.Cells(2, 2) = "New Data"

objWorkbook.Save
 objWorkBook.Close SaveChanges=True

 ObjExcel.Quit

问题是我的excel工作簿是只读的(我希望它保持这种方式)。然后我运行我的代码我想从我的Excel工作簿中删除只读。运行上面的代码,然后再次添加只读。

2 个答案:

答案 0 :(得分:0)

试试这个

$wpdb->show_errors(); 
global $wpdb;                       
// Grab any post values you sent with your submit function
$DownloadReportFrom = "ReportDateFrom";
$DownloadReportTo = "ReportDateFrom";

// Build your query 
// $MyQuery = $wpdb->get_results($wpdb->prepare('SELECT * FROM wp_rpci_rpci')); -Delete the ($wpdb->prepare                 
$MyQuery = $wpdb->get_results('SELECT * FROM wp_rpci_rpci');



// Process report request
if (! $MyQuery) {
$Error = $wpdb->print_error();
die("The following error was found: $Error");
} else {
// Prepare our csv download

// Set header row values
$csv_fields=array();
$csv_fields[] = 'Field Name 1';
$csv_fields[] = 'Field Name 2';

$output_filename = 'MyReport_' . $DownloadReportFrom .'-'. $DownloadReportTo  . '.csv';
$output_handle = @fopen( 'php://output', 'w' );

 header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
  header( 'Content-Description: File Transfer' );
 header( 'Content-type: text/csv' );
 header( 'Content-Disposition: attachment; filename=' . $output_filename );
header( 'Expires: 0' );
header( 'Pragma: public' ); 

// Insert header row
fputcsv( $output_handle, $csv_fields );

// Parse results to csv format
 foreach ($MyQuery as $Result) {
$leadArray = (array) $Result; // Cast the Object to an array
// Add row to file
fputcsv( $output_handle, $leadArray );
}

// Close output file stream
 fclose( $output_handle ); 

 die();

 }

答案 1 :(得分:0)

objExcel.Workbooks.Open "C:\Users\g46973\Desktop\test.xlsx",‌​,True

这个适合我。