C# .NET - How to export dataset to Ms Word in winforms -Urgent

Asked By shashikanth talupuru
26-Oct-09 08:13 AM
Hi friends

                    I need to export data from dataset to Ms Word in Windows forms application using c#.Please suggest me the code snippets or reference links.

                   I also need to format the ms-word as per my requirements.

                   Thanks in Advance..


Shashi.

reply  reply

26-Oct-09 08:25 AM
Hi,
Most people out there export dataset to Microsoft Excel, but not that sure why you want to display on Word. But, i will recommend you to do this. 1. Save your dataset to xml file. http://www.dotnetjohn.com/articles.aspx?articleid=34 2. Then create a schema of your xml file, then create the word document http://www.dotnetjohn.com/articles.aspx?articleid=170 But i think it only can work with Microsoft Office 2003 or Word 2003 as it support xml features. Hope it helps and gets you started. Cheers.

export dataset to Ms Word  export dataset to Ms Word

26-Oct-09 08:48 AM

See try this method;

'Save dataset data to xml file and schema file
dstCust.WriteXML(Server.MapPath("Customers.xml"),XmlWriteMode.IgnoreSchema)
dstCust.WriteXMLSchema(Server.MapPath("Customers.xsd"))

Then Start by creating or opening a document in Word 2003 with the desired text. You can highlight or somehow mark the locations for XML placeholders in your document so you can find them easily when it comes time to edit the document. My convention is to write the node names into the text of the document, and surround them with square brackets (e.g., [ContactName]). These become the placeholders for the schema elements in the document.

See this link for same;

http://www.dotnetjohn.com/articles.aspx?articleid=170

re  re

26-Oct-09 12:27 PM
Hi

here my code
private void button1_Click(object sender, EventArgs e)
{

object missing = System.Reflection.Missing.Value;

object Visible = true;

object start1 = 0;

object end1 = 0;



ApplicationClass WordApp = new ApplicationClass();

Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);

Range rng = adoc.Range(ref start1, ref missing);



try
{
DataSet data = new DataSet();

rng.Font.Name = "Georgia";
foreach (DataRow row in data.Tables[0].Rows)
{
rng.InsertAfter(row[0].ToString());

}

object filename = @"D:\MyWord.doc";

adoc.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

WordApp.Visible = true;

}

catch (Exception ex)
{

MessageBox.Show(ex.Message);

}
}

Note;please assign your data set and look here to more customozation http://support.microsoft.com/kb/316384


Thank you

Use Word Automation  Use Word Automation
26-Oct-09 01:02 PM
You could use the Microsoft Office x.x interop library to do this. It can be found under the "Com" objects in the "AddReferences" dialog of your windows application project.

However, the answer varies with how you would like to see the dataset in the word document. You could build a table, just lines of data . or what ever you need. 

And you need to use the corresponding word objects to do this. The answer provided above is one such example. 

C-sharp Corner has an http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx with sufficient example explaining all of these.
How to export dataset to Ms Word in winforms -Urgent  How to export dataset to Ms Word in winforms -Urgent
28-Oct-09 06:00 AM
Hi Bill
         I used your code but only one value is displaying in the word.I need to pop  the whole data of dataset into the word file.

  foreach (DataRow row in data.Tables[0].Rows)
{
rng.InsertAfter(row[0].ToString());

}

Do I need to change anything in this foreach loop.




