Public Function ToExcel(ByVal vSP As FarPoint.Win.Spread.FpSpread, Optional ByVal vMsg As Boolean = True) As String
If (MsgBox("是否保存文件?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "竣伎函券") <> MsgBoxResult.Yes) Then Return ""
Dim ckMsg As String = ""
Dim dlg As New System.Windows.Forms.SaveFileDialog
Dim k As Integer
Dim stProtect() As Boolean
Try
dlg.Title = "Excel 保存"
dlg.Filter = "竣伎颇老(*.xlsx)|*.xlsx"
dlg.ShowDialog()
If (dlg.FileName <> "") Then
ReDim stProtect(vSP.Sheets.Count)
For k = 0 To vSP.Sheets.Count - 1
stProtect(k) = vSP.Sheets(k).Protect
vSP.Sheets(k).Protect = False
Next
vSP.SaveExcel(dlg.FileName, FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders Or FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat)
For k = 0 To vSP.Sheets.Count - 1
vSP.Sheets(k).Protect = stProtect(k)
Next
ckMsg = "OK"
End If
'
Catch ex As Exception
ckMsg = ex.Message
End Try
'
If vMsg = True Then
If ckMsg = "OK" Then
MsgBox(" TO .. [" & dlg.FileName + "] " + vbCrLf + " Excel 函券捞 肯丰登菌嚼聪促.", MsgBoxStyle.OkOnly, "Excel函券")
ElseIf ckMsg <> "" Then
MsgBox(ckMsg, MsgBoxStyle.OkOnly, "Excel函券")
End If
End If
Return ckMsg
End Function |