1

小さな印刷業向けのシンプルな VB.NET デスクトップ アプリを開発しています。メインの WinForm、JPG/PDF/Word/Excel ファイルを開くためのボタン、関連するプログラムを開くためのボタン、ファイルを印刷するためのボタン、スプール ジョブをキャプチャするためのボタン、最後にプリンター名、ページ数に基づいて印刷されたものに対してユーザーに請求するためのボタンがあります。 、ページのサイズ、およびページあたりのコスト。大きな問題ではない。ホスト マシンには Win7 OS が搭載されています。

ユーザーが XLS ファイルを印刷したい場合、アプリで Excel 2010 を開き、以前にファイル ダイアログで選択したファイルを開きます。そして、Excel が開いたら、印刷ダイアログに直接移動し、ジョブがスプールにロードされたら、そのイベントをキャプチャして Excel プロセスを強制終了します。

私の問題は次のとおりです。

Excel を直接開いて印刷ダイアログを開くことはできません。Excel は「print」動詞に応答します。ただし、デフォルトのプリンターで印刷するだけです。開いて印刷ダイアログに移動したい。デフォルトのプリンターで印刷するだけではなく、ユーザーが目的のプリンター、ページ、コピーなどを選択できるようにする必要があります。

私は次のコードでこれをやろうとしています:

   Dim openFileDialog1 As New OpenFileDialog()
   Dim filePath As String = ""
   Dim startInfo As ProcessStartInfo

    'openFileDialog1.InitialDirectory = "c:\"
    openFileDialog1.Filter = "XLS Files (*.xls)|*.xls|XLSX Files (*.xlsx)|*.xlsx|All files (*.*)|*.*"
    openFileDialog1.FilterIndex = 1
    openFileDialog1.RestoreDirectory = True

    If (DialogResult.OK) = openFileDialog1.ShowDialog(Me) Then
        filePath = openFileDialog1.FileName
    Else
        Exit Sub
    End If

    startInfo = New ProcessStartinfo(rutaArchivo)

    With startInfo
            .FileName = filePath 
                .WindowStyle = ProcessWindowStyle.Normal 
            .Verb = "print"
            .CreateNoWindow = False
            .UseShellExecute = True

    End With

    Try
        System.Diagnostics.Process.Start(startInfo)

    Catch ex As Exception
        MsgBox(ex.ToString)

    End Try

IDE は SharpDevelop 4.3 です。フレームワークは .NET 4.0 クライアント プロファイルです。OSはWin7です。

どうもありがとう :)

4

2 に答える 2

0

MS Excel には次のコマンド ライン スイッチしかありません。Excel スイッチ

あなたが望むことをするために、あなたはExcel Interopを調べるかもしれません

于 2013-09-24T21:16:33.977 に答える
0

最初に印刷ダイアログを開き、次のように「PrintTo」の動詞で選択したプリンターを使用することで、これを行うことができるはずです。

Dim openFileDialog1 As New OpenFileDialog()
    Dim filePath As String = ""
    Dim startInfo As ProcessStartInfo

    'openFileDialog1.InitialDirectory = "c:\"
    openFileDialog1.Filter = "XLS Files (*.xls)|*.xls|XLSX Files (*.xlsx)|*.xlsx|All files (*.*)|*.*"
    openFileDialog1.FilterIndex = 1
    openFileDialog1.RestoreDirectory = True

    If (DialogResult.OK) = openFileDialog1.ShowDialog(Me) Then
        filePath = openFileDialog1.FileName
    Else
        Exit Sub
    End If

    Dim printer As String = ""
    Dim printDialog As New PrintDialog()

    If printDialog.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
        printer = printDialog.PrinterSettings.PrinterName
    End If


    startInfo = New ProcessStartInfo(filePath)

    With startInfo
        .WindowStyle = ProcessWindowStyle.Normal
        .Verb = "PrintTo"
        '.Arguments = """\\" & System.Net.Dns.GetHostName() & "\" & printer & """"
        .Arguments = """" & printer & """"
        .CreateNoWindow = False
        .UseShellExecute = True

    End With

    Try
        System.Diagnostics.Process.Start(startInfo)

    Catch ex As Exception
        MsgBox(ex.ToString)

    End Try

Arguments (コメント行) にサーバーを含める必要がある場合があります。

于 2013-09-24T21:24:21.523 に答える