XML to generate an Excel list instance

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. IO;
Using system. xml;
Using system. xml. serialization;

Namespace businessrules
{
Public class reporttablehelper
{
Public static memorystream generaterdlc (list <reportparas> paras, string reportname)
{
# Previous version of Region
// Xmlelement thebook = NULL, theelem = NULL, root = NULL;
// Xmldocument xmldoc = new xmldocument ();

/// find the file path and read the file
// string Path = appdomain. currentdomain. basedirectory + "/" + reportname;
// xmldoc. load (PATH);
// root = xmldoc. documentelement;

// # Region Declaration
// Xmlnodelist matrixfieldlist = root. getelementsbytagname ("textbox ");
// Xmlnodelist tablefieldlist = root. getelementsbytagname ("value ");
// Xmlnodelist pointlist = root. getelementsbytagname ("Left ");
// # Endregion

// # Region processes incoming data and modifies the XML template
// Int Index = 0;
// Int pointindex = 0;
/// Locate the data column to be hidden in XML
// For (INT x = 0; x <paras. Count; X ++)
//{
// For (INT I = 0; I <matrixfieldlist. Count; I ++)
//{
// If (matrixfieldlist [I]. attributes ["name"]. value = paras [X]. paravalue)
//{
//// Hide the found Data
// Matrixfieldlist [I]. innerxml + = "<visibility> /// Set the width of the matrix data column to zero to hide the column.
// Matrixfieldlist [I]. parentnode. childnodes [0]. innertext = "0 cm ";
// Index = I; // Save the current index to hide the header.
// Break;
//}
//}

/// Locate the header column to be hidden in XML
// For (Int J = 0; j <tablefieldlist. Count; j ++)
//{
// If (tablefieldlist [J]. innertext = paras [X]. paraheader)
//{
// Pointindex = tablefieldlist. Count-2;
//// Hide the found Data
// Tablefieldlist [J]. parentnode. innerxml ++ = "<visibility> /// Reset the coordinates of each column
// While (pointindex> J)
//{
// String content = matrixfieldlist [pointindex-1]. childnodes [4]. innertext;
// Matrixfieldlist [pointindex]. childnodes [4]. innertext = content;
// Pointindex --;
//}
// Pointindex ++;
// Break;
//}
//}

// # Region sets the header column width in the table to zero to hide the column.
/// Xmlnodelist contentlist = root. getelementsbytagname ("style ");
/// For (INT temp = 0; temp <contentlist. Count; temp ++)
////{

/// Contentlist [temp]. innerxml + = "<textalign> center </textalign> ";
////}
// # Endregion
//}
// # Endregion

// # Region serializes the modified XML file into a memorystream object and returns
// Memorystream MS = new memorystream ();
// Xmlserializer serializer = new xmlserializer (typeof (xmldocument ));
// Serializer. serialize (MS, xmldoc );
// Ms. Position = 0;
// Return MS;
// # Endregion
# Endregion

# Region Declaration
Xmlelement root = NULL;
Xmldocument xmldoc = new xmldocument ();
# Endregion

# Region read the file after finding the file path
String Path = appdomain. currentdomain. basedirectory + "/" + reportname;
Xmldoc. Load (PATH );
Root = xmldoc. documentelement;
# Endregion

# region defines xmlnodelist
xmlnodelist matrixfieldlist = root. getelementsbytagname ("textbox");
xmlnodelist tablefieldlist = root. getelementsbytagname ("value");
# endregion

# Add a namespace for Region
Xmlnamespacemanager nsmanager = new xmlnamespacemanager (xmldoc. nametable );
Nsmanager. addnamespace ("RD", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner ");
Nsmanager. addnamespace ("XX", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition ");
# Endregion

# Region restructured the XM structure so that all textbox nodes in Rectangle contain left subnodes
Bool leftexsit = false; // whether the left node exists
Xmlnodelist leftlist = root. getelementsbytagname ("rectangle ");
Xmlnode reportList = NULL;
If (leftlist. Count> 0)
{
// Find the reportitems Node
For (INT B = 0; B <leftlist [0]. childnodes. Count; B ++)
{
If (leftlist [0]. childnodes [B]. Name = "reportitems ")
{
ReportList = leftlist [0]. childnodes [B];
}
}
If (reportList! = NULL)
{
For (INT temp = 0; temp <reportList. childnodes. Count; temp ++)
{
For (int A = 0; A <reportList. childnodes [temp]. childnodes. Count; A ++)
{
If (reportList. childnodes [temp]. childnodes [A]. Name = "Left ")
{
Leftexsit = true; // The left node exists.
}
}
If (! Leftexsit) // If the left node does not exist, add the left node.
{
ReportList. childnodes [temp]. innerxml + = "<left> 0 cm </left> ";
}
}
}
Else // The node does not exist and an exception is thrown.
{
Throw new exception ("must include \" reportitems \ "in the node \" rectangle \"");
}
}
# Endregion

# Region processes incoming data and modifies the XML template
Int Index = 0;
Int pointindex = 0;
// Locate the data column to be hidden in XML
For (INT x = 0; x <paras. Count; X ++)
{
For (INT I = 0; I <matrixfieldlist. Count; I ++)
{
If (matrixfieldlist [I]. attributes ["name"]. value = paras [X]. paravalue)
{
// Hide the data found
Matrixfieldlist [I]. innerxml + = "<visibility> // Set the width of the matrix data column to zero to hide the column.
Matrixfieldlist [I]. parentnode. childnodes [0]. innertext = "0 cm ";
Index = I; // Save the current index to hide the header.
Break;
}
}
String content = "";
// Locate the header column to be hidden in XML
For (Int J = 0; j <tablefieldlist. Count; j ++)
{
If (tablefieldlist [J]. innertext = paras [X]. paraheader)
{
Pointindex = tablefieldlist. Count-2;
// Hide the data found
Tablefieldlist [J]. parentnode. innerxml + = "<visibility> // Reset the coordinates of each column
While (pointindex> J)
{
// Retrieve the coordinates of all subnodes and update the coordinates of the previous nodes in sequence.
For (int c = 0; C <matrixfieldlist [pointindex-1]. childnodes. Count; C ++)
{
If (matrixfieldlist [pointindex-1]. childnodes [C]. Name = "Left ")
{
Content = matrixfieldlist [pointindex-1]. childnodes [C]. innertext;
}
}
If (content = "") // The left node does not exist. An exception occurs.
{
Throw new exception ("missing \" Left \ "Node ");
}
For (int d = 0; D <matrixfieldlist [pointindex]. childnodes. Count; D ++)
{
If (matrixfieldlist [pointindex]. childnodes [D]. Name = "Left ")
{
Matrixfieldlist [pointindex]. childnodes [D]. innertext = content;
}
}
Pointindex --;
}
Pointindex ++;
Break;
}
}
}
# Endregion

# region serializes the modified XML file into a memorystream object and returns
memorystream MS = new memorystream ();
xmlserializer serializer = new xmlserializer (typeof (xmldocument);
serializer. serialization (MS, xmldoc);
MS. position = 0;
return MS;
# endregion
}< BR >}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.