12
votes

Excel à la bibliothèque PDF C #

Je cherche une MS Excel (.xls and .xlsx) au convertisseur / bibliothèque PDF ou à l'API. Je le veux pour mon application C # .NET.

J'aime les bibliothèques commerciales, mais je ne peux pas me permettre beaucoup.


2 commentaires

Je voulais juste ajouter une alternative, GUMBOX.SPREADSHEET , qui peut également faire la conversion requise, voir ici . En bref, c'est littéralement une ligne de code: Excelfelfile.load ("INPUT.XLSX"). Enregistrer ("INPUT.OUTPUT");


Voici une solution complète avec la configuration IIS. McUslu.medium.com/...


3 Réponses :


3
votes

Essayez ce qui suit:

http://www.sautinsoft.com/convert-excel-xls-a-pdf/spreadsheet-xls-excel-to-pdf-export-component-asp.net.php

ou

http://www.html-to-pdf.net/excel -Library.aspx

Je pense que vous pouvez manipuler ITEXT pour le faire aussi: http://www.itextpdf.com/

Il y a aussi http://www.aspose.com mais ils ne sont pas particulièrement bon marché.

La réponse suivante sur le débordement de la pile peut aider. https://stackoverflow.com/questions/891531/convert-xls- DOC-Files-TO-PDF-with-C et HTTPS: // Stackoverflow.com/Questions/769246/XLS-TO-PDF-CONVERSION-Inside-net . La deuxième réponse a une solution intéressante automatiser Open Office !! / p>


1 commentaires

C'est le plus simple // exportation à pdf var x = nouvelle SautinSoft.exceltopdf {sortieFormat = saucetinsoft.exceltopdf.eOutputformat.pdf}; var pdfpath = string.format ("{0} \\ {1} .pdf", courantDirectoryPath, nom de fichier); x.convertie (finalxcelpath, pdfpath);



6
votes

ces articles vous aideront! strong>

Services de convertisseur PDF P>

ITEXTSTHARP P>

Excel à PDF .NET p>

EDIT STRAR>: J'ai trouvé cette fonction de classe. P>

public DataSet GetExcel(string fileName)
    {
        Application oXL;
        Workbook oWB;
        Worksheet oSheet;
        Range oRng;
        try 
        {
            //  creat a Application object
            oXL = new ApplicationClass();
            //   get   WorkBook  object
            oWB = oXL.Workbooks.Open(fileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value);

            //   get   WorkSheet object 
            oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.Sheets[1];
            System.Data.DataTable dt = new System.Data.DataTable("dtExcel");
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            DataRow dr;

            StringBuilder sb = new StringBuilder();
            int jValue = oSheet.UsedRange.Cells.Columns.Count;
            int iValue = oSheet.UsedRange.Cells.Rows.Count;
            //  get data columns
            for (int j = 1; j <= jValue; j++)
            {
                dt.Columns.Add("column" + j, System.Type.GetType("System.String"));
            }

            //string colString = sb.ToString().Trim();
            //string[] colArray = colString.Split(':');

            //  get data in cell
            for (int i = 1; i <= iValue; i++)
            {
                dr = ds.Tables["dtExcel"].NewRow();
                for (int j = 1; j <= jValue; j++)
                {
                    oRng = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[i, j];
                    string strValue = oRng.Text.ToString();
                    dr["column" + j] = strValue;
                }
                ds.Tables["dtExcel"].Rows.Add(dr);
            }
            return ds;
        }
        catch (Exception ex)
        {
            Label1.Text = "Error: ";
            Label1.Text += ex.Message.ToString();
            return null;
        }
        finally
        {
            Dispose();
        } 


1 commentaires

Le premier édition avec le code est totalement inutile dans le but de convertir Excel au PDF.



34
votes

J'ai essayé de m'éloigner de l'interaction directe de COM via Interop via des forfaits tiers, mais quand ce n'est pas une option en raison des considérations de coûts, je vais utiliser les fonctionnalités d'exportation intégrées du bureau 2007/2010 pour y accomplir.

La méthode que vous devez appeler est workbook.exportaSfixedFormat ()

Voici un exemple de la façon dont je l'utilise une fonction d'exportation: xxx


3 commentaires

N'oubliez pas d'installer Bureau Plugin Sauvegardez en PDF et XPS (un complément pour Office 2007). Vous pouvez le télécharger sur le site Web officiel de Microsoft.


Grande panne! Je vous remercie


Comment le faire si WorkbookPath est multiple