Create New Account
help
Logging Service b9wt High Log retention limit reached. Log file 'C: \ Program Files \ Common Files \ Microsoft Shared \ Web Server Extensions \ 14 \ LOGS \ TRICOFLEX-20111030-0008.log' has been deleted. 11 / 13 e63e-4ee9-b396-3fc61e3e6b80 11 / 13 / 2011 00:08:31.87 w3wp.exe (0x0DB4) 0x0AB8 Excel Services Application Excel Calculation Services 8jg2 Medium ResourceManager.PerformCleanup: Memory Manager: CurrentSize = 536850432. 53fed7f1-b549-1a88-0000-000050f7b00c SharePoint Foundation Topology e5mc Medium WcfSendRequest: RemoteAddress: 'http: / / tricoflex:32843 / 7a4080d658ba42efa38ff6455cbc382b / BdcService.svc / http' Channel: 'Microsoft.SharePoint.BusinessData.SharedService.IBdcServiceApplication' Action: 'http: / / www.microsoft.com / Office / 2009 / BusinessDataCatalog / BusinessDataCatalogSharedService / GetLobSystemsLikeName' MessageId: 'urn:uuid:abbcffd4-6783-4121-86ca-a30f0afe866a' 5c243a60-f458-4953 hozetric.local:32843 / 7a4080d658ba42efa38ff6455cbc382b / bdcservice.svc / http' Channel: 'System.ServiceModel.Channels.ServiceChannel' Action: 'http: / / www.microsoft.com / Office / 2009 / BusinessDataCatalog / BusinessDataCatalogSharedService / GetLobSystemsLikeName' MessageId: 'urn:uuid:abbcffd4-6783-4121-86ca-a30f0afe866a' 5c243a60-f458-4953
Setup MS Office SharePoint 2007 Test / Dev Environment Authentication Problems Hello all, i like to setup a fast mistake, but currently I am reading the logfiles placed under "c: \ program files \ common files \ microsoft shared \ web server extensions \ 12 \ logs". I don't find any relavant information regarding authentication EXE (0x0980) 0x0988 Windows SharePoint Services Database 880i High . . .tem.Data.SqlClient.SqlConnection.Open() bei Microsoft.SharePoint.Utilities.SqlSession.OpenConnection() 03 / 04 / 2010 13:53:11.35 OWSTIMER.EXE (0x0980) 0x0988 13:53:11.59 OWSTIMER.EXE (0x0980) 0x0988 Windows SharePoint Services Database 880k High bei Microsoft.SharePoint.Utilities.SqlSession.ExecuteReader(SqlCommand command, CommandBehavior behavior) bei Microsoft.SharePoint.Administration.SPConfigurationDatabase.FetchId(QualifiedObjectName qName) bei Microsoft.SharePoint.Administration.SPConfigurationDatabase.GetObject(String name, Guid parentId, Type type) bei Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_Farm() bei Microsoft.SharePoint.Administration.SPFarm.FindLocal(SPFarm& farm, Boolean& isJoined) bei Microsoft.SharePoint.Administration.SPFarm.get_Local() bei
other are not processing. and am getting below one in log file as error cause: Microsoft Windows Installer 4.5 Update (x86) - Windows XP: [2] CGenericComponent::Install() expects the setup file for Microsoft Windows Installer 4.5 Update (x86) - Windows XP, but the file is not available. [08 ISetupManager::InternalInstallManager() with HRESULT -2147467259. [08 / 10 / 11, 14:26:00] VS70pgui: [2] DepCheck indicates Microsoft Windows Installer 4.5 Update (x86) - Windows XP is not installed. [08 / 10 / 11, 14:26:00] VS70pgui: [2] DepCheck indicates Microsoft Visual F# 2.0 Runtime was not attempted to be installed. [08 / 10 / 11, 14 26:00] VS70pgui: [2] DepCheck indicates Microsoft Visual Studio Macro Tools was not attempted to be installed. [08 / 10 / 11, 14:26 not attempted to be installed. [08 / 10 / 11, 14:26:01] VS70pgui: [2] DepCheck indicates Microsoft Visual Studio 2010 Professional - ENU was not attempted to be installed. [08 / 10 / 11, 14:26:01] VS70pgui: [2] DepCheck indicates Microsoft Web Deployment Tool (x86) was not attempted to be installed. [08 / 10 / 11, 14:26 01] VS70pgui: [2] DepCheck indicates Microsoft ASP.NET MVC 2 - Visual Studio 2010 Tools was not attempted to be installed. [08
2011 19:10:25.0731] [0] * ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * [11 / 17 / 2011 19:10:25.0731] [0] Starting Microsoft Exchange Server 2010 Setup [11 / 17 / 2011 19:10:25.0731] [0] * ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * [11 / 17 / 2011 Central Time (US & Canada). [11 / 17 / 2011 19:10:25.0731] [0] Operating System version: Microsoft Windows NT 6.1.7601 Service Pack 1. [11 / 17 / 2011 19:10:25.0731 17 / 2011 19:10:27.0135] [0] Exchange configuration container for the organization is 'CN = Microsoft Exchange, CN = Services, CN = Configuration, DC = mr238, DC = org'. [11 / 17 / 2011 19:10:27.0135] [0] Exchange organization container for the organization is 'CN = First Organization, CN = Microsoft Exchange, CN = Services, CN = Configuration, DC = mr238, DC = org'. [11 / 17 / 2011 19:10:27 EXCHANGE, CN = Servers, CN = Exchange Administrative Group (FYDIBOHF23SPDLT), CN = Administrative Groups, CN = First Organization, CN = Microsoft Exchange, CN = Services, CN = Configuration, DC = mr238, DC = org'. [11 / 17 / 2011 19:10:27 EXCHANGE, CN = Servers, CN = Exchange Administrative Group (FYDIBOHF23SPDLT), CN = Administrative Groups, CN = First Organization, CN = Microsoft Exchange, CN = Services, CN = Configuration, DC = mr238, DC = org'. [11 / 17 / 2011 19:10:27 15. [11 / 17 / 2011 19:11:17.0415] [0] Exchange Installation Directory : 'F: \ Program Files \ Microsoft \ Exchange Server \ V14'. [11 / 17 / 2011 19:11:17.0446] [0] Applying default role selection 17 / 2011 19:11:17.0477] [0] Setup will run from path 'F: \ Program Files \ Microsoft \ Exchange Server \ V14 \ '. [11 / 17 / 2011 19:11:17.0493] [0] InstallModeDataHandler has 0 DataHandlers