Excel Dateien mit c# öffnen

  • C#

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von Radinator.

    Excel Dateien mit c# öffnen

    Hallo Liebes Forum,
    evtl. kann mir jemand bei einem Problem helfen .. ich möchte unabhängig der Office Version mit einem c# Form eine Excel Tabelle öffnen also wenn ich mir ein Symbol in eine Form lege und dort clicke/doppelklick
    dann soll Die Form das so behandeln als würde die Verknüpfung oder das Dokument auf dem Desktop liegen die Form soll einfach die Standard Anwendung die für diese Endung hinterlegt ist nutzen.

    Ich habe leider überall nur was mit manipulation oder öffnen der Tabellen direkt im Form usw. gefunden oder Dinge, die Versionsgebunden sind...

    Momentan mache ich es so dass ich mit der Form eine .bat datei starte die wiederum direkt die .exe von Excel startet also mit bat call funktion und öffnen der Mappe

    Wäre für Hilfe dankbar ?(
    Funktioniert ein

    C#-Quellcode

    1. var p = new Process();
    2. p.StartInfo = new ProcessStartInfo()
    3. {
    4. FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "file.xlsx")
    5. };
    6. p.Start();
    nicht?
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Wie groß ist die Excel Datei und wie viel RAM hast du verbaut?
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Kannst du die Excel manuell (im Explorer) öffnen?
    Liegt die Datei Lokal?

    Zeig mal deinen Code, evtl. kommt der Fehler von wo anders.
    "Gib einem Mann einen Fisch und du ernährst ihn für einen Tag. Lehre einen Mann zu fischen und du ernährst ihn für sein Leben."

    Wie debugge ich richtig? => Debuggen, Fehler finden und beseitigen
    Wie man VisualStudio nutzt? => VisualStudio richtig nutzen
    Hallo,

    ich habe hier mal ein paar Infos

    Variante 1: Standard-ProcessStart mit dem Disablen der Raising Events

    VB.NET-Quellcode

    1. Process process_exe = Process.Start(@"S:" + sFilePath + sFileName);
    2. process_exe.EnableRaisingEvents = false;



    Variante 2: StartInfo mit Angabe der excel.exe, funktioniert auch ohne Angabe der .exe nicht (was eig. besser wäre)

    VB.NET-Quellcode

    1. string programFiles = Environment.GetEnvironmentVariable("ProgramFiles");
    2. const string excelRelativePath = @"Microsoft Office\Office16\excel.exe";
    3. string excel = Path.Combine(programFiles, excelRelativePath);
    4. ProcessStartInfo startInfo = new ProcessStartInfo(excel, @""+sFile2open+"");
    5. startInfo.CreateNoWindow = false;
    6. startInfo.UseShellExecute = false;
    7. startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    8. //startInfo.Arguments = "-f -j -o" ;
    9. //"-f j -o ;
    10. try
    11. {
    12. Process.Start(startInfo);
    13. }
    14. catch (Exception ex) { xy}


    Variante 3: inklusive Excel-Process schließen

    VB.NET-Quellcode

    1. foreach (Process clsProcess in Process.GetProcesses())
    2. if (clsProcess.ProcessName.Equals("EXCEL")) //Process Excel?
    3. clsProcess.Kill();
    4. ProcessStartInfo startInfo = new ProcessStartInfo();
    5. startInfo.CreateNoWindow = false;
    6. startInfo.UseShellExecute = false;
    7. startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    8. //startInfo.FileName = sFile2open;
    9. //startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;
    10. Process.Start(startInfo);


    Ich möchte halt einfach nur wie im Windows Explorer auch einen Doppelklick machen wie als wenn ich die .xls doppelt anklicke und das entsprechende Programm geht auf
    wusste nicht , dass es so viel ärger macht
    Bilder
    • Fehler.png

      22,18 kB, 861×155, 198 mal angesehen
    Was bringen dir denn die ganzen Aufrufparameter?

    Edit: Hab man nach Befehlszeilen Argumente und Excel gesucht: support.office.com. So wie es aussieht, gibt es die Parameter, welche du verwendest (f, j, o, z, y) - außer -s bzw /s gar nicht
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell