locked
Create multiple MS-word files using an input .csv file RRS feed

  • Question



  • Hi,
    I am totally new to C# but I have a good background in programming in Java. I asked a similar question in my other post.
    My input is a .csv with Unicode text with say R = 10 rows ( includes the header) and C = 5 columns

    I want to create R-1 = 9 MS-word documents, each with text from rows of the .CSV file, the input file.

    I want the text to be right-justified with column names to be the section( heading) names, and the cells to be the context/content of the section. So, after executing C# code, I will end out with 9 MS-word documents generated say 1.docx, 2.docx, ....


    If anyone could guide me through this also tell which APIs I need to use I do appreciate it.


    Sunday, November 1, 2020 8:52 AM

All replies

  • There are two different techniques that you can use to create the Word documents. The first is to use Word itself. If it is installed in the same machine where you are running the program, your program can use OLE automation to control Word via COM/Interop, thus giving Word the commands to produce the files.

    The second is to use an external library to directly create the files themselves, without using Word at all. This has the advantage that it does not require a Word license, and it has higher performance and is supported on a server. But t will usually require more effort, as well as having to go through the (usually steep) learning curve for the library.

    Although there are third-party libraries, there is a free one from Microsoft called OpenXML. You can download the library (as well as a its Software Development Kit) from here.

    Documentation and examples for creating a Word document using the OpenXML library can be found here.

    Sunday, November 1, 2020 11:17 AM
  • I am on Mac ( Mojave). Can I do either approaches on MacOS or I need to have a Windows computer?

    By the way, is there a book or good starting reference to learn these things? Like I said, I already code in JavaScript, Python, Java and C++ and I suppose I can pick up C# fairly quick.

    Thank you very much, again.

    Sunday, November 1, 2020 9:16 PM
  • Hello,

    I agree with Alberto for options. OpenXML requires a spending quality time learning the API and the nuances of how to code for OpenXML.

    I've never tried working on a Mac but can't imagine it's so different from Windows.

    Take a look at my Microsoft TechNet code sample for an idea what to expect. Even working with third party libraries which do make things easier there are no shortcuts to learning third party libraries, see my code sample using a library known has GemBox Document (which my team uses), Apose Words library or Sprte.Doc.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, November 1, 2020 10:03 PM
  • Thank you Karen.
    Monday, November 2, 2020 5:38 AM
  • Hi,

    Has your issue been resolved?

    If so, please click on the "Mark as answer" option of the reply that solved your question, so that it will help other members to find the solution quickly if they face a similar issue. If you still have questions, please feel free to ask.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 5, 2020 5:28 AM