Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6827101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:13:36+00:00 2026-05-26T22:13:36+00:00

I need to generate a report file from my don net app. i need

  • 0

I need to generate a report file from my don net app. i need to put the data in tabulated format. ordinarily, you would expect me to use the Microsoft report viewer control. but am using sqlite, and cannot generate the report automatically. Also my report is based on a multiple tables, not on a specific table. so i decided to use RichTextFormat or Word .doc.

i need to create a report that looks like this

-------------------------------------------------------------------------
|    Column 1     |    Column 2     |    Column 3     |    Column 4     |
-------------------------------------------------------------------------
|                 |                 |                 |                 |
|                 |                 |                 |                 |
|                 |                 |                 |                 |
-------------------------------------------------------------------------

An of course the rows are not fixed but can be smaller of more. can you please guid me on the best way to do this.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:13:37+00:00Added an answer on May 26, 2026 at 10:13 pm

    You can use interop library and write directly to Word document as well. Especially if document structure is quite simple. Disadvantages: Word must be installed on machine which will be generating report. Example below, remember to add assemblies: Microsoft.Office.Interop.Word (…\Office12\Microsoft.Office.Interop.Word.dll), Office (…\Office12\Office.dll).

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Office.Interop.Word;
    using Microsoft.Office.Core;
    using System.Runtime.InteropServices;
    using System.IO;
    using System.Diagnostics;
    
    namespace WriteToWordSO
    {
        class Program
        {
            static void Main(string[] args)
            {
                _Application app = null;
                Documents docs = null;
                Document doc = null;
                Range range = null;
                Tables tables = null;
                Table table = null;
    
                object oMissing = System.Reflection.Missing.Value;
                object oFalse = false;
                object oTrue = true;
                object fileName = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "tmp.doc");
                object fileFormat = WdSaveFormat.wdFormatDocument;
    
                FileInfo fi = new FileInfo(fileName.ToString());
                if (fi.Exists) fi.Delete();
    
                int rows = 4, cols = 5;
    
                try
                {
                    app = new ApplicationClass();
                    app.Visible = false;
                    app.DisplayAlerts = WdAlertLevel.wdAlertsNone;
                    app.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;
    
                    docs = app.Documents;
                    doc = docs.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    
                    range = doc.Range(ref oMissing, ref oMissing);
    
                    tables = doc.Tables;
    
                    object oAutoFitCell = WdDefaultTableBehavior.wdWord9TableBehavior;
                    object oAutoFitWindow = WdAutoFitBehavior.wdAutoFitWindow;
    
                    table = tables.Add(range, rows, cols, ref oAutoFitCell, ref oAutoFitWindow);
    
                    Cell c = null;
                    Range cellRange = null;
    
                    // header row
                    for (int i = 1; i < cols + 1; i++)
                    {
                        c = table.Cell(1, i);
                        cellRange = c.Range;
                        cellRange.Text = "Header " + i.ToString();
                        cellRange.Bold = 1;
                        Marshal.ReleaseComObject(c);
                        Marshal.ReleaseComObject(cellRange);
                    }
    
                    // data rows
                    for (int i = 1; i < cols + 1; i++)
                    {
                        for (int j = 1; j < rows; j++)
                        {
                            c = table.Cell(j + 1, i);
                            cellRange = c.Range;
                            cellRange.Text = "Cell " + i.ToString() + j.ToString();
                            Marshal.ReleaseComObject(c);
                            Marshal.ReleaseComObject(cellRange);
                        }
                    }
    
                    doc.SaveAs(ref fileName, ref fileFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing);
    
                    ((_Document)doc).Close(ref oFalse, ref oMissing, ref oMissing);
    
                    ((_Application)app).Quit(ref oFalse, ref oMissing, ref oMissing);
    
                    Process.Start(fileName.ToString());
                }
                finally
                {
                    // frees memory
    
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
    
                    // its very important to release all used object,
                    // otherwise some complications may appear
                    if (table != null) Marshal.ReleaseComObject(table);
                    table = null;
    
                    if (tables != null) Marshal.ReleaseComObject(tables);
                    tables = null;
    
                    if (range == null) Marshal.ReleaseComObject(range);
                    range = null;
    
                    if (doc != null) Marshal.ReleaseComObject(doc);
                    doc = null;
    
                    if (docs != null) Marshal.ReleaseComObject(docs);
                    docs = null;
    
                    if (app != null) Marshal.ReleaseComObject(app);
                    app = null;
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a lot of mysql data that I need to generate reports from.
I need to automatically generate a PDF file from an exisiting (X)HTML-document. The input
I need to generate a report where the user can choose All Issues, Open
i will need to generate a report based on user input for every food
I need to generate thumbnails from a set of jpg's that need to have
I need to generate a directory in my makefile and I would like to
I am creating a Generate Report button for some data in my application. The
To generate an ouput file (.rwo format) containing the desired result, we have to
An iPhone app which I am creating generates reports from a Core Data database
I have problem related to file protection when changed the Jasper Report output from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.