public RunParameters(XmlElement e, Provider<IAgent, string> agentProvider) { exePath = e.SelectSingleNode("./cmd").InnerText; workingDirectory = e.SelectSingleNode("./dir").InnerText; parameters = e.SelectSingleNode("./args").InnerText; agent = agentProvider(e.SelectSingleNode("./agent").InnerText); }
public void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException("value"); } XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable); nsmgr.AddNamespace("enc", "http://www.w3.org/2001/04/xmlenc#"); XmlNode node = value.SelectSingleNode("enc:CipherValue", nsmgr); XmlNode node2 = value.SelectSingleNode("enc:CipherReference", nsmgr); if (node != null) { if (node2 != null) { throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired")); } this.m_cipherValue = Convert.FromBase64String(System.Security.Cryptography.Xml.Utils.DiscardWhiteSpaces(node.InnerText)); } else { if (node2 == null) { throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired")); } this.m_cipherReference = new System.Security.Cryptography.Xml.CipherReference(); this.m_cipherReference.LoadXml((XmlElement) node2); } this.m_cachedXml = value; }
public WxEventMsg(XmlElement element) : base(element) { try { EventType = element.SelectSingleNode("Event").InnerText; } catch (Exception e) { if (element == null) throw new Exception("Element is null"+e.Message); throw new Exception("EventNode is null"+e.Message); } try { EventKey = element.SelectSingleNode("EventKey").InnerText; } catch (Exception) { string s = ""; foreach (XmlNode node in element.ChildNodes) { s += node.Name + "=" + node.InnerText + "|"; } throw new Exception(s); } }
/// <summary> /// Initializes a new instance of the XmlTabPage class. /// </summary> /// <param name="definition">XML definition.</param> internal XmlTabPage( XmlElement definition) { string name = definition.Attributes[ "name" ].Value; string tooltip = definition.Attributes[ "tooltip" ].Value; _tab = new TabPage(); _tab.Text = name; _tab.ToolTipText = tooltip; _tab.Tag = this; _tab.DockPadding.All = Property.TabPadding; XmlAttribute _modesAttr = null; _invisibleElem = (XmlElement) definition.SelectSingleNode( "invisible", FormsNamespace.NamespaceManager ); if(_invisibleElem != null) { _modesAttr = _invisibleElem.Attributes[ "modes" ]; if(_modesAttr != null) _invisibleModes = _modesAttr.Value.Split( ',' ); //Isto tem de estar aqui para não estourar mais à frente por "No registered property handler" definition.RemoveChild(definition.SelectSingleNode( "invisible", FormsNamespace.NamespaceManager )); } _disabledElem = (XmlElement)definition.SelectSingleNode("disabled", FormsNamespace.NamespaceManager); if (_disabledElem != null) { _modesAttr = _disabledElem.Attributes["modes"]; if (_modesAttr != null) _disabledModes = _modesAttr.Value.Split(','); //Isto tem de estar aqui para não estourar mais à frente por "No registered property handler" definition.RemoveChild(definition.SelectSingleNode("disabled", FormsNamespace.NamespaceManager)); } }
public AttributeDefinition(IMetaModel metaModel, XmlElement element) { this.metaModel = metaModel; token = element.GetAttribute("token"); TextBuilder.SplitPrefix(token, '.', out assetTypeToken, out name); displayName = element.GetAttribute("displayname"); attributeType = (AttributeType)Enum.Parse(typeof(AttributeType), element.GetAttribute("attributetype")); isReadonly = bool.Parse(element.GetAttribute("isreadonly")); isRequired = bool.Parse(element.GetAttribute("isrequired")); isMultivalue = bool.Parse(element.GetAttribute("ismultivalue")); var baseelement = element.SelectSingleNode("Base") as XmlElement; if (baseelement != null) { baseToken = baseelement.GetAttribute("tokenref"); } var relatedelement = element.SelectSingleNode("RelatedAsset") as XmlElement; if (relatedelement != null) { relatedAssetToken = relatedelement.GetAttribute("nameref"); } ((AssetType)AssetType).SaveAttributeDefinition(this); }
/// <summary> /// 從XML載入設定值 /// <![CDATA[ /// ]]> /// </summary> /// <param name="data"></param> public void Load(XmlElement data) { RefStudentID = data.GetAttribute("RefStudentID"); Permanent = new AddressItem(data.SelectSingleNode("Permanent/Address") as XmlElement); Mailing = new AddressItem(data.SelectSingleNode("Mailing/Address") as XmlElement); Address1 = new AddressItem(null); Address2 = new AddressItem(null); Address3 = new AddressItem(null); int index = 0; foreach (XmlElement each in data.SelectNodes("Addresses/AddressList/Address")) { if (index == 0) Address1 = new AddressItem(each); if (index == 1) Address2 = new AddressItem(each); if (index == 2) Address3 = new AddressItem(each); index++; } }
public void SetUp() { XmlCompletionDataProvider completionDataProvider = new XmlCompletionDataProvider(new XmlSchemaCompletionDataCollection(), null, String.Empty); treeViewContainerControl = new XmlTreeViewContainerControl(); treeView = treeViewContainerControl.TreeView; treeViewContainerControl.LoadXml(GetXml(), completionDataProvider); doc = treeViewContainerControl.Document; clipboardHandler = treeViewContainerControl as IClipboardHandler; htmlElement = doc.DocumentElement; bodyElement = htmlElement.FirstChild as XmlElement; paragraphElement = bodyElement.SelectSingleNode("p") as XmlElement; paragraphText = paragraphElement.SelectSingleNode("text()") as XmlText; bodyComment = bodyElement.SelectSingleNode("comment()") as XmlComment; htmlTreeNode = treeView.Nodes[0] as XmlElementTreeNode; htmlTreeNode.PerformInitialization(); bodyTreeNode = htmlTreeNode.FirstNode as XmlElementTreeNode; bodyTreeNode.PerformInitialization(); bodyCommentTreeNode = bodyTreeNode.FirstNode as XmlCommentTreeNode; paragraphTreeNode = bodyTreeNode.LastNode as XmlElementTreeNode; paragraphTreeNode.PerformInitialization(); paragraphTextTreeNode = paragraphTreeNode.FirstNode as XmlTextTreeNode; }
public ZVTCommandEnvironment(XmlElement environmentConfig) { _environmentConfig = environmentConfig; string transport = XmlHelper.ReadString(environmentConfig, "Transport"); if (transport == null) throw new ArgumentException("No transport layer specified"); if (transport.Equals("serial", StringComparison.InvariantCultureIgnoreCase)) { XmlElement serialConfig = (XmlElement)environmentConfig.SelectSingleNode("TransportSettings"); if(serialConfig == null) throw new ArgumentException("No serial configuration specified"); _transport = new RS232Transport(serialConfig); } else if (transport.Equals("network", StringComparison.InvariantCultureIgnoreCase)) { XmlElement networkConfig = (XmlElement)environmentConfig.SelectSingleNode("TransportSettings"); if (networkConfig == null) throw new ArgumentException("No network configuration specified"); _transport = new NetworkTransport(networkConfig); } }
public Sheet(XmlElement nParent) { Parent = nParent; XmlNode wNode = Parent.SelectSingleNode("./AcSmAcDbLayoutReference"); layout = new Layout((XmlElement)wNode); wNode = Parent.SelectSingleNode("./AcSmCustomPropertyBag"); wCustomPropertyBag = new CustomPropertyBag((XmlElement)wNode); }
public void Init() { base.InitFixture(); rootElement = editor.Document.DocumentElement; bodyElement = (XmlElement)rootElement.FirstChild; paragraphElement = (XmlElement)bodyElement.SelectSingleNode("p"); bodyComment = (XmlComment)bodyElement.SelectSingleNode("comment()"); paragraphText = (XmlText)paragraphElement.SelectSingleNode("text()"); }
internal override void Load(XmlElement albumElement) { base.Load(albumElement); artist = albumElement.SelectSingleNode("spotify:artist/spotify:name", NamespaceManager.Instance).InnerText; // availability in countries string availability = albumElement.SelectSingleNode("spotify:availability/spotify:territories", NamespaceManager.Instance).InnerText; availableInTerritories = availability.Split(' '); }
internal DirectoryAttribute(XmlElement node) { this.attributeName = ""; string xpath = "@dsml:name"; string str2 = "@name"; XmlNamespaceManager dsmlNamespaceManager = NamespaceUtils.GetDsmlNamespaceManager(); XmlAttribute attribute = (XmlAttribute) node.SelectSingleNode(xpath, dsmlNamespaceManager); if (attribute == null) { attribute = (XmlAttribute) node.SelectSingleNode(str2, dsmlNamespaceManager); if (attribute == null) { throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("MissingSearchResultEntryAttributeName")); } this.attributeName = attribute.Value; } else { this.attributeName = attribute.Value; } XmlNodeList list = node.SelectNodes("dsml:value", dsmlNamespaceManager); if (list.Count != 0) { foreach (XmlNode node2 in list) { XmlAttribute attribute2 = (XmlAttribute) node2.SelectSingleNode("@xsi:type", dsmlNamespaceManager); if (attribute2 == null) { this.Add(node2.InnerText); } else if (string.Compare(attribute2.Value, "xsd:string", StringComparison.OrdinalIgnoreCase) == 0) { this.Add(node2.InnerText); } else if (string.Compare(attribute2.Value, "xsd:base64Binary", StringComparison.OrdinalIgnoreCase) == 0) { byte[] buffer; string innerText = node2.InnerText; try { buffer = Convert.FromBase64String(innerText); } catch (FormatException) { throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("BadBase64Value")); } this.Add(buffer); } else if (string.Compare(attribute2.Value, "xsd:anyURI", StringComparison.OrdinalIgnoreCase) == 0) { Uri uri = new Uri(node2.InnerText); this.Add(uri); } } } }
protected override PaFolder GetFolderAttributesFromNode(XmlElement FolderElement) { // call the V2 implementation to load the values PaFolder folder = base.GetFolderAttributesFromNode(FolderElement); // V3 .dnn file format adds the optional businesscontrollerclass node to the folder node element XmlElement businessControllerElement = (XmlElement)FolderElement.SelectSingleNode("businesscontrollerclass"); if (businessControllerElement != null) { folder.BusinessControllerClass = businessControllerElement.InnerText.Trim(); } // V3 .dnn file format adds the optional friendlyname/foldername/modulename nodes to the folder node element //For these new nodes the defaults are as follows // <friendlyname>, <name> // <foldernamee>, <name>, "MyModule" // <modulename>, <friendlyname>, <name> XmlElement friendlynameElement = (XmlElement)FolderElement.SelectSingleNode("friendlyname"); if (friendlynameElement != null) { folder.FriendlyName = friendlynameElement.InnerText.Trim(); folder.ModuleName = friendlynameElement.InnerText.Trim(); } XmlElement foldernameElement = (XmlElement)FolderElement.SelectSingleNode("foldername"); if (foldernameElement != null) { folder.FolderName = foldernameElement.InnerText.Trim(); } if (folder.FolderName == "") { folder.FolderName = "MyModule"; } XmlElement modulenameElement = (XmlElement)FolderElement.SelectSingleNode("modulename"); if (modulenameElement != null) { folder.ModuleName = modulenameElement.InnerText.Trim(); } // V4.3.6 .dnn file format adds the optional compatibleversions node to the folder node element XmlElement compatibleVersionsElement = (XmlElement)(FolderElement.SelectSingleNode("compatibleversions")); if (compatibleVersionsElement != null) { folder.CompatibleVersions = compatibleVersionsElement.InnerText.Trim(); } // V4.4.0 .dnn file format adds the optional supportsprobingprivatepath node to the folder node element XmlElement supportsProbingPrivatePath = (XmlElement)(FolderElement.SelectSingleNode("supportsprobingprivatepath")); if (supportsProbingPrivatePath != null) { folder.SupportsProbingPrivatePath = Convert.ToBoolean(supportsProbingPrivatePath.InnerText.Trim()); } return folder; }
internal DirectoryControl(XmlElement el) { XmlAttribute attribute2; this.directoryControlType = ""; this.directoryControlCriticality = true; this.directoryControlServerSide = true; XmlNamespaceManager dsmlNamespaceManager = NamespaceUtils.GetDsmlNamespaceManager(); XmlAttribute attribute = (XmlAttribute) el.SelectSingleNode("@dsml:criticality", dsmlNamespaceManager); if (attribute == null) { attribute = (XmlAttribute) el.SelectSingleNode("@criticality", dsmlNamespaceManager); } if (attribute == null) { this.directoryControlCriticality = false; } else { string str = attribute.Value; switch (str) { case "true": case "1": this.directoryControlCriticality = true; goto Label_00B5; } if (!(str == "false") && !(str == "0")) { throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("BadControl")); } this.directoryControlCriticality = false; } Label_00B5: attribute2 = (XmlAttribute) el.SelectSingleNode("@dsml:type", dsmlNamespaceManager); if (attribute2 == null) { attribute2 = (XmlAttribute) el.SelectSingleNode("@type", dsmlNamespaceManager); } if (attribute2 == null) { throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("BadControl")); } this.directoryControlType = attribute2.Value; XmlElement element = (XmlElement) el.SelectSingleNode("dsml:controlValue", dsmlNamespaceManager); if (element != null) { try { this.directoryControlValue = Convert.FromBase64String(element.InnerText); } catch (FormatException) { throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("BadControl")); } } }
internal override void Load(XmlElement trackElement) { base.Load(trackElement); artist = trackElement.SelectSingleNode("spotify:artist/spotify:name", NamespaceManager.Instance).InnerText; length = TimeSpan.FromSeconds(double.Parse(trackElement.SelectSingleNode("spotify:length", NamespaceManager.Instance).InnerText)); // *** JS addition - get where this is available so we can filter out tracks that won't play. string availability = trackElement.SelectSingleNode("spotify:album/spotify:availability/spotify:territories", NamespaceManager.Instance).InnerText; availableInTerritories = availability.Split(' '); }
/// <summary> /// Constructor /// </summary> /// <param name="Element">XML element containing the item content</param> public Item(XmlElement Element) { if (Element == null) throw new ArgumentNullException("Element"); if (!Element.Name.Equals("item", StringComparison.CurrentCultureIgnoreCase)) throw new ArgumentException("Element is not an item"); XmlNamespaceManager NamespaceManager = new XmlNamespaceManager(Element.OwnerDocument.NameTable); NamespaceManager.AddNamespace("media", "http://search.yahoo.com/mrss/"); XmlNode Node = Element.SelectSingleNode("./title", NamespaceManager); if (Node != null) { Title = Node.InnerText; } Node = Element.SelectSingleNode("./link", NamespaceManager); if (Node != null) { Link = Node.InnerText; } Node = Element.SelectSingleNode("./description", NamespaceManager); if (Node != null) { Description = Node.InnerText; } Node = Element.SelectSingleNode("./author", NamespaceManager); if (Node != null) { Author = Node.InnerText; } XmlNodeList Nodes = Element.SelectNodes("./category", NamespaceManager); foreach (XmlNode TempNode in Nodes) { Categories.Add(RSS.StripIllegalCharacters(TempNode.InnerText)); } Node = Element.SelectSingleNode("./enclosure", NamespaceManager); if (Node != null) { Enclosure = new Enclosure((XmlElement)Node); } Node = Element.SelectSingleNode("./pubdate", NamespaceManager); if (Node != null) { PubDate = DateTime.Parse(Node.InnerText); } Node = Element.SelectSingleNode("./media:thumbnail", NamespaceManager); if (Node != null) { Thumbnail = new Thumbnail((XmlElement)Node); } Node = Element.SelectSingleNode("./guid", NamespaceManager); if (Node != null) { GUID = new GUID((XmlElement)Node); } }
public Game(XmlElement item) { Id = item.GetAttribute<int>("objectid", -1); Name = ((XmlElement)item.SelectSingleNode("name")).InnerText; XmlElement stats = (XmlElement)item.SelectSingleNode("stats"); MinPlayers = stats.GetAttribute<int>("minplayers", -1); MaxPlayers = stats.GetAttribute<int>("maxplayers", -1); PlayingTime = stats.GetAttribute<int>("playingtime", -1); UserRating = ((XmlElement)item.SelectSingleNode("stats/rating")).GetAttribute<double>("value", -1); BGGRating = ((XmlElement)item.SelectSingleNode("stats/rating/average")).GetAttribute<double>("value", -1); }
public static NeatGenome Read(XmlElement xmlGenome) { int inputNeuronCount=0; int outputNeuronCount=0; uint id = uint.Parse(XmlUtilities.GetAttributeValue(xmlGenome, "id")); //--- Read neuron genes into a list. NeuronGeneList neuronGeneList = new NeuronGeneList(); XmlNodeList listNeuronGenes = xmlGenome.SelectNodes("neurons/neuron"); foreach(XmlElement xmlNeuronGene in listNeuronGenes) { NeuronGene neuronGene = ReadNeuronGene(xmlNeuronGene); // Count the input and output neurons as we go. switch(neuronGene.NeuronType) { case NeuronType.Input: inputNeuronCount++; break; case NeuronType.Output: outputNeuronCount++; break; } neuronGeneList.Add(neuronGene); } //--- Read module genes into a list. List<ModuleGene> moduleGeneList = new List<ModuleGene>(); XmlNodeList listModuleGenes = xmlGenome.SelectNodes("modules/module"); foreach (XmlElement xmlModuleGene in listModuleGenes) { moduleGeneList.Add(ReadModuleGene(xmlModuleGene)); } //--- Read connection genes into a list. ConnectionGeneList connectionGeneList = new ConnectionGeneList(); XmlNodeList listConnectionGenes = xmlGenome.SelectNodes("connections/connection"); foreach(XmlElement xmlConnectionGene in listConnectionGenes) connectionGeneList.Add(ReadConnectionGene(xmlConnectionGene)); //return new NeatGenome(id, neuronGeneList, connectionGeneList, inputNeuronCount, outputNeuronCount); NeatGenome g = new NeatGenome(id, neuronGeneList, moduleGeneList, connectionGeneList, inputNeuronCount, outputNeuronCount); g.Behavior = ReadBehavior(xmlGenome.SelectSingleNode("behavior")); g.Behavior.objectives = new double[6]; g.objectives = new double[6]; // JUSTIN: Read grid/trajectory info g.GridCoords = ReadGrid(xmlGenome.SelectSingleNode("grid")); g.Behavior.trajectory = ReadTrajectory(xmlGenome.SelectSingleNode("trajectory")); return g; }
public ValidateStatement(XmlElement statementDesc) { this.Validator = statementDesc.SelectSingleNode("@Validator").InnerText; ErrorType = ParseErrorType(statementDesc); this.Description = statementDesc.SelectSingleNode("@Description").InnerText; this.AutoCorrect = bool.Parse(statementDesc.SelectSingleNode("@AutoCorrect").InnerText); if (!string.IsNullOrEmpty(statementDesc.GetAttribute("When"))) { this.When = statementDesc.GetAttribute("When"); } }
public WeewarMap(XmlElement el) { Width = Int32.Parse(el.SelectSingleNode("width").InnerText); Height = Int32.Parse(el.SelectSingleNode("height").InnerText); XmlNodeList terrains = el.SelectNodes("terrains/terrain"); foreach (XmlElement terrain in terrains) { Terrain t = new Terrain(); t.Coordinate = new Coordinate(Int32.Parse(terrain.GetAttribute("x")), Int32.Parse(terrain.GetAttribute("y"))); t.Type = Terrain.ToType(terrain.GetAttribute("type")); add(t); } }
private static XmlElement FindIdElement(XmlElement context, string idValue) { if (context == null) return null; XmlElement idReference = context.SelectSingleNode("//*[@Id=\"" + idValue + "\"]") as XmlElement; if (idReference != null) return idReference; idReference = context.SelectSingleNode("//*[@id=\"" + idValue + "\"]") as XmlElement; if (idReference != null) return idReference; return context.SelectSingleNode("//*[@ID=\"" + idValue + "\"]") as XmlElement; }
public override void LoadXml(XmlElement value) { if (value == null) throw new ArgumentNullException("value"); XmlNamespaceManager nsm = new XmlNamespaceManager(value.OwnerDocument.NameTable); nsm.AddNamespace("enc", EncryptedXml.XmlEncNamespaceUrl); nsm.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl); this.Id = Utils.GetAttribute(value, "Id", EncryptedXml.XmlEncNamespaceUrl); this.Type = Utils.GetAttribute(value, "Type", EncryptedXml.XmlEncNamespaceUrl); this.MimeType = Utils.GetAttribute(value, "MimeType", EncryptedXml.XmlEncNamespaceUrl); this.Encoding = Utils.GetAttribute(value, "Encoding", EncryptedXml.XmlEncNamespaceUrl); XmlNode encryptionMethodNode = value.SelectSingleNode("enc:EncryptionMethod", nsm); // EncryptionMethod this.EncryptionMethod = new EncryptionMethod(); if (encryptionMethodNode != null) this.EncryptionMethod.LoadXml(encryptionMethodNode as XmlElement); // Key Info this.KeyInfo = new KeyInfo(); XmlNode keyInfoNode = value.SelectSingleNode("ds:KeyInfo", nsm); if (keyInfoNode != null) this.KeyInfo.LoadXml(keyInfoNode as XmlElement); // CipherData XmlNode cipherDataNode = value.SelectSingleNode("enc:CipherData", nsm); if (cipherDataNode == null) throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_MissingCipherData")); this.CipherData = new CipherData(); this.CipherData.LoadXml(cipherDataNode as XmlElement); // EncryptionProperties XmlNode encryptionPropertiesNode = value.SelectSingleNode("enc:EncryptionProperties", nsm); if (encryptionPropertiesNode != null) { // Select the EncryptionProperty elements inside the EncryptionProperties element XmlNodeList encryptionPropertyNodes = encryptionPropertiesNode.SelectNodes("enc:EncryptionProperty", nsm); if (encryptionPropertyNodes != null) { foreach (XmlNode node in encryptionPropertyNodes) { EncryptionProperty ep = new EncryptionProperty(); ep.LoadXml(node as XmlElement); this.EncryptionProperties.Add(ep); } } } // Save away the cached value m_cachedXml = value; }
public static Pass ParseXmlElement(XmlElement el, Dictionary<string, Shader> shaders) { XmlElement vshEl = (XmlElement)el.SelectSingleNode("vshader"); XmlElement pshEl = (XmlElement)el.SelectSingleNode("pshader"); string vsh = vshEl.InnerText; string psh = pshEl.InnerText; string vshProcesses = vshEl.GetAttribute("processes"); string pshPRocesses = pshEl.GetAttribute("processes"); string[] vProcesses = null; int idx = 0; if (vshProcesses != null && vshProcesses.Length > 0) { MatchCollection matches = Regex.Matches(vshProcesses, "[a-zA-Z0-9]"); if (matches != null && matches.Count > 0) { vProcesses = new string[matches.Count]; foreach (Match match in matches) { vProcesses[idx++] = match.Groups[0].Value; } } } string[] pProcesses = null; idx = 0; if (pshPRocesses != null && pshPRocesses.Length > 0) { MatchCollection matches = Regex.Matches(pshPRocesses, "[a-zA-Z0-9]"); if (matches != null && matches.Count > 0) { pProcesses = new string[matches.Count]; foreach (Match match in matches) { pProcesses[idx++] = match.Groups[0].Value; } } } Shader vshader = null; Shader pshader = null; shaders.TryGetValue(vsh, out vshader); shaders.TryGetValue(psh, out pshader); Pass pass = new Pass((VShader)vshader, (PShader)pshader); pass.vProcesses = vProcesses; pass.pProcesses = pProcesses; return pass; }
protected override void ExecuteCore(XmlElement element) { if (!element.HasAttribute(Name)) { var attribute = element.OwnerDocument.CreateAttribute(Name); attribute.Value = Value; if (!string.IsNullOrEmpty(After)) { try { var node = element.SelectSingleNode(After); if (node != null && node is XmlAttribute) { element.Attributes.InsertAfter(attribute, node as XmlAttribute); return; } } catch (XPathException e) { var message = string.Format("'{0}' is not a valid XPath expression.", After); throw new TaskExecutionException(message, e); } } if (!string.IsNullOrEmpty(Before)) { try { var node = element.SelectSingleNode(Before); if (node != null && node is XmlAttribute) { element.Attributes.InsertBefore(attribute, node as XmlAttribute); return; } } catch (XPathException e) { var message = string.Format("'{0}' is not a valid XPath expression.", Before); throw new TaskExecutionException(message, e); } } element.Attributes.Append(attribute); } }
public static SitePublishInfo GetSitePublishInfoFromXml(XmlElement rootElem) { SitePublishInfo info = new SitePublishInfo(); XmlElement elem = rootElem.SelectSingleNode("ApplicationXml") as XmlElement; if (elem != null) info.ApplicationXml = elem.InnerText; elem = rootElem.SelectSingleNode("MapXaml") as XmlElement; if (elem != null) info.MapXaml = elem.InnerText; elem = rootElem.SelectSingleNode("BehaviorsXml") as XmlElement; if (elem != null) info.BehaviorsXml = elem.InnerText; elem = rootElem.SelectSingleNode("ColorsXaml") as XmlElement; if (elem != null) info.ColorsXaml = elem.InnerText; elem = rootElem.SelectSingleNode("ControlsXml") as XmlElement; if (elem != null) info.ControlsXml = elem.InnerText; elem = rootElem.SelectSingleNode("ToolsXml") as XmlElement; if (elem != null) info.ToolsXml = elem.InnerText; elem = rootElem.SelectSingleNode("PreviewImageBytes") as XmlElement; if (elem != null && elem.InnerText != null) info.PreviewImageBytes = Encoding.UTF8.GetBytes(elem.InnerText); elem = rootElem.SelectSingleNode("ExtensionsXapsInUse") as XmlElement; if (elem != null && elem.InnerText != null) info.ExtensionsXapsInUse = elem.InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); return info; }
/// <summary> /// Initializes a new instance of the <see cref="ErrorViewInfo"/> class. /// </summary> /// <param name="element">The info element.</param> public ErrorViewInfo(XmlElement element) { Contract.Requires<ArgumentNullException>(element != null); this.Error = element.GetAttribute("error"); var defaultContent = element.SelectSingleNode("p:default", Sage.XmlNamespaces.Manager); var developerContent = element.SelectSingleNode("p:developer", Sage.XmlNamespaces.Manager); if (defaultContent != null) this.DefaultContent = defaultContent.InnerText; if (developerContent != null) this.DeveloperContent = developerContent.InnerText; }
public virtual void DoTest(Blog blog, IBlogClient blogClient, XmlElement providerEl) { TestResultImpl results = new TestResultImpl(); DoTest(blog, blogClient, results); results.ForEach(delegate (string key, string value) { XmlElement optionsEl = (XmlElement)providerEl.SelectSingleNode("options"); if (optionsEl == null) { optionsEl = providerEl.OwnerDocument.CreateElement("options"); providerEl.AppendChild(optionsEl); } XmlElement el = (XmlElement)optionsEl.SelectSingleNode(key); if (el == null) { el = providerEl.OwnerDocument.CreateElement(key); optionsEl.AppendChild(el); } if (!el.HasAttribute("readonly", NAMESPACE_BLOGRUNNER)) { el.InnerText = value; } }); }
public WorkItemTypeDefinition(XmlElement witdElement, bool isWritable) { if (witdElement.SelectSingleNode("WORKITEMTYPE") == null) { throw new ArgumentException("Invalid definition document, missing WORKITEMTYPE element."); } _witdElement = (XmlElement)witdElement.Clone(); _isWritable = isWritable; if (!_isWritable) { _fields = _witdElement .SelectNodes("WORKITEMTYPE/FIELDS/FIELD") .Cast<XmlElement>() .Select(e => new WitdField(e)) .ToArray(); _states = _witdElement .SelectNodes("WORKITEMTYPE/WORKFLOW/STATES/STATE") .Cast<XmlElement>() .Select(e => new WitdState(e)) .ToArray(); _transitions = new HashSet<WitdTransition>(witdElement .SelectNodes("WORKITEMTYPE/WORKFLOW/TRANSITIONS/TRANSITION") .Cast<XmlElement>() .Select(e => new WitdTransition(e))); } }
public static XmlElement GetElementByAttribute( XmlElement parent, string elementName, string attributeName, string attributeValue, bool filtered ) { if ( parent == null || elementName == null || attributeName == null || attributeValue == null ) { return null; } // TODO: Implement better filtering in the xpath expression so that the multiple steps of operations are not necessary XmlElement element = null; string xPath = elementName + "[@" + attributeName + "=\"" + attributeValue + "\"]"; if ( filtered ) { FilteredElementList list = new FilteredElementList( parent.SelectNodes( xPath ) ); IEnumerator enumerator = list.GetEnumerator(); if ( enumerator.MoveNext() ) { element = (XmlElement) enumerator.Current; } } else { element = (XmlElement) parent.SelectSingleNode( xPath ); } return element; }
private static void EvaluateMeta(XmlElement root, PageScheme page) { var element = root.SelectSingleNode("Meta") as XmlElement; page.Meta = new PageMeta(); page.Meta.Interval = XmlUtility.GetAttrValue(element, "Interval"); page.Meta.LayoutStyle = XmlUtility.GetAttrValue(element, "LayoutStyle"); }
/// <summary> /// 获得xml文件中指定节点的节点数据 /// </summary> /// <param name="TableName"></param> /// <returns></returns> public static string GetNodeInfoByNodeName(string path, string nodeName) { string XmlString = ""; XmlDocument xml = new XmlDocument(); xml.Load(path); System.Xml.XmlElement root = xml.DocumentElement; System.Xml.XmlNode node = root.SelectSingleNode("//" + nodeName); if (node != null) { XmlString = node.InnerText; } return(XmlString); }
/// <summary> /// Deserializes the specified element. /// </summary> /// <param name="element">The element.</param> public override void Deserialize(System.Xml.XmlElement element) { this._assemblies = new CloneableList <string> ( ); this.OutputFile = string.Empty; this._nunitPath = string.Empty; this.RunnerPath = string.Empty; this.Timeout = null; if (string.Compare(element.Name, this.TypeName, false) != 0) { throw new InvalidCastException(string.Format("Unable to convert {0} to a {1}", element.Name, this.TypeName)); } XmlElement ele = ( XmlElement )element.SelectSingleNode("assemblies"); if (ele != null) { foreach (XmlElement aele in ele.SelectNodes("assembly")) { this.Assemblies.Add(aele.InnerText); } } string s = Util.GetElementOrAttributeValue("nunitPath", element); this.NUnitPath = s; s = Util.GetElementOrAttributeValue("runnerPath", element); if (!string.IsNullOrEmpty(s)) { this.RunnerPath = s; } s = Util.GetElementOrAttributeValue("outputfile", element); if (!string.IsNullOrEmpty(s)) { this.OutputFile = s; } s = Util.GetElementOrAttributeValue("timeout", element); if (!string.IsNullOrEmpty(s)) { int i = 0; if (int.TryParse(s, out i)) { this.Timeout = i; } } }
public void TestGetsIfThenElse() { XCRMParser parser = new XCRMParser(); System.Xml.XmlElement xmlelement = RoarExtensions.CreateXmlElement( "<if_then_else>" + "<if>" + "</if>" + "<then>" + "</then>" + "<else>" + "</else>" + "</if_then_else>" ); System.Xml.XmlNode if_node = xmlelement.SelectSingleNode("./if"); System.Xml.XmlNode then_node = xmlelement.SelectSingleNode("./then"); System.Xml.XmlNode else_node = xmlelement.SelectSingleNode("./else"); parser.crm = mockery.NewMock <IXCRMParser>(); List <Roar.DomainObjects.Requirement> mock_if_requirement_list = new List <Roar.DomainObjects.Requirement>(); List <Roar.DomainObjects.Modifier> mock_then_modifier_list = new List <Roar.DomainObjects.Modifier>(); List <Roar.DomainObjects.Modifier> mock_else_modifier_list = new List <Roar.DomainObjects.Modifier>(); Expect.AtLeastOnce.On(parser.crm).Method("ParseRequirementList").With(if_node).Will(Return.Value(mock_if_requirement_list)); Expect.AtLeastOnce.On(parser.crm).Method("ParseModifierList").With(then_node).Will(Return.Value(mock_then_modifier_list)); Expect.AtLeastOnce.On(parser.crm).Method("ParseModifierList").With(else_node).Will(Return.Value(mock_else_modifier_list)); IfThenElse m = parser.ParseAModifier(xmlelement) as IfThenElse; mockery.VerifyAllExpectationsHaveBeenMet(); Assert.IsNotNull(m); Assert.AreSame(m.if_, mock_if_requirement_list); Assert.AreSame(m.then_, mock_then_modifier_list); Assert.AreSame(m.else_, mock_else_modifier_list); }
/// <summary> /// Deserializes the specified element. /// </summary> /// <param name="element">The element.</param> public override void Deserialize(System.Xml.XmlElement element) { if (string.Compare(element.GetAttribute("type"), this.TypeName, false) != 0) { throw new InvalidCastException(string.Format("Unable to convert {0} to a {1}", element.GetAttribute("type"), this.TypeName)); } this.AutoGetSource = null; this.BranchUrl = null; this.Executable = string.Empty; this.LabelOnSuccess = null; this.WebUrlBuilder = null; this.WorkingDirectory = string.Empty; string s = Util.GetElementOrAttributeValue("autoGetSource", element); if (!string.IsNullOrEmpty(s)) { this.AutoGetSource = string.Compare(s, bool.TrueString, true) == 0; } s = Util.GetElementOrAttributeValue("tagOnSuccess", element); if (!string.IsNullOrEmpty(s)) { this.LabelOnSuccess = string.Compare(s, bool.TrueString, true) == 0; } s = Util.GetElementOrAttributeValue("branchUrl", element); if (!string.IsNullOrEmpty(s)) { this.BranchUrl = new Uri(s); } s = Util.GetElementOrAttributeValue("workingDirectory", element); if (!string.IsNullOrEmpty(s)) { this.WorkingDirectory = s; } XmlElement ele = element.SelectSingleNode("webUrlBuilder") as XmlElement; if (ele != null && (ele.HasAttributes || ele.HasChildNodes)) { // this doesn't protect against malformed Uri's, but I haven't seen checks for those anywhere else this.WebUrlBuilder = new WebUrlBuilder(); this.WebUrlBuilder.Deserialize(ele); } }
/// <summary> /// Deserializes the specified element. /// </summary> /// <param name="element">The element.</param> public override void Deserialize(System.Xml.XmlElement element) { this.ApplyLabel = null; this.AutoGetSource = null; this.CleanCopy = null; this.Culture = string.Empty; this.Executable = string.Empty; this.Password = new HiddenPassword(); this.Project = string.Empty; this.SourceSafeDirectory = string.Empty; this.Timeout = new Timeout(); this.Username = string.Empty; this.WorkingDirectory = string.Empty; string s = Util.GetElementOrAttributeValue("applyLabel", element); if (!string.IsNullOrEmpty(s)) { this.ApplyLabel = string.Compare(s, bool.TrueString, true) == 0; } s = Util.GetElementOrAttributeValue("autoGetSource", element); if (!string.IsNullOrEmpty(s)) { this.AutoGetSource = string.Compare(s, bool.TrueString, true) == 0; } s = Util.GetElementOrAttributeValue("cleanCopy", element); if (!string.IsNullOrEmpty(s)) { this.CleanCopy = string.Compare(s, bool.TrueString, true) == 0; } this.Culture = Util.GetElementOrAttributeValue("culture", element); this.Executable = Util.GetElementOrAttributeValue("executable", element); this.Password.Password = Util.GetElementOrAttributeValue("password", element); this.Project = Util.GetElementOrAttributeValue("project", element); this.SourceSafeDirectory = Util.GetElementOrAttributeValue("ssdir", element); this.Username = Util.GetElementOrAttributeValue("username", element); this.WorkingDirectory = Util.GetElementOrAttributeValue("workingDirectory", element); XmlElement ele = (XmlElement)element.SelectSingleNode("timeout"); this.Timeout.Deserialize(ele); }
public static int GetNodeCount(System.Xml.XmlElement root, string prefixPath, string xRelativePath) { //LoadXmlFile(); string xPath = prefixPath; //xPath = xPath.Replace("/", "/ns:"); XmlNode node = root.SelectSingleNode(xPath); int count = 0; if (node == null) { return(0); } foreach (XmlElement tr in node.ChildNodes) { if (tr.Name == xRelativePath) { count++; } } return(count); }
public void FromXML(System.Xml.XmlElement node) { try { this.EntityKey1 = new Guid(XmlHelper.GetAttributeValue(node, "entityid1", this.EntityKey1.ToString())); this.EntityKey2 = new Guid(XmlHelper.GetAttributeValue(node, "entityid2", this.EntityKey1.ToString())); var fieldsNode = node.SelectSingleNode("fields"); if (fieldsNode != null) { foreach (XmlNode n in fieldsNode.ChildNodes) { var source = XmlHelper.GetAttributeValue(n, "source", Guid.Empty); var target = XmlHelper.GetAttributeValue(n, "target", Guid.Empty); this.ReMappedFieldIDList.Add(source, target); } } } catch (Exception ex) { //Do Nothing } }
public Event CreateEvent(EventInformation eventInformation, System.Xml.XmlElement eventData) { FunctionCallDataElement el = new FunctionCallDataElement(eventData); uint socket = el.GetSimpleArgumentValueAsUInt(1); EndPoint ep = null; XmlNode saNode = eventData.SelectSingleNode("/event/arguments[@direction='in']/argument[2]/value/value"); string family = saNode.SelectSingleNode("field[@name='sin_family']/value/@value").Value; if (family == "AF_INET") { string addr = saNode.SelectSingleNode("field[@name='sin_addr']/value/@value").Value; int port = Convert.ToInt32(saNode.SelectSingleNode("field[@name='sin_port']/value/@value").Value); ep = new IPEndPoint(IPAddress.Parse(addr), port); } ConnectResult result; if (el.ReturnValueAsInt == 0) { result = ConnectResult.Success; } else { if (el.LastError == 10035) { result = ConnectResult.WouldBlock; } else { result = ConnectResult.Error; } } return(new ConnectEvent(eventInformation, socket, ep, result)); }
/// <summary> /// Deserializes the specified element. /// </summary> /// <param name="element">The element.</param> public override void Deserialize(System.Xml.XmlElement element) { SourceControls = new List <SourceControl> (); XmlElement scs = (XmlElement)element.SelectSingleNode("sourceControls"); if (scs != null) { foreach (XmlElement tele in scs.SelectNodes("./*")) { SourceControl scItem = this.ConvertElementToSourceControl(tele); if (scItem != null) { this._sourceControls.Add(scItem); } } } string s = Util.GetElementOrAttributeValue("requireChangesFromAll", element); if (!string.IsNullOrEmpty(s)) { this.RequireChangesFromAll = string.Compare(s, bool.TrueString, true) == 0; } }
public override void SavetoXML(System.Xml.XmlElement parent, System.Xml.XmlDocument doc) { try{ if ((parent != null) && (doc != null)) { base.SavetoXML(parent, doc); XmlElement myitem = (XmlElement)parent.SelectSingleNode("Element[@Name='" + Name.Trim() + "']"); myitem.SetAttribute("source", Source.GetStringPath()); lock (Syncobj) { foreach (KeyValuePair <string, string> pair in mapping) { XmlElement pairelem = doc.CreateElement("mapping"); pairelem.SetAttribute("key", pair.Key); pairelem.SetAttribute("value", pair.Value); myitem.AppendChild(pairelem); } } } }catch (Exception ex) { Console.WriteLine("Fehler beim Speichern von" + Name + ex.StackTrace.ToString()); } }
/// <summary> /// 在XML映射文档中的指定路径,加入当前对象信息 /// </summary> /// <param name="xpath">分级对象的路径 </param> /// <param name="o">被缓存的对象</param> public virtual void AddObject(string xpath, object o) { lock (LockHelper) { { //当缓存到期时间为0或负值,则不再放入缓存 if (_cs.TimeOut <= 0) { return; } //整理XPATH表达式信息 var newXpath = PrepareXpath(xpath); var separator = newXpath.LastIndexOf("/", StringComparison.Ordinal); //找到相关的组名 var group = newXpath.Substring(0, separator); //找到相关的对象 var element = newXpath.Substring(separator + 1); var groupNode = _objectXmlMap.SelectSingleNode(@group); //建立对象的唯一键值, 用以映射XML和缓存对象的键 var objectId = ""; var node = _objectXmlMap.SelectSingleNode(PrepareXpath(xpath)); if (node != null) { if (node.Attributes != null) { objectId = node.Attributes["objectId"].Value; } } if (objectId == "") { groupNode = CreateNode(@group); objectId = Guid.NewGuid().ToString(); //建立新元素和一个属性 for this perticular object if (_objectXmlMap.OwnerDocument != null) { var objectElement = _objectXmlMap.OwnerDocument.CreateElement(element); var objectAttribute = _objectXmlMap.OwnerDocument.CreateAttribute("objectId"); objectAttribute.Value = objectId; objectElement.Attributes.Append(objectAttribute); //为XML文档建立新元素 groupNode.AppendChild(objectElement); } } else { //建立新元素和一个属性 for this perticular object if (_objectXmlMap.OwnerDocument != null) { var objectElement = _objectXmlMap.OwnerDocument.CreateElement(element); var objectAttribute = _objectXmlMap.OwnerDocument.CreateAttribute("objectId"); objectAttribute.Value = objectId; objectElement.Attributes.Append(objectAttribute); //为XML文档建立新元素 if (groupNode != null) { if (node != null) { groupNode.ReplaceChild(objectElement, node); } } } } //向缓存加入新的对象 _cs.AddObject(objectId, o); } } }
/// <summary> /// Determines the version of the target msbuild file. /// </summary> /// <remarks> /// <para> /// This method identifies the msbuild version by reviewing the following tags in order: /// </para> /// <list type="number"> /// <item> /// <description><ProductVersion></description> /// </item> /// <item> /// <description><TargetFrameworkVersion></description> /// </item> /// <item> /// <description>ToolsVersion attribute</description> /// </item> /// </list> /// </remarks> /// <param name="docElement"> /// A <see cref="System.Xml.XmlElement"/> representing the msbuild project file. /// </param> /// <returns> /// A <see cref="NAnt.VSNet.ProductVersion"/> enum value indicating the msbuild project /// file version. /// </returns> /// <exception cref="NAnt.Core.BuildException"> /// version string found in the tags listed above is not recognized. /// </exception> protected override ProductVersion DetermineProductVersion(System.Xml.XmlElement docElement) { XmlNamespaceManager _nsMgr = new XmlNamespaceManager(new NameTable()); _nsMgr.AddNamespace("ms", docElement.NamespaceURI); // <ProductVersion> element node XmlNode _productVerNode = docElement.SelectSingleNode("ms:PropertyGroup/ms:ProductVersion", _nsMgr); // <TargetFrameworkVersion> element node XmlNode _targetNetVerNode = docElement.SelectSingleNode("ms:PropertyGroup/ms:TargetFrameworkVersion", _nsMgr); // If the <ProductVersion> element exists and it is not empty, get the // product version from it. if (_productVerNode != null && !String.IsNullOrEmpty(_productVerNode.InnerText)) { Version _ver = new Version(_productVerNode.InnerText); switch (_ver.Major) { case 8: // <ProductVersion>8.0.50727</ProductVersion> return(ProductVersion.Whidbey); case 9: // <ProductVersion>9.0.21022</ProductVersion> if (_ver.Build <= 21022) { return(ProductVersion.Orcas); } return(ProductVersion.Rosario); } // If the <TargetFrameworkVersion> element exists, get the product version from it. } else if (_targetNetVerNode != null) { string targetFrameworkVer = _targetNetVerNode.InnerText; switch (targetFrameworkVer.ToUpper().Trim()) { case "V4.0": return(ProductVersion.Rosario); case "V3.5": return(ProductVersion.Orcas); case "V2.0": return(ProductVersion.Whidbey); } // If neither of the above mentioned tags exist, look for the "ToolsVersion" // attribute in the <Project> tag. } else { XmlAttribute toolsVersionAttribute = docElement.Attributes["ToolsVersion"]; // If the ToolsVersion attribute does not exist at this point, // assume that the project is 2.0. if (toolsVersionAttribute == null) { return(ProductVersion.Whidbey); } switch (toolsVersionAttribute.Value) { case "4.0": return(ProductVersion.Rosario); case "3.5": return(ProductVersion.Orcas); case "2.0": return(ProductVersion.Whidbey); } } // Throw a buildexception if none of the version numbers above are found. throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Unknown Project version '{0}'.", ProjectPath), Location.UnknownLocation); }
protected override void Build(System.Xml.XmlElement source, string location) { #region 建立 Excel //從 Resources 將新生名冊template讀出來 Workbook template = new Workbook(); template.Open(new MemoryStream(Properties.Resources.TemporaryStudentListTemplate), FileFormatType.Excel2003); //產生 excel Workbook wb = new Aspose.Cells.Workbook(); wb.Open(new MemoryStream(Properties.Resources.TemporaryStudentListTemplate), FileFormatType.Excel2003); #endregion #region 複製樣式-預設樣式、欄寬 //設定預設樣式 wb.DefaultStyle = template.DefaultStyle; //複製樣版中前18個 Column(欄寬) for (int m = 0; m < 18; m++) { /* * 複製 template的第一個 Sheet的第 m個 Column * 到 wb的第一個 Sheet的第 m個 Column */ wb.Worksheets[0].Cells.CopyColumn(template.Worksheets[0].Cells, m, m); } #endregion #region 初始變數 /****************************** * rowi 填入學校資料用 * rowj 填入學生資料用 * num 計算清單份數 * numcount 計算每份清單頁數 * j 計算所產生清單頁數 * x 判斷個數是否為20被數用 ******************************/ int rowi = 0, rowj = 1, num = source.SelectNodes("清單").Count, numcount = 1, j = 0; bool x = false; int recCount = 0; int totalRec = source.SelectNodes("清單/異動紀錄").Count; #endregion foreach (XmlNode list in source.SelectNodes("清單")) { int i = 0; #region 找出資料總數及判斷 //找出資料總數方便評估進度 int count = list.SelectNodes("異動紀錄").Count; //判斷個數是否為20被數 if (count % 20 == 0) { x = true; } #endregion #region 異動紀錄 // 所在地代碼對照 Dictionary <string, string> gLocationCodeDict = new Dictionary <string, string>(); //將xml資料填入至excel foreach (XmlNode st in list.SelectNodes("異動紀錄")) { recCount++; if (i % 20 == 0) { #region 複製樣式-欄高、範圍 //複製樣版中前28個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 6].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText)); wb.Worksheets[0].Cells[rowi + 2, 9].PutValue(Convert.ToInt32(source.SelectSingleNode("@學期").InnerText)); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); #endregion if (j > 0) { //插入分頁(在 j * 28 跟 (j * 28) +1 中間,R跟S中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } else { rowj = 6; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 if (x != true) { wb.Worksheets[0].Cells[(28 * (j - 1)) + 26, 13].PutValue("第" + numcount + "頁,共" + Math.Ceiling((double)count / 20) + "頁"); } else { wb.Worksheets[0].Cells[(28 * (j - 1)) + 26, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); } numcount++; #endregion } #region 填入學生資料 //將學生資料填入適當的位置內 wb.Worksheets[0].Cells[rowj, 1].PutValue(st.SelectSingleNode("@學號").InnerText); wb.Worksheets[0].Cells[rowj, 3].PutValue(st.SelectSingleNode("@姓名").InnerText); string ss = st.SelectSingleNode("@出生年月日").InnerText + "\n" + st.SelectSingleNode("@身分證號").InnerText; wb.Worksheets[0].Cells[rowj, 4].PutValue(ss); try { wb.Worksheets[0].Cells[rowj, 7].PutValue(Convert.ToInt32(st.SelectSingleNode("@性別代號").InnerText)); } catch (Exception) { } wb.Worksheets[0].Cells[rowj, 8].PutValue(st.SelectSingleNode("@性別").InnerText); if (st.SelectSingleNode("@特殊身份代碼") != null) { wb.Worksheets[0].Cells[rowj, 9].PutValue(st.SelectSingleNode("@特殊身份代碼").InnerText); } // 借讀學校代碼 string LSCode = ""; if (st.SelectSingleNode("@借讀學校代碼") != null) { LSCode = st.SelectSingleNode("@借讀學校代碼").InnerText; } wb.Worksheets[0].Cells[rowj, 10].PutValue(LSCode); // 借讀科別代碼 string LDCode = ""; if (st.SelectSingleNode("@借讀科別代碼") != null) { LDCode = st.SelectSingleNode("@借讀科別代碼").InnerText; } wb.Worksheets[0].Cells[rowj, 11].PutValue(LDCode); string uCode = ""; if (st.SelectSingleNode("@異動代號") == null) { if (st.SelectSingleNode("@異動代碼") != null) { uCode = st.SelectSingleNode("@異動代碼").InnerText; } } else { uCode = st.SelectSingleNode("@異動代號").InnerText; } wb.Worksheets[0].Cells[rowj, 12].PutValue(uCode); wb.Worksheets[0].Cells[rowj, 13].PutValue(st.SelectSingleNode("@原因及事項").InnerText); //申請日期 string sD1 = ""; if (st.SelectSingleNode("@申請開始日期") != null) { sD1 += ParseCDate1(st.SelectSingleNode("@申請開始日期").InnerText); } if (st.SelectSingleNode("@申請結束日期") != null) { sD1 += "\n" + ParseCDate1(st.SelectSingleNode("@申請結束日期").InnerText); } wb.Worksheets[0].Cells[rowj, 14].PutValue(sD1); //實際日期 string sD2 = ""; if (st.SelectSingleNode("@實際開始日期") != null) { sD2 += ParseCDate1(st.SelectSingleNode("@實際開始日期").InnerText); } if (st.SelectSingleNode("@實際結束日期") != null) { sD2 += "\n" + ParseCDate1(st.SelectSingleNode("@實際結束日期").InnerText); } wb.Worksheets[0].Cells[rowj, 17].PutValue(sD2); wb.Worksheets[0].Cells[rowj, 18].PutValue(st.SelectSingleNode("@備註").InnerText); #endregion i++; rowj++; //回報進度 ReportProgress((int)(((double)recCount * 100.0) / ((double)totalRec))); } #endregion #region 若個數為20倍數,處理單一頁面 if (x == true) { #region 複製樣式-欄高、範圍 //複製樣版前28個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 6].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText)); wb.Worksheets[0].Cells[rowi + 2, 9].PutValue(Convert.ToInt32(source.SelectSingleNode("@學期").InnerText)); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); #endregion if (j > 0) { //插入分頁(在i跟i+1中間,O跟P中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 wb.Worksheets[0].Cells[(28 * (j - 1)) + 26, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); numcount++; #endregion } #endregion #region 統計人數 //填入統計人數 wb.Worksheets[0].Cells[rowj, 1].PutValue("合 計 "); wb.Worksheets[0].Cells[rowj, 3].PutValue(count.ToString() + " 名"); #endregion wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); #region 設定變數 //調整新清單所使用變數 numcount = 1; rowj = (28 * j) - 2; rowi = (28 * j); x = false; #endregion } #region 97中辦格式 Worksheet mingdao = wb.Worksheets["電子格式範本"]; Worksheet mdws = wb.Worksheets[wb.Worksheets.Add()]; mdws.Name = "借讀學生名冊"; Range range_header = mingdao.Cells.CreateRange(0, 1, false); Range range_row = mingdao.Cells.CreateRange(1, 1, false); // 107新格式 結束行要 有End 字樣 Range range_R_EndRow = mingdao.Cells.CreateRange(2, 1, false); mdws.Cells.CreateRange(0, 1, false).Copy(range_header); int mdws_index = 0; foreach (XmlElement record in source.SelectNodes("清單/異動紀錄")) { mdws_index++; mdws.Cells.CreateRange(mdws_index, 1, false).Copy(range_row); mdws.Cells[mdws_index, 0].PutValue(record.GetAttribute("班別")); mdws.Cells[mdws_index, 1].PutValue((record.ParentNode as XmlElement).GetAttribute("科別代號")); mdws.Cells[mdws_index, 2].PutValue(""); mdws.Cells[mdws_index, 3].PutValue(record.GetAttribute("學號")); mdws.Cells[mdws_index, 4].PutValue(record.GetAttribute("姓名")); mdws.Cells[mdws_index, 5].PutValue(record.GetAttribute("身分證號")); mdws.Cells[mdws_index, 6].PutValue(record.GetAttribute("註1")); mdws.Cells[mdws_index, 7].PutValue(record.GetAttribute("性別代號")); mdws.Cells[mdws_index, 8].PutValue(GetBirthdateWithoutSlash(record.GetAttribute("出生年月日"))); mdws.Cells[mdws_index, 9].PutValue(record.GetAttribute("特殊身份代碼")); mdws.Cells[mdws_index, 10].PutValue(record.GetAttribute("年級")); mdws.Cells[mdws_index, 11].PutValue(record.GetAttribute("借讀學校代碼")); mdws.Cells[mdws_index, 12].PutValue(record.GetAttribute("借讀科別代碼")); mdws.Cells[mdws_index, 13].PutValue(record.GetAttribute("異動代碼")); mdws.Cells[mdws_index, 14].PutValue(ParseCDate2(record.GetAttribute("申請開始日期"))); mdws.Cells[mdws_index, 15].PutValue(ParseCDate2(record.GetAttribute("申請結束日期"))); mdws.Cells[mdws_index, 16].PutValue(record.GetAttribute("備註")); } // 資料末底 加End mdws.Cells.CreateRange(mdws_index + 1, 1, false).Copy(range_R_EndRow); mdws.AutoFitColumns(); wb.Worksheets.RemoveAt("電子格式範本"); //範本 Worksheet TemplateWb_Cover = wb.Worksheets["借讀學生名冊封面範本"]; //實做頁面 Worksheet cover = wb.Worksheets[wb.Worksheets.Add()]; //名稱 cover.Name = "借讀學生名冊封面"; string school_code = source.SelectSingleNode("@學校代號").InnerText; string school_year = source.SelectSingleNode("@學年度").InnerText; string school_semester = source.SelectSingleNode("@學期").InnerText; //範圍 Range range_H_Cover = TemplateWb_Cover.Cells.CreateRange(0, 1, false); //range_H_Cover cover.Cells.CreateRange(0, 1, false).Copy(range_H_Cover); Range range_R_cover = TemplateWb_Cover.Cells.CreateRange(1, 1, false); // 107新格式 結束行要 有End 字樣 Range range_R_cover_EndRow = TemplateWb_Cover.Cells.CreateRange(2, 1, false); int cover_row_counter = 1; //2018/2/2 穎驊註解 ,下面是新的封面產生方式 foreach (XmlNode list in source.SelectNodes("清單")) { //每增加一行,複製一次 cover.Cells.CreateRange(cover_row_counter, 1, false).Copy(range_R_cover); string gradeYear = list.SelectSingleNode("@年級").InnerText; string deptCode = list.SelectSingleNode("@科別代碼").InnerText; //學校代碼 cover.Cells[cover_row_counter, 0].PutValue(school_code); //學年度 cover.Cells[cover_row_counter, 1].PutValue(school_year); //學期 cover.Cells[cover_row_counter, 2].PutValue(school_semester); //年級 cover.Cells[cover_row_counter, 3].PutValue(gradeYear); //科別代碼 cover.Cells[cover_row_counter, 6].PutValue(deptCode); foreach (XmlElement st in list.SelectNodes("異動名冊封面")) { string reportType = st.SelectSingleNode("@名冊別").InnerText; string classType = st.SelectSingleNode("@班別").InnerText; string updateType = st.SelectSingleNode("@上傳類別").InnerText; string disasterStudentCount = st.SelectSingleNode("@因災害申請借讀學生數").InnerText; string maladapStudentCount = st.SelectSingleNode("@因適應不良申請借讀學生數").InnerText; string playerTrainingStudentCount = st.SelectSingleNode("@因參加國家代表隊選手培集訓申請借讀學生數").InnerText; string remarksContent = st.SelectSingleNode("@備註說明").InnerText; //名冊別 cover.Cells[cover_row_counter, 4].PutValue(reportType); //班別 cover.Cells[cover_row_counter, 5].PutValue(classType); //上傳類別 cover.Cells[cover_row_counter, 7].PutValue(updateType); //因災害申請借讀學生數 cover.Cells[cover_row_counter, 8].PutValue(disasterStudentCount); //因適應不良申請借讀學生數 cover.Cells[cover_row_counter, 9].PutValue(maladapStudentCount); //因參加國家代表隊選手培集訓申請借讀學生數 cover.Cells[cover_row_counter, 10].PutValue(playerTrainingStudentCount); //備註說明 cover.Cells[cover_row_counter, 11].PutValue(remarksContent); } cover_row_counter++; } // 資料末底 加End cover.Cells.CreateRange(cover_row_counter, 1, false).Copy(range_R_cover_EndRow); #endregion wb.Worksheets.RemoveAt("借讀學生名冊封面範本"); wb.Worksheets.ActiveSheetIndex = 0; //儲存 Excel wb.Save(location, FileFormatType.Excel2003); }
protected override void Build(System.Xml.XmlElement source, string location) { #region 建立 Excel //從 Resources 將延修生學籍名冊template讀出來 Workbook template = new Workbook(); template.Open(new MemoryStream(Properties.Resources.ExtendingStudentUpdateRecordListTemplate), FileFormatType.Excel2003); //產生 excel Workbook wb = new Aspose.Cells.Workbook(); wb.Open(new MemoryStream(Properties.Resources.ExtendingStudentUpdateRecordListTemplate), FileFormatType.Excel2003); #endregion #region 複製樣式-預設樣式、欄寬 //設定預設樣式 wb.DefaultStyle = template.DefaultStyle; //複製樣版中前18個 Column(欄寬) for (int m = 0; m < 18; m++) { /* * 複製 template的第一個 Sheet的第 m個 Column * 到 wb的第一個 Sheet的第 m個 Column */ wb.Worksheets[0].Cells.CopyColumn(template.Worksheets[0].Cells, m, m); } #endregion #region 初始變數 /****************************** * rowi 填入學校資料用 * rowj 填入學生資料用 * num 計算清單份數 * numcount 計算每份清單頁數 * j 計算所產生清單頁數 * x 判斷個數是否為20被數用 ******************************/ int rowi = 0, rowj = 1, num = source.SelectNodes("清單").Count, numcount = 1, j = 0; bool x = false; int recCount = 0; int totalRec = source.SelectNodes("清單/異動紀錄").Count; #endregion foreach (XmlNode list in source.SelectNodes("清單")) { int i = 0; #region 找出資料總數及判斷 //找出資料總數方便評估進度 int count = list.SelectNodes("異動紀錄").Count; //判斷個數是否為20被數 if (count % 20 == 0) { x = true; } #endregion #region 異動紀錄 //將xml資料填入至excel foreach (XmlNode st in list.SelectNodes("異動紀錄")) { recCount++; if (i % 20 == 0) { #region 複製樣式-欄高、範圍 //複製樣版中前287個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 7].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText) + "學年度第" + Convert.ToInt32(source.SelectSingleNode("@學期").InnerText) + "學期"); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); #endregion if (j > 0) { //插入分頁(在 j * 28 跟 (j * 28) +1 中間,R跟S中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } else { rowj = 6; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 if (x != true) { wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + Math.Ceiling((double)count / 20) + "頁"); } else { wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); } numcount++; #endregion } #region 填入學生資料 //將學生資料填入適當的位置內 wb.Worksheets[0].Cells[rowj, 1].PutValue(st.SelectSingleNode("@學號").InnerText); wb.Worksheets[0].Cells[rowj, 3].PutValue(st.SelectSingleNode("@姓名").InnerText); wb.Worksheets[0].Cells[rowj, 4].PutValue(st.SelectSingleNode("@身分證號").InnerText); wb.Worksheets[0].Cells[rowj, 8].PutValue(Util.ConvertDateStr2(st.SelectSingleNode("@備查日期").InnerText) + "\n" + st.SelectSingleNode("@備查文號").InnerText); wb.Worksheets[0].Cells[rowj, 11].PutValue(st.SelectSingleNode("@異動代號").InnerText); wb.Worksheets[0].Cells[rowj, 12].PutValue(st.SelectSingleNode("@原因及事項").InnerText); if (st.SelectSingleNode("@新學號").InnerText == "") { wb.Worksheets[0].Cells[rowj, 13].PutValue(Util.ConvertDateStr2(st.SelectSingleNode("@異動日期").InnerText)); } else { wb.Worksheets[0].Cells[rowj, 13].PutValue(st.SelectSingleNode("@新學號").InnerText + "\n" + Util.ConvertDateStr2(st.SelectSingleNode("@異動日期").InnerText)); } //wb.Worksheets[0].Cells[rowj, 16].PutValue(st.SelectSingleNode("@備註").InnerText); if (st.SelectSingleNode("@特殊身份代碼") != null) { wb.Worksheets[0].Cells[rowj, 16].PutValue(st.SelectSingleNode("@特殊身份代碼").InnerText); } #endregion i++; rowj++; //回報進度 ReportProgress((int)(((double)recCount * 100.0) / ((double)totalRec))); } #endregion #region 若個數為20倍數,處理單一頁面 if (x == true) { #region 複製樣式-欄高、範圍 //複製樣版前28個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 7].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText) + "學年度第" + Convert.ToInt32(source.SelectSingleNode("@學期").InnerText) + "學期"); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); #endregion if (j > 0) { //插入分頁(在i跟i+1中間,O跟P中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); numcount++; #endregion } #endregion #region 統計人數 //填入統計人數 wb.Worksheets[0].Cells.CreateRange(rowj, 1, 1, 2).UnMerge(); wb.Worksheets[0].Cells.Merge(rowj, 1, 1, 3); wb.Worksheets[0].Cells[rowj, 1].PutValue("合 計 " + count.ToString() + " 名"); #endregion wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); #region 設定變數 //調整新清單所使用變數 numcount = 1; rowj = (28 * j) - 2; rowi = (28 * j); x = false; #endregion } Worksheet mingdao = wb.Worksheets[1]; Worksheet mdws = wb.Worksheets[1]; mdws.Name = "電子格式"; Range range_header = mingdao.Cells.CreateRange(0, 1, false); Range range_row = mingdao.Cells.CreateRange(1, 1, false); mdws.Cells.CreateRange(0, 1, false).Copy(range_header); int mdws_index = 0; DAL.DALTransfer DALTranser = new DAL.DALTransfer(); // 格式轉換 List <GovernmentalDocument.Reports.List.rpt_UpdateRecord> _data = DALTranser.ConvertRptUpdateRecord(source); // 排序 (依 班別、年級、科別代碼、異動代碼) _data = (from data in _data orderby data.ClassType, data.DeptCode, data.UpdateCode select data).ToList(); foreach (GovernmentalDocument.Reports.List.rpt_UpdateRecord rec in _data) { mdws_index++; //每增加一行,複製一次 mdws.Cells.CreateRange(mdws_index, 1, false).Copy(range_row); // 應畢業學年度 mdws.Cells[mdws_index, 0].PutValue(rec.ExpectGraduateSchoolYear); //班別 mdws.Cells[mdws_index, 1].PutValue(rec.ClassType); //科別代碼 mdws.Cells[mdws_index, 2].PutValue(rec.DeptCode); // 2 放上傳類別,請使用者自填 //學號 mdws.Cells[mdws_index, 4].PutValue(rec.StudentNumber); //姓名 mdws.Cells[mdws_index, 5].PutValue(rec.Name); //身分證字號 mdws.Cells[mdws_index, 6].PutValue(rec.IDNumber); //註1 mdws.Cells[mdws_index, 7].PutValue(rec.Comment1); //性別代碼 mdws.Cells[mdws_index, 8].PutValue(rec.GenderCode); //出生日期 mdws.Cells[mdws_index, 9].PutValue(rec.Birthday); //特殊身份代碼 mdws.Cells[mdws_index, 10].PutValue(rec.SpecialStatusCode); //異動原因代碼 mdws.Cells[mdws_index, 11].PutValue(rec.UpdateCode); //異動日期 mdws.Cells[mdws_index, 12].PutValue(rec.UpdateDate); // 異動順序 mdws.Cells[mdws_index, 13].PutValue(rec.Order); //備查日期 mdws.Cells[mdws_index, 14].PutValue(rec.LastADDate); //備查文字 mdws.Cells[mdws_index, 15].PutValue(rec.LastADDoc); //備查文號 mdws.Cells[mdws_index, 16].PutValue(rec.LastADNum); //更正後資料 string strUpdateData = string.Empty; //若是更正後資料有值則填入更正後資料 if (!string.IsNullOrEmpty(rec.NewData)) { strUpdateData = rec.NewData; } //若是新學號中有值則填入新學號 //判斷strUpdateData是否已有值,若是已有值則加入斷行符號 if (!string.IsNullOrEmpty(rec.NewStudNumber)) { strUpdateData += string.IsNullOrEmpty(strUpdateData) ? rec.NewStudNumber : "\n" + rec.NewStudNumber; } mdws.Cells[mdws_index, 17].PutValue(strUpdateData); // 註2 mdws.Cells[mdws_index, 18].PutValue(rec.Comment2); //備註說明 mdws.Cells[mdws_index, 19].PutValue(rec.Comment); } //foreach (XmlElement record in source.SelectNodes("清單/異動紀錄")) //{ // mdws_index++; // mdws.Cells.CreateRange(mdws_index, 1, false).Copy(range_row); // // 學年度 // string schoolYear = ""; // if (!string.IsNullOrEmpty(record.GetAttribute("學生編號"))) // { // SHSchool.Data.SHLeaveInfoRecord scl = SHSchool.Data.SHLeaveInfo.SelectByStudentID(record.GetAttribute("學生編號")); // if (scl.SchoolYear.HasValue) // schoolYear = scl.SchoolYear.Value.ToString(); // } // mdws.Cells[mdws_index, 0].PutValue(schoolYear); // mdws.Cells[mdws_index, 1].PutValue(record.GetAttribute("班別")); // mdws.Cells[mdws_index, 2].PutValue((record.ParentNode as XmlElement).GetAttribute("科別代號")); // mdws.Cells[mdws_index, 3].PutValue(""); // mdws.Cells[mdws_index, 4].PutValue(record.GetAttribute("學號")); // mdws.Cells[mdws_index, 5].PutValue(record.GetAttribute("姓名")); // mdws.Cells[mdws_index, 6].PutValue(record.GetAttribute("身分證號")); // mdws.Cells[mdws_index, 7].PutValue(record.GetAttribute("註1")); // mdws.Cells[mdws_index, 8].PutValue(record.GetAttribute("性別代號")); // mdws.Cells[mdws_index, 9].PutValue(GetBirthdateWithoutSlash(BL.Util.ConvertDate1(record.GetAttribute("出生年月日")))); // mdws.Cells[mdws_index, 10].PutValue(record.GetAttribute("特殊身份代碼")); //原為抓取註備欄位值 // mdws.Cells[mdws_index, 11].PutValue(record.GetAttribute("異動代號")); // mdws.Cells[mdws_index, 12].PutValue(GetBirthdateWithoutSlash(BL.Util.ConvertDate1(record.GetAttribute("異動日期")))); // mdws.Cells[mdws_index, 13].PutValue(GetBirthdateWithoutSlash(BL.Util.ConvertDate1(record.GetAttribute("備查日期")))); // mdws.Cells[mdws_index, 14].PutValue(GetADDoc(record.GetAttribute("備查文號"))); // mdws.Cells[mdws_index, 15].PutValue(GetADNo(record.GetAttribute("備查文號"))); // mdws.Cells[mdws_index, 16].PutValue(record.GetAttribute("新學號")); // mdws.Cells[mdws_index, 17].PutValue(record.GetAttribute("備註")); //} mdws.AutoFitColumns(); mdws.Cells.SetColumnWidth(5, 8.5); mdws.Cells.SetColumnWidth(11, 20); wb.Worksheets.ActiveSheetIndex = 0; //儲存 Excel wb.Save(location, FileFormatType.Excel2003); }
protected override void ExecuteTask() { if (System.IO.Directory.Exists(workdir) == false) { System.IO.Directory.CreateDirectory(workdir); } if (workdir.EndsWith("\\") == false) { workdir += "\\"; } workdir = workdir.ToLower(); // 마스터 디스크립터를 기록하자 // 알아먹기 쉽게 일단 xml로 System.Collections.ArrayList files = new System.Collections.ArrayList(); // 리스트 foreach (string path in System.IO.Directory.GetFiles(workdir, "*", System.IO.SearchOption.AllDirectories)) { if (path.Contains("\\.svn\\") == false && System.IO.Path.GetFileName(path).ToLower() != System.IO.Path.GetFileName(filename).ToLower()) { files.Add(path.ToLower().Replace(workdir, "")); } } System.Xml.XmlDocument desc = new System.Xml.XmlDocument(); if (System.IO.File.Exists(filename) == true) { desc.Load(filename); } else { desc.AppendChild(desc.CreateNode(System.Xml.XmlNodeType.XmlDeclaration, "", "")); } System.Xml.XmlElement patchinfo = (System.Xml.XmlElement)desc.SelectSingleNode("Patchinfo"); if (patchinfo == null) { patchinfo = desc.CreateElement("Patchinfo"); desc.AppendChild(patchinfo); } System.Xml.XmlElement revisions = (System.Xml.XmlElement)patchinfo.SelectSingleNode("Revisions"); if (revisions == null) { revisions = desc.CreateElement("Revisions"); patchinfo.AppendChild(revisions); } System.Xml.XmlElement packing = (System.Xml.XmlElement)revisions.SelectSingleNode("Packing"); if (packing == null) { packing = desc.CreateElement("Packing"); packing.SetAttribute("Revision", "0"); revisions.AppendChild(packing); } System.Xml.XmlElement client = (System.Xml.XmlElement)revisions.SelectSingleNode("Client"); if (client == null) { client = desc.CreateElement("Client"); client.SetAttribute("Revision", "0"); revisions.AppendChild(client); } System.Xml.XmlElement patcher = (System.Xml.XmlElement)revisions.SelectSingleNode("Patcher"); if (patcher == null) { patcher = desc.CreateElement("Patcher"); patcher.SetAttribute("Revision", "0"); revisions.AppendChild(patcher); } System.Xml.XmlElement patch = (System.Xml.XmlElement)revisions.SelectSingleNode("Patch"); if (patch == null) { patch = desc.CreateElement("Patch"); patch.SetAttribute("Revision", "0"); revisions.AppendChild(patch); } System.Xml.XmlElement filesnode = (System.Xml.XmlElement)patchinfo.SelectSingleNode("Files"); if (filesnode != null) { patchinfo.RemoveChild(filesnode); } filesnode = desc.CreateElement("Files"); patchinfo.AppendChild(filesnode); foreach (string path in files) { System.Xml.XmlElement file = desc.CreateElement("File"); System.IO.FileInfo fi = new System.IO.FileInfo(System.IO.Path.Combine(workdir, path)); file.SetAttribute("Name", path); file.SetAttribute("Size", fi.Length.ToString()); Kom2.NET.Komfile kom = new Kom2.NET.Komfile(); if (kom.Open(System.IO.Path.Combine(workdir, path)) == true) { file.SetAttribute("Checksum", string.Format("{0:x8}", kom.Adler32)); file.SetAttribute("FileTime", string.Format("{0:x8}", kom.FileTime)); kom.Close(); } else { file.SetAttribute("Checksum", string.Format("{0:x8}", Kom2.NET.AdlerCheckSum.GetAdler32(System.IO.Path.Combine(workdir, path)))); file.SetAttribute("FileTime", "0"); } filesnode.AppendChild(file); } if (System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(filename)) == false) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(filename)); } desc.Save(filename); }
protected override void Build(System.Xml.XmlElement source, string location) { #region 建立 Excel //從 Resources 將學籍異動名冊template讀出來 Workbook template = new Workbook(); template.Open(new MemoryStream(Properties.Resources.ExtendingStudentListTemplate), FileFormatType.Excel2003); //產生 excel Workbook wb = new Aspose.Cells.Workbook(); wb.Open(new MemoryStream(Properties.Resources.ExtendingStudentListTemplate), FileFormatType.Excel2003); #endregion #region 複製樣式-預設樣式、欄寬 //設定預設樣式 wb.DefaultStyle = template.DefaultStyle; //複製樣版中前18個 Column(欄寬) for (int m = 0; m < 18; m++) { /* * 複製 template的第一個 Sheet的第 m個 Column * 到 wb的第一個 Sheet的第 m個 Column */ wb.Worksheets[0].Cells.CopyColumn(template.Worksheets[0].Cells, m, m); } #endregion #region 初始變數 /****************************** * rowi 填入學校資料用 * rowj 填入學生資料用 * num 計算清單份數 * numcount 計算每份清單頁數 * j 計算所產生清單頁數 * x 判斷個數是否為20被數用 ******************************/ int rowi = 0, rowj = 1, num = source.SelectNodes("清單").Count, numcount = 1, j = 0; bool x = false; int recCount = 0; int totalRec = source.SelectNodes("清單/異動紀錄").Count; #endregion foreach (XmlNode list in source.SelectNodes("清單")) { int i = 0; #region 找出資料總數及判斷 //找出資料總數方便評估進度 int count = list.SelectNodes("異動紀錄").Count; //判斷個數是否為20被數 if (count % 20 == 0) { x = true; } #endregion #region 異動紀錄 //將xml資料填入至excel foreach (XmlNode st in list.SelectNodes("異動紀錄")) { recCount++; if (i % 20 == 0) { #region 複製樣式-欄高、範圍 //複製樣版中前287個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 7].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText) + " 學年度 第 " + Convert.ToInt32(source.SelectSingleNode("@學期").InnerText) + " 學期"); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); wb.Worksheets[0].Cells[rowi + 2, 14].PutValue(list.SelectSingleNode("@年級").InnerText); #endregion if (j > 0) { //插入分頁(在 j * 28 跟 (j * 28) +1 中間,R跟S中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } else { rowj = 6; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 if (x != true) { wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + Math.Ceiling((double)count / 20) + "頁"); } else { wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); } numcount++; #endregion } #region 填入學生資料 //將學生資料填入適當的位置內 wb.Worksheets[0].Cells[rowj, 1].PutValue(st.SelectSingleNode("@學號").InnerText); wb.Worksheets[0].Cells[rowj, 3].PutValue(st.SelectSingleNode("@姓名").InnerText); wb.Worksheets[0].Cells[rowj, 4].PutValue(st.SelectSingleNode("@身分證號").InnerText); wb.Worksheets[0].Cells[rowj, 8].PutValue(st.SelectSingleNode("@備查日期").InnerText + "\n" + st.SelectSingleNode("@備查文號").InnerText); wb.Worksheets[0].Cells[rowj, 11].PutValue(st.SelectSingleNode("@異動代號").InnerText); wb.Worksheets[0].Cells[rowj, 12].PutValue(st.SelectSingleNode("@原因及事項").InnerText); if (st.SelectSingleNode("@新學號").InnerText == "") { wb.Worksheets[0].Cells[rowj, 13].PutValue(st.SelectSingleNode("@異動日期").InnerText); } else { wb.Worksheets[0].Cells[rowj, 13].PutValue(st.SelectSingleNode("@新學號").InnerText + "\n" + st.SelectSingleNode("@異動日期").InnerText); } wb.Worksheets[0].Cells[rowj, 16].PutValue(st.SelectSingleNode("@備註").InnerText); #endregion i++; rowj++; //回報進度 ReportProgress((int)(((double)recCount * 100.0) / ((double)totalRec))); } #endregion #region 若個數為20倍數,處理單一頁面 if (x == true) { #region 複製樣式-欄高、範圍 //複製樣版前28個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 7].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText) + " 學年度 第 " + Convert.ToInt32(source.SelectSingleNode("@學期").InnerText) + " 學期"); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); #endregion if (j > 0) { //插入分頁(在i跟i+1中間,O跟P中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); numcount++; #endregion } #endregion #region 統計人數 //填入統計人數 wb.Worksheets[0].Cells.CreateRange(rowj, 1, 1, 2).UnMerge(); wb.Worksheets[0].Cells.Merge(rowj, 1, 1, 3); wb.Worksheets[0].Cells[rowj, 1].PutValue("合 計 " + count.ToString() + " 名"); #endregion wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); #region 設定變數 //調整新清單所使用變數 numcount = 1; rowj = (28 * j) - 2; rowi = (28 * j); x = false; #endregion } //儲存 Excel wb.Save(location, FileFormatType.Excel2003); }
public static bool IsPluginCompatible(System.Xml.XmlElement rootNode) { XmlNode versionNode = rootNode.SelectSingleNode("CompatibleVersion/Items"); if (versionNode == null) { return(false); } var minRequiredVersion = new Version(MinRequiredVersionDefault); var designedForVersion = new Version(1, 0, 0, 0); foreach (XmlNode node in versionNode.ChildNodes) { XmlNode minVersionNode = node.SelectSingleNode("MinRequiredVersion"); XmlNode designedVersionNode = node.SelectSingleNode("DesignedForVersion"); if (minVersionNode != null) { minRequiredVersion = new Version(minVersionNode.InnerText); } if (designedForVersion == null) { return(false); } designedForVersion = new Version(designedVersionNode.InnerText); break; //Break cause we only check first instance?? } CheckLoadedAssemblies(); Version lastFullyBreakingVersion; if (CompareVersions(AppVersion, minRequiredVersion) < 0 || // MP version is too old (SubSystemVersions.TryGetValue("*", out lastFullyBreakingVersion) && CompareVersions(lastFullyBreakingVersion, designedForVersion) > 0)) // MP breaking version after plugin released { return(false); } List <string> subsystemsUsed = new List <string>(); XmlNode subsystemNode = rootNode.SelectSingleNode("SubSystemsUsed/Items"); if (subsystemNode == null) { return(false); } foreach (XmlNode node in subsystemNode.ChildNodes) { XmlAttribute nameAttrib = node.Attributes["Name"]; if (nameAttrib == null || string.IsNullOrEmpty(nameAttrib.InnerText)) { continue; } subsystemsUsed.Add(nameAttrib.InnerText); } if (subsystemsUsed.Count == 0) { return(true); } Version ver; // Have all used subsystem known versions and prior to the one the plugin was designed for? return(subsystemsUsed.All(attr => SubSystemVersions.TryGetValue(attr, out ver) && CompareVersions(ver, designedForVersion) <= 0)); }
private bool ReadAndRewriteXmlData(UploadedFile uploadedFile) { XmlDocument doc = new XmlDocument(); try { using (MemoryStream zipToOpen = new MemoryStream(uploadedFile.FileContent)) { using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read)) { //////////////////////////app.xml//////////////////////////////////////// //берем конкретный файл который нужно считать ZipArchiveEntry readmeEntry = archive.GetEntry("docProps/app.xml"); //считвываем поток из конкретного файла System.IO.Stream entryStream = readmeEntry.Open(); doc = new XmlDocument(); //передаем паток для обработки xml файлов doc.Load(entryStream); // получим корневой элемент System.Xml.XmlElement root = doc.DocumentElement; // обход всех узлов в корневом элементе до изменения данных foreach (System.Xml.XmlNode childnode in root.ChildNodes) { uploadedFile.OldXmlData.Add(childnode.Name, childnode.InnerText); } /////////////////////////////core.xml///////////////////////////////////// //берем конкретный файл который нужно считать и модефицировать readmeEntry = archive.GetEntry("docProps/core.xml"); //считвываем поток из конкретного файла entryStream = readmeEntry.Open(); //передаем паток для обработки xml файлов doc.Load(entryStream); //создаем менеджер пространств имен и описываем его XmlNamespaceManager xs = new XmlNamespaceManager(doc.NameTable); xs.AddNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); xs.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); xs.AddNamespace("dcterms", "http://purl.org/dc/terms/"); xs.AddNamespace("dcmitype", "http://purl.org/dc/dcmitype/"); xs.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); // получим корневой элемент root = doc.DocumentElement; // обход всех узлов в корневом элементе до изменения данных foreach (System.Xml.XmlNode childnode in root.ChildNodes) { uploadedFile.OldXmlData.Add(childnode.Name, childnode.InnerText); } //////////////////////МОДЕФИЦИРУЕМ УЗЛЫ/////////////////// //the tag - dc:title XmlNode myNode = root.SelectSingleNode("dc:title", xs); if (myNode != null) { myNode.InnerText = "The best title"; } //the tag - dc:subject myNode = root.SelectSingleNode("dc:subject", xs); if (myNode != null) { myNode.InnerText = "Some a new subject of the article"; } //the tag - dc:creator myNode = root.SelectSingleNode("dc:creator", xs); if (myNode != null) { myNode.InnerText = "The king of rings"; } //the tag - cp:keywords myNode = root.SelectSingleNode("cp:keywords", xs); if (myNode != null) { myNode.InnerText = "blablabla"; } //the tag - dc:description myNode = root.SelectSingleNode("dc:description", xs); if (myNode != null) { myNode.InnerText = "A new description this document"; } //the tag - cp:lastModifiedBy myNode = root.SelectSingleNode("cp:lastModifiedBy", xs); if (myNode != null) { myNode.InnerText = "It is Alex!!!!!!!!!!!!!!!!"; } //the tag - cp:revision myNode = root.SelectSingleNode("cp:revision", xs); if (myNode != null) { myNode.InnerText = new Random().Next(1, 1000).ToString(); } //the tag - dcterms:created myNode = root.SelectSingleNode("dcterms:created", xs); DateTimeOffset dateTimeOffset; if (myNode != null) { dateTimeOffset = DateTimeOffset.ParseExact(myNode.InnerText.ToString(), "yyyy-MM-dd'T'HH:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture); myNode.InnerText = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ssZ"); } //the tag - dcterms:modified myNode = root.SelectSingleNode("dcterms:modified", xs); if (myNode != null) { dateTimeOffset = DateTimeOffset.ParseExact(myNode.InnerText.ToString(), "yyyy-MM-dd'T'HH:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture); myNode.InnerText = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ssZ"); } } } using (MemoryStream zipStream = new MemoryStream()) { //считали данные в поток zipStream.Write(uploadedFile.FileContent, 0, uploadedFile.FileContent.Length); using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Update)) { archive.GetEntry("docProps/core.xml").Delete(); ZipArchiveEntry readmeEntry = archive.CreateEntry("docProps/core.xml"); string strFromDoc = doc.InnerXml.ToString(); Console.WriteLine(strFromDoc); using (StreamWriter writer = new StreamWriter(readmeEntry.Open())) { writer.WriteLine(strFromDoc); } } uploadedFile.FileContent = zipStream.ToArray(); } } catch (InvalidDataException ex) { return(false); } return(true); }
/// <summary>根据Xml元素加载对象</summary> /// <param name="element">Xml元素</param> public void Deserialize(System.Xml.XmlElement element) { XmlNode node = null; // Scence node = element.SelectSingleNode("scence"); this.Variables["scence"] = (node == null) ? "default" : node.InnerText; // Table node = element.SelectSingleNode("table"); this.Table = (node == null) ? string.Empty : node.InnerText; // Fields node = element.SelectSingleNode("fileds"); this.Fields.Clear(); if (node != null) { string[] fields = node.InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string field in fields) { this.Fields.Add(field); } } // Where XmlNodeList nodes = element.SelectNodes("where/key"); this.Where.Clear(); foreach (XmlNode item in nodes) { if (item.Attributes["type"] == null || item.Attributes["type"].Value == "string") { this.Where.Add(item.Attributes["name"].Value, item.InnerText); } else if (item.Attributes["type"].Value == "int") { this.Where.Add(item.Attributes["name"].Value, Convert.ToInt32(item.InnerText)); } else if (item.Attributes["type"].Value == "long") { this.Where.Add(item.Attributes["name"].Value, Convert.ToInt64(item.InnerText)); } else if (item.Attributes["type"].Value == "decimal") { this.Where.Add(item.Attributes["name"].Value, Convert.ToDecimal(item.InnerText)); } else if (item.Attributes["type"].Value == "date") { this.Where.Add(item.Attributes["name"].Value, Convert.ToDateTime(item.InnerText)); } } // Orders node = element.SelectSingleNode("orders"); this.Orders.Clear(); if (node != null) { string[] orders = node.InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string order in orders) { this.Orders.Add(order); } } // Length node = element.SelectSingleNode("length"); if (node != null) { this.Length = Convert.ToInt32(node.InnerText); } }
public override void Deserialize(Version documentVersion, System.Xml.XmlElement node) { base.Deserialize(documentVersion, node); Hyperlink = node.GetAttribute("hyperlink"); Folded = ST.GetBoolDefault(node.GetAttribute("folded")); // if (documentVersion >= Document.DV_3) // 新 { CustomWidth = ST.GetInt(node.GetAttribute("custom_width")); CustomHeight = ST.GetInt(node.GetAttribute("custom_height")); } else { CustomWidth = ST.GetInt(node.GetAttribute("width")); CustomHeight = ST.GetInt(node.GetAttribute("height")); } TextBounds = ST.GetRectangle(node.GetAttribute("text_b"), TextBounds); RemarkIconBounds = ST.GetRectangle(node.GetAttribute("remark_b"), RemarkIconBounds); FoldingButton = ST.GetRectangle(node.GetAttribute("fold_btn_b"), FoldingButton); XmlElement styleNode = node.SelectSingleNode("style") as XmlElement; if (styleNode != null) { Style.Deserialize(documentVersion, styleNode); } // var linkNodes = node.SelectNodes("links/link"); foreach (XmlElement linkNode in linkNodes) { Link link = new Link(); link.Deserialize(documentVersion, linkNode); Links.Add(link); } // var widgetNodes = node.SelectNodes("widgets/widget"); foreach (XmlElement widgetNode in widgetNodes) { var widget = Widget.DeserializeWidget(documentVersion, widgetNode); if (widget != null) { Widgets.Add(widget); } } // XmlNodeList nodes = node.SelectNodes("nodes/node"); foreach (XmlElement subNode in nodes) { Topic subTopic = new Topic(); subTopic.Deserialize(documentVersion, subNode); Children.Add(subTopic); } // if (!Children.IsNullOrEmpty()) { XmlNodeList lines = node.SelectNodes("lines/line"); foreach (XmlElement lineNode in lines) { var line = new TopicLine(); line.Deserialize(documentVersion, lineNode); var targetID = lineNode.GetAttribute("target"); var target = Children.Find(c => StringComparer.OrdinalIgnoreCase.Equals(c.ID, targetID)); if (target != null) { line.SetTarget(target); Lines.Add(line); } } } // }
protected override void Build(System.Xml.XmlElement source, string location) { Workbook template = new Workbook(); //從Resources把Template讀出來 template.Open(new MemoryStream(Properties.Resources.GraduatingStudentListTemplate), FileFormatType.Excel2003); //要產生的excel檔 Workbook wb = new Aspose.Cells.Workbook(); wb.Open(new MemoryStream(Properties.Resources.GraduatingStudentListTemplate), FileFormatType.Excel2003); Worksheet ws = wb.Worksheets[0]; //頁面間隔幾個row int next = 24; //索引 int index = 0; //範本範圍 Range tempRange = template.Worksheets[0].Cells.CreateRange(0, 24, false); //總共幾筆異動紀錄 int count = 0; int totalRec = source.SelectNodes("清單/異動紀錄").Count; foreach (XmlNode list in source.SelectNodes("清單")) { //產生清單第一頁 //for (int row = 0; row < next; row++) //{ // ws.Cells.CopyRow(template.Worksheets[0].Cells, row, row + index); //} ws.Cells.CreateRange(index, next, false).Copy(tempRange); //Page int currentPage = 1; int totalPage = (list.ChildNodes.Count / 18) + 1; //寫入名冊類別 if (source.SelectSingleNode("@類別").InnerText == "畢業名冊") { ws.Cells[index, 0].PutValue(ws.Cells[index, 0].StringValue.Replace("□畢業", "■畢業")); } else { ws.Cells[index, 0].PutValue(ws.Cells[index, 0].StringValue.Replace("□結業", "■結業")); } ////寫入代號 //ws.Cells[index,6].PutValue("代碼:"+source.SelectSingleNode("@學校代號").InnerText+"-"+list.SelectSingleNode("@科別代號").InnerText); ////寫入校名、學年度、學期、科別 //ws.Cells[index+2, 0].PutValue("校名:" + source.SelectSingleNode("@學校名稱").InnerText); //ws.Cells[index+2, 4].PutValue(source.SelectSingleNode("@學年度").InnerText + "學年度 第" + source.SelectSingleNode("@學期").InnerText + "學期"); //ws.Cells[index+2, 6].PutValue(list.SelectSingleNode("@科別").InnerText); //寫入資料 int recCount = 0; int dataIndex = index + 5; for (; currentPage <= totalPage; currentPage++) { //寫入代號 ws.Cells[index, 6].PutValue("代碼:" + source.SelectSingleNode("@學校代號").InnerText + "-" + list.SelectSingleNode("@科別代號").InnerText); //寫入校名、學年度、學期、科別 ws.Cells[index + 2, 0].PutValue("校名:" + source.SelectSingleNode("@學校名稱").InnerText); ws.Cells[index + 2, 4].PutValue(source.SelectSingleNode("@學年度").InnerText + "學年度 第" + source.SelectSingleNode("@學期").InnerText + "學期"); ws.Cells[index + 2, 6].PutValue(list.SelectSingleNode("@科別").InnerText); //複製頁面 if (currentPage + 1 <= totalPage) { ws.Cells.CreateRange(index + next, next, false).Copy(tempRange); //寫入名冊類別 if (source.SelectSingleNode("@類別").InnerText == "畢業名冊") { ws.Cells[index + next, 0].PutValue(ws.Cells[index + next, 0].StringValue.Replace("□畢業", "■畢業")); } else { ws.Cells[index + next, 0].PutValue(ws.Cells[index + next, 0].StringValue.Replace("□結業", "■結業")); } } //填入資料 for (int i = 0; i < 18 && recCount < list.ChildNodes.Count; i++, recCount++) { //MsgBox.Show(i.ToString()+" "+recCount.ToString()); XmlNode rec = list.SelectNodes("異動紀錄")[recCount]; ws.Cells[dataIndex, 0].PutValue(rec.SelectSingleNode("@學號").InnerText + "\n" + rec.SelectSingleNode("@姓名").InnerText); ws.Cells[dataIndex, 1].PutValue(rec.SelectSingleNode("@性別代號").InnerText.ToString()); ws.Cells[dataIndex, 2].PutValue(rec.SelectSingleNode("@性別").InnerText); string ssn = ""; if (rec.SelectSingleNode("@身分證號") != null) { ssn = rec.SelectSingleNode("@身分證號").InnerText; } if (ssn == "") { if (rec.SelectSingleNode("@身份證號") != null) { ssn = rec.SelectSingleNode("@身份證號").InnerText; } } ws.Cells[dataIndex, 3].PutValue(Util.ConvertDateStr2(rec.SelectSingleNode("@生日").InnerText) + "\n" + ssn); if (rec.SelectSingleNode("@最後異動代號") != null) { ws.Cells[dataIndex, 4].PutValue(rec.SelectSingleNode("@最後異動代號").InnerText.ToString()); } ws.Cells[dataIndex, 5].PutValue(Util.ConvertDateStr2(rec.SelectSingleNode("@備查日期").InnerText) + "\n" + rec.SelectSingleNode("@備查文號").InnerText); ws.Cells[dataIndex, 6].PutValue(rec.SelectSingleNode("@畢業證書字號").InnerText); //ws.Cells[dataIndex, 7].PutValue(rec.SelectSingleNode("@備註").InnerText); if (rec.SelectSingleNode("@特殊身份代碼") != null) { ws.Cells[dataIndex, 7].PutValue(rec.SelectSingleNode("@特殊身份代碼").InnerText); } dataIndex++; count++; } //計算合計 if (currentPage == totalPage) { ws.Cells[dataIndex, 0].PutValue("合計"); ws.Cells[dataIndex, 1].PutValue(list.ChildNodes.Count.ToString()); //ws.Cells[index + 22, 0].PutValue("合計"); //ws.Cells[index + 22, 1].PutValue(list.ChildNodes.Count.ToString()); } //分頁 ws.Cells[index + 23, 6].PutValue("第 " + currentPage + " 頁,共 " + totalPage + " 頁"); ws.HPageBreaks.Add(index + 24, 8); //索引指向下一頁 index += next; dataIndex = index + 5; //回報進度 ReportProgress((int)(((double)count * 100.0) / ((double)totalRec))); } } #region 畢業異動,電子格式 //範本 Worksheet TemplateWb = wb.Worksheets["電子格式範本"]; //實做頁面 Worksheet DyWb = wb.Worksheets[wb.Worksheets.Add()]; //名稱 DyWb.Name = "電子格式"; //範圍 Range range_H = TemplateWb.Cells.CreateRange(0, 1, false); Range range_R = TemplateWb.Cells.CreateRange(1, 1, false); //拷貝range_H DyWb.Cells.CreateRange(0, 1, false).Copy(range_H); int DyWb_index = 0; foreach (XmlElement Record in source.SelectNodes("清單/異動紀錄")) { DyWb_index++; //每增加一行,複製一次 DyWb.Cells.CreateRange(DyWb_index, 1, false).Copy(range_R); //班別 DyWb.Cells[DyWb_index, 0].PutValue(Record.GetAttribute("班別")); //科別代碼 DyWb.Cells[DyWb_index, 1].PutValue((Record.ParentNode as XmlElement).GetAttribute("科別代號")); // 上傳類別 //學號 DyWb.Cells[DyWb_index, 3].PutValue(Record.GetAttribute("學號")); //姓名 DyWb.Cells[DyWb_index, 4].PutValue(Record.GetAttribute("姓名")); //身分證字號 if (Record.GetAttribute("身分證號") == "") { DyWb.Cells[DyWb_index, 5].PutValue(Record.GetAttribute("身份證號")); } else { DyWb.Cells[DyWb_index, 5].PutValue(Record.GetAttribute("身分證號")); } //註1 DyWb.Cells[DyWb_index, 6].PutValue(Record.GetAttribute("註1")); //性別代碼 DyWb.Cells[DyWb_index, 7].PutValue(Record.GetAttribute("性別代號")); //出生日期 if (!string.IsNullOrEmpty(Record.GetAttribute("生日"))) { DyWb.Cells[DyWb_index, 8].PutValue(GetBirthdateWithoutSlash(Record.GetAttribute("生日"))); } else { DyWb.Cells[DyWb_index, 8].PutValue(GetBirthdateWithoutSlash(Record.GetAttribute("生日1"))); } // 特殊身分代碼 DyWb.Cells[DyWb_index, 9].PutValue(Record.GetAttribute("特殊身分代碼")); // 年級 DyWb.Cells[DyWb_index, 10].PutValue(Record.GetAttribute("年級")); // 學籍異動代碼 DyWb.Cells[DyWb_index, 11].PutValue(Record.GetAttribute("最後異動代號")); //學籍異動文字 DyWb.Cells[DyWb_index, 12].PutValue(Util.GetDocNo_Doc(Record.GetAttribute("備查文號"))); //學籍異動文號 DyWb.Cells[DyWb_index, 13].PutValue(Util.GetDocNo_No(Record.GetAttribute("備查文號"))); // 學籍異動核准日期 DyWb.Cells[DyWb_index, 14].PutValue(Util.ConvertDate1(Record.GetAttribute("備查日期"))); //畢業證書字號 DyWb.Cells[DyWb_index, 15].PutValue(Record.GetAttribute("畢業證書字號")); //備註說明 DyWb.Cells[DyWb_index, 16].PutValue(Record.GetAttribute("備註")); } DyWb.AutoFitColumns(); wb.Worksheets.RemoveAt("電子格式範本"); #endregion wb.Worksheets.ActiveSheetIndex = 0; //儲存 wb.Save(location, FileFormatType.Excel2003); }
private void scanXMLFilesThread() { while (true) { try { IDatabase db = redis.GetDatabase(); string key = this.Text + "live"; string value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); db.StringSet(key, value); } catch (Exception ee) { CommonTools.writeLog("redis 写入key value 异常!" + ee.ToString(), logpath, "error"); } string[] mediaMd5files = Directory.GetFiles(Properties.Settings.Default.scanstpFilePath, "*.md5sum", SearchOption.TopDirectoryOnly); //扫描arcstp打包完成后的素材目录 //判断文件素材是否已经做过 foreach (string mediaMd5file in mediaMd5files) { string mediafile = Properties.Settings.Default.scanstpFilePath + "\\" + Path.GetFileNameWithoutExtension(mediaMd5file); if (!File.Exists(mediafile)) { mediafile = mediafile + ".mxf"; } try { FileInfo fimedia = new FileInfo(mediafile); string extens = fimedia.Extension; if (!extens.ToLower().Equals(Properties.Settings.Default.fileExtension)) //非mxf文件 { CommonTools.writeLog("非avid mxf文件 不处理!" + mediafile, logpath, "info"); SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + "非avid mxf文件 不处理:" + Path.GetFileName(mediafile) + "\n"); continue; } if (IsFileInUse(mediafile)) { continue; //该文件正在被使用 } else //不再被使用 { CommonTools.writeLog("开始MediaManager--avidin流程:" + mediafile, logpath, "info"); SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + "开始开始MediaManager---avidin流程:" + Path.GetFileName(mediafile) + "\n"); //生成count文件 if (!Directory.Exists(Application.StartupPath + "\\counts")) { Directory.CreateDirectory(Application.StartupPath + "\\counts"); } string newcountfile = Application.StartupPath + "\\counts\\" + Path.GetFileNameWithoutExtension(mediafile) + "count.xml"; try { if (!File.Exists(newcountfile)) { File.Copy(Application.StartupPath + "\\counts.xml", newcountfile, true); } XmlDocument doc = new XmlDocument(); doc.Load(newcountfile); System.Xml.XmlElement root = doc.DocumentElement; XmlNode countnode = root.SelectSingleNode("/root/counts"); string nowcount = countnode.InnerText; int newcount = Convert.ToInt32(nowcount) + 1; countnode.InnerText = newcount.ToString(); doc.Save(newcountfile); if (newcount > Properties.Settings.Default.errorRetryCounts) { //对文件进行重命名 string newerrorfile = Properties.Settings.Default.scanstpFilePath + "\\" + Path.GetFileName(mediafile) + ".error"; if (!File.Exists(newerrorfile)) { try { File.Move(mediafile, newerrorfile); CommonTools.writeLog("对素材进行出错处理:" + newerrorfile, logpath, "info"); SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + "对素材进行出错处理:" + Path.GetFileName(mediafile) + "\n"); } catch (Exception ee) { CommonTools.writeLog("对素材进行出错处理失败:" + newerrorfile + ee.ToString(), logpath, "error"); } } continue; } //超过重试次数 } catch (Exception ee) { CommonTools.writeLog("生成文件统计失败!" + ee.ToString(), logpath, "error"); SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + "生成文件统计失败!" + "\n"); continue; } string mxffilename = replaceSpecialSQLSyntax(mediafile); mxffilename = mxffilename.Replace(" ", ""); if (mediafile.Equals(mxffilename)) { // } else //mpg文件 需要改名 { try { File.Move(mediafile, mxffilename); CommonTools.writeLog("素材修改名称成功!" + mxffilename, logpath, "info"); SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + "素材修改名称成功:" + Path.GetFileName(mxffilename) + "\n"); } catch (Exception ee) { CommonTools.writeLog("素材修改名称失败!" + Path.GetFileName(mxffilename) + ee.ToString(), logpath, "info"); continue; } } //从节目名称中获取节目ID 从oracle中获取节目ID string hrfile01 = Path.GetFileNameWithoutExtension(mediafile); string getprogramid = ""; int findhr = hrfile01.IndexOf("_HR_HD"); try { if (findhr > 20) //往前数20个字段获取节目ID { getprogramid = hrfile01.Substring(findhr - 20, 20); } } catch (Exception ee) { CommonTools.writeLog("获取节目ID异常:" + hrfile01 + " " + ee.ToString(), logpath, "error"); SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + "获取节目ID异常:" + hrfile01 + "\n"); } string programID = getprogramid; CommonTools.writeLog("获取节目ID:" + programID, logpath, "info"); XnewsInfo xinfo = new XnewsInfo(); xinfo.ChannelPath = Properties.Settings.Default.site; xinfo.ProgramID = programID; xinfo.MediafilePath = mxffilename; xinfo.Mediafilename = Path.GetFileName(mxffilename); xinfo.Creator = "mmadmin"; if (programID.Length == 0) { CommonTools.writeLog("获取节目ID为空,为非MediaMangerSTP生成的文件!" + hrfile01, logpath, "error"); xinfo.ProgramID = DateTime.Now.ToString("yyyyMMddHHmmssfff"); xinfo.Title = Path.GetFileNameWithoutExtension(mediafile); //直接复制mxf到内网 并生成videoxml //复制视频文件 string destvideo = Properties.Settings.Default.destVideoPath + "\\" + Path.GetFileName(xinfo.MediafilePath); try { CommonTools.writeLog("开始复制视频文件:" + destvideo, logpath, "info"); SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + "开始复制视频文件:" + destvideo + "\n"); File.Copy(xinfo.MediafilePath, destvideo, true); CommonTools.writeLog("复制视频文件成功:" + destvideo, logpath, "info"); SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + "复制视频文件成功:" + destvideo + "\n"); //复制视频文件xml //生成导入的xml文件 createVideoInfo(xinfo); } catch (Exception ee) { CommonTools.writeLog("处理非MediaMangerSTP生成的文件流程异常!" + destvideo + ee.ToString(), logpath, "error"); } continue; } string scripPath = Properties.Settings.Default.scanScripPath + "\\" + programID; //查询oracle数据库 根据节目ID查询目录 #region oracle 数据库查询 OracleConnection conn = new OracleConnection(Properties.Settings.Default.oracleConn); try { conn.Open(); string sql = "SELECT MEDIADIRID ,MEDIACREATER FROM TPROGRAMMEDIA WHERE (MEDIAID ='" + programID + "')"; OracleCommand cmd = new OracleCommand(sql, conn); OracleDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { dr.Read(); pathid = dr[0].ToString(); xinfo.Creator = dr[1].ToString(); } dr.Close(); } catch (Exception ee) { CommonTools.writeLog("数据库异常:" + ee.ToString(), logpath, "error"); } #endregion if (!Directory.Exists(scripPath)) { CommonTools.writeLog("获取文稿信息目录不存在!" + scripPath, logpath, "error"); } else { string localdescpath = Application.StartupPath + "\\DBTemp\\" + programID + "_DescData.xml"; File.Copy(scripPath + "\\DescData.xml", localdescpath, true); CommonTools.writeLog("复制描述信息xml到本地:" + localdescpath, logpath, "info"); SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + "复制描述信息xml到本地:" + Path.GetFileName(localdescpath) + "\n"); XmlDocument xDoc = new XmlDocument(); xDoc.Load(localdescpath); XmlNodeList lxDescItemNodeList = xDoc.SelectNodes("//DescItem"); #region 读取文稿xml信息 foreach (XmlNode lxDescItemNode in lxDescItemNodeList) { if (lxDescItemNode.Attributes["EName"].Value.Equals("title")) { xinfo.Title = lxDescItemNode.FirstChild.NextSibling.InnerText; } if (lxDescItemNode.Attributes["EName"].Value.Equals("writer")) { xinfo.Author = lxDescItemNode.FirstChild.NextSibling.InnerText; } if (lxDescItemNode.Attributes["EName"].Value.Equals("txt")) { xinfo.Texts = lxDescItemNode.FirstChild.NextSibling.InnerText; } if (lxDescItemNode.Attributes["EName"].Value.Equals("v_bumen")) { xinfo.Vbumen = lxDescItemNode.FirstChild.NextSibling.InnerText; } if (lxDescItemNode.Attributes["EName"].Value.Equals("channel")) { xinfo.ChannelPath = lxDescItemNode.FirstChild.NextSibling.InnerText; } if (lxDescItemNode.Attributes["EName"].Value.Equals("platform")) { xinfo.PlatForm = lxDescItemNode.FirstChild.NextSibling.InnerText; } if (lxDescItemNode.Attributes["EName"].Value.Equals("site")) { xinfo.Sites = lxDescItemNode.FirstChild.NextSibling.InnerText; } } //foreach #endregion } //文稿目录存在 int result = 0; //生成导入内网的xml result = createAvidInfo(xinfo); if (result == 0) { //移动完成目录 //更新数据库 移动到其它目录中去 AVID发布完成 20160725102749410810 string destpath = Properties.Settings.Default.destMediaManagerPathID; string MEDIADIRIDNew = ""; try { MEDIADIRIDNew = destpath; } catch (Exception ee) { CommonTools.writeLog("获取发布完成目录异常!" + ee.ToString(), logpath, "error"); } if (conn.State == ConnectionState.Closed) { try { conn.Open(); CommonTools.writeLog("数据库处于关闭状态!重新打开!", logpath, "info"); } catch (Exception ee) { CommonTools.writeLog("数据库处于关闭状态!重新打开异常:" + ee.ToString(), logpath, "error"); } } string updatesql = ""; if (!string.IsNullOrEmpty(MEDIADIRIDNew)) { updatesql = " update TPROGRAMMEDIA set MEDIADIRID='" + MEDIADIRIDNew + "' where MEDIAID = '" + programID + "' "; OracleCommand cmdupdate = new OracleCommand(updatesql, conn); try { int resultupdate = cmdupdate.ExecuteNonQuery(); if (resultupdate > 0) { CommonTools.writeLog("移动到发布目录成功!", logpath, "info"); } else { string delsql = " delete TPROGRAMMEDIA where MEDIAID = '" + programID + "' "; OracleCommand cmddel = new OracleCommand(delsql, conn); try { int resultdel = cmddel.ExecuteNonQuery(); CommonTools.writeLog("删除原目录下的打包记录成功!" + resultdel.ToString(), logpath, "info"); } catch (Exception ee) { CommonTools.writeLog("删除原目录下的打包记录异常:" + delsql + ee.ToString(), logpath, "error"); } } //else 更新失败 } catch (Exception ee) { CommonTools.writeLog("update异常:" + updatesql + ee.ToString(), logpath, "error"); } } else { string delsql = " delete TPROGRAMMEDIA where MEDIAID = '" + programID + "' "; OracleCommand cmddel = new OracleCommand(delsql, conn); try { int resultdel = cmddel.ExecuteNonQuery(); CommonTools.writeLog("删除原目录下的打包记录成功!" + resultdel.ToString(), logpath, "info"); } catch (Exception ee) { CommonTools.writeLog("删除原目录下的打包记录异常!" + delsql + ee.ToString(), logpath, "error"); } } try { conn.Close(); } catch (Exception ee) { CommonTools.writeLog("数据库关闭异常:" + ee.ToString(), logpath, "error"); } File.Delete(mxffilename); CommonTools.writeLog("删除文件:" + mxffilename, logpath, "info"); File.Delete(mediaMd5file); CommonTools.writeLog("删除md5文件:" + mediaMd5file, logpath, "info"); SetText("\n"); } Thread.Sleep(10); } //else //不再被使用 } catch (Exception ee) { CommonTools.writeLog("redis 写入key value 异常!" + ee.ToString(), logpath, "error"); } }//foreach(string mediafile in mediafiles) System.Threading.Thread.Sleep(Properties.Settings.Default.ScanXmlInterval); } }
/// <summary> /// Deserializes the specified element. /// </summary> /// <param name="element">The element.</param> public override void Deserialize(System.Xml.XmlElement element) { this._executable = string.Empty; this._project = string.Empty; this._subproject = string.Empty; this.Username = string.Empty; this.Password = new HiddenPassword(); this.AutoGetSource = null; this.LabelOnSuccess = null; this.LabelOrPromotionName = null; this.Recursive = null; this.Timeout = new Timeout(); this.WorkingDirectory = string.Empty; this.Executable = Util.GetElementOrAttributeValue("executable", element); this.Project = Util.GetElementOrAttributeValue("project", element); this.SubProject = Util.GetElementOrAttributeValue("subproject", element); string s = Util.GetElementOrAttributeValue("autoGetSource", element); if (!string.IsNullOrEmpty(s)) { this.AutoGetSource = string.Compare(s, bool.TrueString, true) == 0; } s = Util.GetElementOrAttributeValue("username", element); if (!string.IsNullOrEmpty(s)) { this.Username = s; } s = Util.GetElementOrAttributeValue("password", element); if (!string.IsNullOrEmpty(s)) { this.Password.Password = s; } s = Util.GetElementOrAttributeValue("labelOnSuccess", element); if (!string.IsNullOrEmpty(s)) { this.LabelOnSuccess = string.Compare(s, bool.TrueString, true) == 0; } s = Util.GetElementOrAttributeValue("recursive", element); if (!string.IsNullOrEmpty(s)) { this.Recursive = string.Compare(s, bool.TrueString, true) == 0; } s = Util.GetElementOrAttributeValue("recursive", element); if (!string.IsNullOrEmpty(s)) { this.Recursive = string.Compare(s, bool.TrueString, true) == 0; } s = Util.GetElementOrAttributeValue("workingDirectory", element); if (!string.IsNullOrEmpty(s)) { this.WorkingDirectory = s; } XmlElement ele = (XmlElement)element.SelectSingleNode("timeout"); if (ele != null) { this.Timeout.Deserialize(ele); } }
protected override void Build(System.Xml.XmlElement source, string location) { #region 建立 Excel //從 Resources 將學籍異動名冊template讀出來 Workbook template = new Workbook(); template.Open(new MemoryStream(Properties.Resources.StudentUpdateRecordListTemplate), FileFormatType.Excel2003); //產生 excel Workbook wb = new Aspose.Cells.Workbook(); wb.Open(new MemoryStream(Properties.Resources.StudentUpdateRecordListTemplate), FileFormatType.Excel2003); #endregion #region 複製樣式-預設樣式、欄寬 //設定預設樣式 wb.DefaultStyle = template.DefaultStyle; //複製樣版中前18個 Column(欄寬) for (int m = 0; m < 18; m++) { /* * 複製 template的第一個 Sheet的第 m個 Column * 到 wb的第一個 Sheet的第 m個 Column */ wb.Worksheets[0].Cells.CopyColumn(template.Worksheets[0].Cells, m, m); } #endregion #region 初始變數 /****************************** * rowi 填入學校資料用 * rowj 填入學生資料用 * num 計算清單份數 * numcount 計算每份清單頁數 * j 計算所產生清單頁數 * x 判斷個數是否為20被數用 ******************************/ int rowi = 0, rowj = 1, num = source.SelectNodes("清單").Count, numcount = 1, j = 0; bool x = false; int recCount = 0; int totalRec = source.SelectNodes("清單/異動紀錄").Count; #endregion foreach (XmlNode list in source.SelectNodes("清單")) { int i = 0; #region 找出資料總數及判斷 //找出資料總數方便評估進度 int count = list.SelectNodes("異動紀錄").Count; //判斷個數是否為20被數 if (count % 20 == 0) { x = true; } #endregion #region 異動紀錄 //將xml資料填入至excel foreach (XmlElement st in list.SelectNodes("異動紀錄")) { recCount++; if (i % 20 == 0) { #region 複製樣式-欄高、範圍 //複製樣版中前287個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 7].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText) + " 學年度 第 " + Convert.ToInt32(source.SelectSingleNode("@學期").InnerText) + " 學期"); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); wb.Worksheets[0].Cells[rowi + 2, 14].PutValue(list.SelectSingleNode("@年級").InnerText); #endregion if (j > 0) { //插入分頁(在 j * 28 跟 (j * 28) +1 中間,R跟S中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } else { rowj = 6; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 if (x != true) { wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + Math.Ceiling((double)count / 20) + "頁"); } else { wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); } numcount++; #endregion } #region 填入學生資料 string updatecode = st.SelectSingleNode("@異動代號").InnerText; ////將學生資料填入適當的位置內 //if (NewStudentNumberCodes.Contains(updatecode)) //{ // string strNum = ""; // if (!string.IsNullOrEmpty(st.SelectSingleNode("@新學號").InnerText)) // strNum = st.SelectSingleNode("@新學號").InnerText; // else // { // string sid = ""; // if (!string.IsNullOrEmpty(st.SelectSingleNode("@學生編號").InnerText)) // sid = st.SelectSingleNode("@學生編號").InnerText; // List<string> ids = new List<string>(); // ids.Add(sid); // SHSchool.Data.SHStudent.RemoveByIDs(ids); // SHSchool.Data.SHStudentRecord stud = SHSchool.Data.SHStudent.SelectByID(sid); // strNum = stud.StudentNumber; // } // wb.Worksheets[0].Cells[rowj, 1].PutValue(strNum); //} //else wb.Worksheets[0].Cells[rowj, 1].PutValue(st.SelectSingleNode("@學號").InnerText); wb.Worksheets[0].Cells[rowj, 3].PutValue(st.SelectSingleNode("@姓名").InnerText); wb.Worksheets[0].Cells[rowj, 4].PutValue(st.SelectSingleNode("@身分證號").InnerText); wb.Worksheets[0].Cells[rowj, 8].PutValue(Util.ConvertDateStr2(st.SelectSingleNode("@備查日期").InnerText) + "\n" + st.SelectSingleNode("@備查文號").InnerText); wb.Worksheets[0].Cells[rowj, 11].PutValue(st.SelectSingleNode("@異動代號").InnerText); //wb.Worksheets[0].Cells[rowj, 12].PutValue(st.SelectSingleNode("@原因及事項").InnerText + (string.IsNullOrEmpty(st.GetAttribute("更正後資料")) ? "" : "\n" + st.GetAttribute("更正後資料"))); string UpdateData = ""; if (st.SelectSingleNode("@新資料") != null) { // 更正學號填到另一格 if (updatecode != "401") { UpdateData = st.SelectSingleNode("@新資料").InnerText; } } wb.Worksheets[0].Cells[rowj, 12].PutValue(st.SelectSingleNode("@原因及事項").InnerText + "\n" + UpdateData); string strUpdateDate = Util.ConvertDateStr2(st.SelectSingleNode("@異動日期").InnerText); //假設有異動學生學號的類別才出現新學號字樣 if (st.SelectSingleNode("@新學號") != null) { if (!string.IsNullOrEmpty(st.SelectSingleNode("@新學號").InnerText)) { int newNo; if (int.TryParse(st.SelectSingleNode("@新學號").InnerText, out newNo)) { strUpdateDate = newNo + "\n" + strUpdateDate; } } else { // 更正學號 if (updatecode == "401") { if (st.SelectSingleNode("@新資料") != null) { if (!string.IsNullOrEmpty(st.SelectSingleNode("@新資料").InnerText)) { strUpdateDate = st.SelectSingleNode("@新資料").InnerText + "\n" + strUpdateDate; } } } } } wb.Worksheets[0].Cells[rowj, 13].PutValue(strUpdateDate); if (st.SelectSingleNode("@特殊身份代碼") != null) { wb.Worksheets[0].Cells[rowj, 16].PutValue(st.SelectSingleNode("@特殊身份代碼").InnerText); } //wb.Worksheets[0].Cells[rowj, 16].PutValue(st.SelectSingleNode("@備註").InnerText); #endregion i++; rowj++; //回報進度 ReportProgress((int)(((double)recCount * 100.0) / ((double)totalRec))); } #endregion #region 若個數為20倍數,處理單一頁面 if (x == true) { #region 複製樣式-欄高、範圍 //複製樣版前28個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 6].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText)); wb.Worksheets[0].Cells[rowi + 2, 9].PutValue(Convert.ToInt32(source.SelectSingleNode("@學期").InnerText)); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); #endregion if (j > 0) { //插入分頁(在i跟i+1中間,O跟P中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); numcount++; #endregion } #endregion #region 統計人數 //填入統計人數 wb.Worksheets[0].Cells.CreateRange(rowj, 1, 1, 2).UnMerge(); wb.Worksheets[0].Cells.Merge(rowj, 1, 1, 3); wb.Worksheets[0].Cells[rowj, 1].PutValue("合 計 " + count.ToString() + " 名"); #endregion wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); #region 設定變數 //調整新清單所使用變數 numcount = 1; rowj = (28 * j) - 2; rowi = (28 * j); x = false; #endregion } // 因2010年格式不同小修改 #region 學籍異動電子格式 //範本 Worksheet TemplateWb = wb.Worksheets["電子格式範本"]; //實做頁面 Worksheet DyWb = wb.Worksheets[wb.Worksheets.Add()]; //名稱 DyWb.Name = "異動名冊"; //範圍 Range range_H = TemplateWb.Cells.CreateRange(0, 1, false); Range range_R = TemplateWb.Cells.CreateRange(1, 1, false); // 107新格式 結束行要 有End 字樣 Range range_R_EndRow = TemplateWb.Cells.CreateRange(2, 1, false); //拷貝range_H DyWb.Cells.CreateRange(0, 1, false).Copy(range_H); int DyWb_index = 0; // 遇到特殊異動代碼要處理 List <string> spcCode = new List <string>(); spcCode.Add("211"); DAL.DALTransfer DALTranser = new DAL.DALTransfer(); // 格式轉換 List <GovernmentalDocument.Reports.List.rpt_UpdateRecord> _data = DALTranser.ConvertRptUpdateRecord(source); // 排序 (依 班別、年級、科別代碼、異動代碼) _data = (from data in _data orderby data.ClassType, GYear(data.GradeYear), data.DeptCode, data.UpdateCode select data).ToList(); foreach (GovernmentalDocument.Reports.List.rpt_UpdateRecord rec in _data) { DyWb_index++; //每增加一行,複製一次 DyWb.Cells.CreateRange(DyWb_index, 1, false).Copy(range_R); //班別 DyWb.Cells[DyWb_index, 0].PutValue(rec.ClassType); //科別代碼 DyWb.Cells[DyWb_index, 1].PutValue(rec.DeptCode); // 2 放上傳類別,請使用者自填 //學號 DyWb.Cells[DyWb_index, 3].PutValue(rec.StudentNumber); //姓名 DyWb.Cells[DyWb_index, 4].PutValue(rec.Name); //身分證字號 DyWb.Cells[DyWb_index, 5].PutValue(rec.IDNumber); //註1 DyWb.Cells[DyWb_index, 6].PutValue(rec.Comment1); //性別代碼 DyWb.Cells[DyWb_index, 7].PutValue(rec.GenderCode); //出生日期 DyWb.Cells[DyWb_index, 8].PutValue(rec.Birthday); //特殊身份代碼 DyWb.Cells[DyWb_index, 9].PutValue(rec.SpecialStatusCode); //年級 DyWb.Cells[DyWb_index, 10].PutValue(rec.GradeYear); //異動原因代碼 DyWb.Cells[DyWb_index, 11].PutValue(rec.UpdateCode); //異動日期 DyWb.Cells[DyWb_index, 12].PutValue(rec.UpdateDate); // 異動順序 DyWb.Cells[DyWb_index, 13].PutValue(rec.Order); //備查日期 DyWb.Cells[DyWb_index, 14].PutValue(rec.LastADDate); //備查文字 DyWb.Cells[DyWb_index, 15].PutValue(rec.LastADDoc); //備查文號 DyWb.Cells[DyWb_index, 16].PutValue(rec.LastADNum); //更正後資料 string strUpdateData = string.Empty; //若是更正後資料有值則填入更正後資料 if (!string.IsNullOrEmpty(rec.NewData)) { strUpdateData = rec.NewData; } //若是新學號中有值則填入新學號 //判斷strUpdateData是否已有值,若是已有值則加入斷行符號 if (!string.IsNullOrEmpty(rec.NewStudNumber)) { strUpdateData += string.IsNullOrEmpty(strUpdateData) ? rec.NewStudNumber : "\n" + rec.NewStudNumber; } DyWb.Cells[DyWb_index, 17].PutValue(strUpdateData); // 註2 DyWb.Cells[DyWb_index, 18].PutValue(rec.Comment2); //雙學籍編號 DyWb.Cells[DyWb_index, 19].PutValue(rec.ReplicatedSchoolRollNumber); //備註說明 DyWb.Cells[DyWb_index, 20].PutValue(rec.Comment); // 2011 新承辦單位修正,轉科讀取新學號 if (NewStudentNumberCodes.Contains(rec.UpdateCode)) { List <string> ids = new List <string>(); ids.Add(rec.StudentID); SHSchool.Data.SHStudent.RemoveByIDs(ids); SHSchool.Data.SHStudentRecord studRec = SHSchool.Data.SHStudent.SelectByID(rec.StudentID); if (studRec != null) { DyWb.Cells[DyWb_index, 3].PutValue(studRec.StudentNumber); } DyWb.Cells[DyWb_index, 17].PutValue(""); } } // 資料末底 加End DyWb.Cells.CreateRange(DyWb_index + 1, 1, false).Copy(range_R_EndRow); DyWb.AutoFitColumns(); //範本 Worksheet TemplateWb_Cover = wb.Worksheets["異動名冊封面範本"]; //實做頁面 Worksheet cover = wb.Worksheets[wb.Worksheets.Add()]; //名稱 cover.Name = "異動名冊封面"; string school_code = source.SelectSingleNode("@學校代號").InnerText; string school_year = source.SelectSingleNode("@學年度").InnerText; string school_semester = source.SelectSingleNode("@學期").InnerText; //範圍 Range range_H_Cover = TemplateWb_Cover.Cells.CreateRange(0, 1, false); //range_H_Cover cover.Cells.CreateRange(0, 1, false).Copy(range_H_Cover); Range range_R_cover = TemplateWb_Cover.Cells.CreateRange(1, 1, false); // 107新格式 結束行要 有End 字樣 Range range_R_cover_EndRow = TemplateWb_Cover.Cells.CreateRange(2, 1, false); int cover_row_counter = 1; //2018/2/2 穎驊註解 ,下面是新的封面產生方式 foreach (XmlNode list in source.SelectNodes("清單")) { //每增加一行,複製一次 cover.Cells.CreateRange(cover_row_counter, 1, false).Copy(range_R_cover); string gradeYear = list.SelectSingleNode("@年級").InnerText; string deptCode = list.SelectSingleNode("@科別代碼").InnerText; //學校代碼 cover.Cells[cover_row_counter, 0].PutValue(school_code); //學年度 cover.Cells[cover_row_counter, 1].PutValue(school_year); //學期 cover.Cells[cover_row_counter, 2].PutValue(school_semester); //年級 cover.Cells[cover_row_counter, 3].PutValue(gradeYear); //科別代碼 cover.Cells[cover_row_counter, 6].PutValue(deptCode); foreach (XmlElement st in list.SelectNodes("異動名冊封面")) { string reportType = st.SelectSingleNode("@名冊別").InnerText; string classType = st.SelectSingleNode("@班別").InnerText; string updateType = st.SelectSingleNode("@上傳類別").InnerText; string approvedClassCount = st.SelectSingleNode("@核定班數").InnerText; string approvedStudentCount = st.SelectSingleNode("@核定學生數").InnerText; string actualClassCount = st.SelectSingleNode("@實招班數").InnerText; string actualStudentCount = st.SelectSingleNode("@實招新生數").InnerText; string originalStudentCount = st.SelectSingleNode("@原有學生數").InnerText; string increaseStudentCount = st.SelectSingleNode("@增加學生數").InnerText; string decreaseStudentCount = st.SelectSingleNode("@減少學生數").InnerText; string modifiedStudentCount = st.SelectSingleNode("@更正學生數").InnerText; string currentStudentCount = st.SelectSingleNode("@現有學生數").InnerText; string remarks1 = st.SelectSingleNode("@註1").InnerText; string remarksContent = st.SelectSingleNode("@備註說明").InnerText; //名冊別 cover.Cells[cover_row_counter, 4].PutValue(reportType); //班別 cover.Cells[cover_row_counter, 5].PutValue(classType); //上傳類別 cover.Cells[cover_row_counter, 7].PutValue(updateType); //核定班級 cover.Cells[cover_row_counter, 8].PutValue(approvedClassCount); //核定學生數 cover.Cells[cover_row_counter, 9].PutValue(approvedStudentCount); //實招班數 cover.Cells[cover_row_counter, 10].PutValue(actualClassCount); //實招新生數 cover.Cells[cover_row_counter, 11].PutValue(actualStudentCount); //原有學生數 cover.Cells[cover_row_counter, 12].PutValue(originalStudentCount); //增加學生數 cover.Cells[cover_row_counter, 13].PutValue(increaseStudentCount); //減少學生數 cover.Cells[cover_row_counter, 14].PutValue(decreaseStudentCount); //更正學生數 cover.Cells[cover_row_counter, 15].PutValue(modifiedStudentCount); //現有學生數 cover.Cells[cover_row_counter, 16].PutValue(currentStudentCount); //註1 cover.Cells[cover_row_counter, 17].PutValue(remarks1); //備註說明 cover.Cells[cover_row_counter, 18].PutValue(remarksContent); } cover_row_counter++; } // 資料末底 加End cover.Cells.CreateRange(cover_row_counter, 1, false).Copy(range_R_cover_EndRow); wb.Worksheets.RemoveAt("電子格式範本"); wb.Worksheets.RemoveAt("異動名冊封面範本"); #endregion wb.Worksheets.ActiveSheetIndex = 0; //儲存 Excel wb.Save(location, FileFormatType.Excel2003); }
/// <summary> /// 在XML映射文档中的指定路径,加入当前对象信息 /// </summary> /// <param name="xpath">分级对象的路径 </param> /// <param name="o">被缓存的对象</param> public virtual void AddObject(string xpath, object o) { lock (lockHelper) { if (applyMemCached || applyRedis) { //向缓存加入新的对象 cs.AddObject(xpath, o); } else { //当缓存到期时间为0或负值,则不再放入缓存 if (cs.TimeOut <= 0) { return; } //整理XPATH表达式信息 string newXpath = PrepareXpath(xpath); int separator = newXpath.LastIndexOf("/"); //找到相关的组名 string group = newXpath.Substring(0, separator); //找到相关的对象 string element = newXpath.Substring(separator + 1); XmlNode groupNode = objectXmlMap.SelectSingleNode(group); //建立对象的唯一键值, 用以映射XML和缓存对象的键 string objectId = ""; XmlNode node = objectXmlMap.SelectSingleNode(PrepareXpath(xpath)); if (node != null) { objectId = node.Attributes["objectId"].Value; } if (objectId == "") { groupNode = CreateNode(group); objectId = Guid.NewGuid().ToString(); //建立新元素和一个属性 for this perticular object XmlElement objectElement = objectXmlMap.OwnerDocument.CreateElement(element); XmlAttribute objectAttribute = objectXmlMap.OwnerDocument.CreateAttribute("objectId"); objectAttribute.Value = objectId; objectElement.Attributes.Append(objectAttribute); //为XML文档建立新元素 groupNode.AppendChild(objectElement); } else { //建立新元素和一个属性 for this perticular object XmlElement objectElement = objectXmlMap.OwnerDocument.CreateElement(element); XmlAttribute objectAttribute = objectXmlMap.OwnerDocument.CreateAttribute("objectId"); objectAttribute.Value = objectId; objectElement.Attributes.Append(objectAttribute); //为XML文档建立新元素 groupNode.ReplaceChild(objectElement, node); } //向缓存加入新的对象 cs.AddObject(objectId, o); } } }
protected override void Build(System.Xml.XmlElement source, string location) { #region 建立 Excel //從 Resources 將新生名冊template讀出來 Workbook template = new Workbook(); template.Open(new MemoryStream(Properties.Resources.RetaintoStudentListTemplate), FileFormatType.Excel2003); //產生 excel Workbook wb = new Aspose.Cells.Workbook(); wb.Open(new MemoryStream(Properties.Resources.RetaintoStudentListTemplate), FileFormatType.Excel2003); #endregion #region 複製樣式-預設樣式、欄寬 //設定預設樣式 wb.DefaultStyle = template.DefaultStyle; //複製樣版中前18個 Column(欄寬) for (int m = 0; m < 18; m++) { /* * 複製 template的第一個 Sheet的第 m個 Column * 到 wb的第一個 Sheet的第 m個 Column */ wb.Worksheets[0].Cells.CopyColumn(template.Worksheets[0].Cells, m, m); } #endregion #region 初始變數 /****************************** * rowi 填入學校資料用 * rowj 填入學生資料用 * num 計算清單份數 * numcount 計算每份清單頁數 * j 計算所產生清單頁數 * x 判斷個數是否為20被數用 ******************************/ int rowi = 0, rowj = 1, num = source.SelectNodes("清單").Count, numcount = 1, j = 0; bool x = false; int recCount = 0; int totalRec = source.SelectNodes("清單/異動紀錄").Count; #endregion foreach (XmlNode list in source.SelectNodes("清單")) { int i = 0; #region 找出資料總數及判斷 //找出資料總數方便評估進度 int count = list.SelectNodes("異動紀錄").Count; //判斷個數是否為20被數 if (count % 20 == 0) { x = true; } #endregion #region 異動紀錄 // 所在地代碼對照 Dictionary <string, string> gLocationCodeDict = new Dictionary <string, string>(); //將xml資料填入至excel foreach (XmlNode st in list.SelectNodes("異動紀錄")) { recCount++; if (i % 20 == 0) { #region 複製樣式-欄高、範圍 //複製樣版中前28個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 6].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText)); wb.Worksheets[0].Cells[rowi + 2, 9].PutValue(Convert.ToInt32(source.SelectSingleNode("@學期").InnerText)); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); #endregion if (j > 0) { //插入分頁(在 j * 28 跟 (j * 28) +1 中間,R跟S中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } else { rowj = 6; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 if (x != true) { wb.Worksheets[0].Cells[(28 * (j - 1)) + 26, 13].PutValue("第" + numcount + "頁,共" + Math.Ceiling((double)count / 20) + "頁"); } else { wb.Worksheets[0].Cells[(28 * (j - 1)) + 26, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); } numcount++; #endregion } #region 填入學生資料 //將學生資料填入適當的位置內 wb.Worksheets[0].Cells[rowj, 1].PutValue(st.SelectSingleNode("@姓名").InnerText); string ss = st.SelectSingleNode("@出生年月日").InnerText + "\n" + st.SelectSingleNode("@身分證號").InnerText; wb.Worksheets[0].Cells[rowj, 3].PutValue(ss); try { wb.Worksheets[0].Cells[rowj, 6].PutValue(Convert.ToInt32(st.SelectSingleNode("@性別代號").InnerText)); } catch (Exception) { } wb.Worksheets[0].Cells[rowj, 7].PutValue(st.SelectSingleNode("@性別").InnerText); wb.Worksheets[0].Cells[rowj, 8].PutValue(st.SelectSingleNode("@出生年月日").InnerText); if (st.SelectSingleNode("@特殊身份代碼") != null) { wb.Worksheets[0].Cells[rowj, 8].PutValue(st.SelectSingleNode("@特殊身份代碼").InnerText); } string uCode = ""; if (st.SelectSingleNode("@異動代號") == null) { if (st.SelectSingleNode("@異動代碼") != null) { uCode = st.SelectSingleNode("@異動代碼").InnerText; } } else { uCode = st.SelectSingleNode("@異動代號").InnerText; } wb.Worksheets[0].Cells[rowj, 9].PutValue(uCode); wb.Worksheets[0].Cells[rowj, 12].PutValue(st.SelectSingleNode("@原因及事項").InnerText); wb.Worksheets[0].Cells[rowj, 13].PutValue(st.SelectSingleNode("@備註").InnerText); #endregion i++; rowj++; //回報進度 ReportProgress((int)(((double)recCount * 100.0) / ((double)totalRec))); } #endregion #region 若個數為20倍數,處理單一頁面 if (x == true) { #region 複製樣式-欄高、範圍 //複製樣版前28個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 6].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText)); wb.Worksheets[0].Cells[rowi + 2, 9].PutValue(Convert.ToInt32(source.SelectSingleNode("@學期").InnerText)); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); #endregion if (j > 0) { //插入分頁(在i跟i+1中間,O跟P中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 wb.Worksheets[0].Cells[(28 * (j - 1)) + 26, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); numcount++; #endregion } #endregion #region 統計人數 //填入統計人數 wb.Worksheets[0].Cells[rowj, 1].PutValue("合 計 "); wb.Worksheets[0].Cells[rowj, 3].PutValue(count.ToString() + " 名"); #endregion wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); #region 設定變數 //調整新清單所使用變數 numcount = 1; rowj = (28 * j) - 2; rowi = (28 * j); x = false; #endregion } #region 97中辦格式 Worksheet mingdao = wb.Worksheets["電子格式103"]; Worksheet mdws = wb.Worksheets[wb.Worksheets.Add()]; mdws.Name = "電子格式"; Range range_header = mingdao.Cells.CreateRange(0, 1, false); Range range_row = mingdao.Cells.CreateRange(1, 1, false); mdws.Cells.CreateRange(0, 1, false).Copy(range_header); int mdws_index = 0; foreach (XmlElement record in source.SelectNodes("清單/異動紀錄")) { mdws_index++; mdws.Cells.CreateRange(mdws_index, 1, false).Copy(range_row); mdws.Cells[mdws_index, 0].PutValue(record.GetAttribute("班別")); mdws.Cells[mdws_index, 1].PutValue((record.ParentNode as XmlElement).GetAttribute("科別代號")); mdws.Cells[mdws_index, 2].PutValue(""); mdws.Cells[mdws_index, 3].PutValue(record.GetAttribute("姓名")); mdws.Cells[mdws_index, 4].PutValue(record.GetAttribute("身分證號")); mdws.Cells[mdws_index, 5].PutValue(record.GetAttribute("註1")); mdws.Cells[mdws_index, 6].PutValue(record.GetAttribute("性別代號")); mdws.Cells[mdws_index, 7].PutValue(GetBirthdateWithoutSlash(record.GetAttribute("出生年月日"))); mdws.Cells[mdws_index, 8].PutValue(record.GetAttribute("特殊身份代碼")); mdws.Cells[mdws_index, 9].PutValue(record.GetAttribute("異動代碼")); mdws.Cells[mdws_index, 10].PutValue(record.GetAttribute("備註")); } mdws.AutoFitColumns(); wb.Worksheets.RemoveAt("電子格式103"); wb.Worksheets.ActiveSheetIndex = 0; #endregion wb.Worksheets.ActiveSheetIndex = 0; //儲存 Excel wb.Save(location, FileFormatType.Excel2003); }
// 處理新竹樣版 private void ProcessHsinChu(System.Xml.XmlElement source, string location) { // 資料轉換 Dictionary <string, JHPermrec.UpdateRecord.DAL.StudBatchUpdateRecContentEntity> data = StudBatchUpdateRecEntity.ConvertGetContentData(source); Workbook template = new Workbook(); //從Resources把Template讀出來 template.Open(new MemoryStream(GDResources.JTransferStudentUpdateRecordTemplate_HsinChu), FileFormatType.Excel2003); //要產生的excel檔 Workbook wb = new Aspose.Cells.Workbook(); wb.Open(new MemoryStream(GDResources.JTransferStudentUpdateRecordTemplate_HsinChu), FileFormatType.Excel2003); Worksheet wst = wb.Worksheets[0]; wst.Name = "轉入異動名冊"; #region 複製樣式-預設樣式、欄寬 //設定預設樣式 wb.DefaultStyle = template.DefaultStyle; string SchoolInfoAndSchoolYear = StudBatchUpdateRecEntity.GetContentSchoolName() + " " + source.SelectSingleNode("@學年度").InnerText + wst.Cells[0, 0].StringValue; wst.Cells[0, 0].PutValue(SchoolInfoAndSchoolYear); #endregion #region 初始變數 int recCount = 0; int totalRec = data.Count; #endregion int row = 2; //將xml資料填入至excel foreach (StudBatchUpdateRecContentEntity sburce in data.Values) { wst.Cells[row, 0].PutValue(sburce.GetClassName()); wst.Cells[row, 1].PutValue(sburce.GetName()); wst.Cells[row, 2].PutValue(sburce.GetStudentNumber()); wst.Cells[row, 3].PutValue(sburce.GetIDNumber()); DateTime dt; string strDate = ""; if (DateTime.TryParse(sburce.GetBirthday(), out dt)) { strDate = "民國" + (dt.Year - 1911) + "年" + dt.Month + "月" + dt.Day + "日"; } wst.Cells[row, 4].PutValue(strDate); wst.Cells[row, 5].PutValue(sburce.GetGender()); wst.Cells[row, 6].PutValue(sburce.GetGuardian()); wst.Cells[row, 7].PutValue(sburce.GetAddress()); wst.Cells[row, 8].PutValue(sburce.GetUpdateCodeType()); wst.Cells[row, 9].PutValue(sburce.GetUpdateDescription()); wst.Cells[row, 10].PutValue(sburce.GetImportExportSchool()); wst.Cells[row, 11].PutValue(sburce.GetComment()); recCount++; row++; //回報進度 ReportProgress((int)(((double)recCount * 100.0) / ((double)totalRec))); } // 畫表 Style st2 = wb.Styles[wb.Styles.Add()]; StyleFlag sf2 = new StyleFlag(); sf2.Borders = true; st2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; st2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; st2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; st2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; int tmpMaxRow = 0, tmpMaxCol = 0; for (int wbIdx1 = 0; wbIdx1 < wb.Worksheets.Count; wbIdx1++) { tmpMaxRow = wb.Worksheets[wbIdx1].Cells.MaxDataRow; tmpMaxCol = wb.Worksheets[wbIdx1].Cells.MaxDataColumn + 1; wb.Worksheets[wbIdx1].Cells.CreateRange(1, 0, tmpMaxRow, tmpMaxCol).ApplyStyle(st2, sf2); } //儲存 wb.Save(location, FileFormatType.Excel2003); }
protected override void Build(System.Xml.XmlElement source, string location) { #region 建立 Excel //從 Resources 將延修生學籍名冊template讀出來 Workbook template = new Workbook(); template.Open(new MemoryStream(Properties.Resources.ExtendingStudentUpdateRecordListTemplate), FileFormatType.Excel2003); //產生 excel Workbook wb = new Aspose.Cells.Workbook(); wb.Open(new MemoryStream(Properties.Resources.ExtendingStudentUpdateRecordListTemplate), FileFormatType.Excel2003); #endregion #region 複製樣式-預設樣式、欄寬 //設定預設樣式 wb.DefaultStyle = template.DefaultStyle; //複製樣版中前18個 Column(欄寬) for (int m = 0; m < 18; m++) { /* * 複製 template的第一個 Sheet的第 m個 Column * 到 wb的第一個 Sheet的第 m個 Column */ wb.Worksheets[0].Cells.CopyColumn(template.Worksheets[0].Cells, m, m); } #endregion #region 初始變數 /****************************** * rowi 填入學校資料用 * rowj 填入學生資料用 * num 計算清單份數 * numcount 計算每份清單頁數 * j 計算所產生清單頁數 * x 判斷個數是否為20被數用 ******************************/ int rowi = 0, rowj = 1, num = source.SelectNodes("清單").Count, numcount = 1, j = 0; bool x = false; int recCount = 0; int totalRec = source.SelectNodes("清單/異動紀錄").Count; #endregion foreach (XmlNode list in source.SelectNodes("清單")) { int i = 0; #region 找出資料總數及判斷 //找出資料總數方便評估進度 int count = list.SelectNodes("異動紀錄").Count; //判斷個數是否為20被數 if (count % 20 == 0) { x = true; } #endregion #region 異動紀錄 //將xml資料填入至excel foreach (XmlNode st in list.SelectNodes("異動紀錄")) { recCount++; if (i % 20 == 0) { #region 複製樣式-欄高、範圍 //複製樣版中前287個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 7].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText) + "學年度第" + Convert.ToInt32(source.SelectSingleNode("@學期").InnerText) + "學期"); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); #endregion if (j > 0) { //插入分頁(在 j * 28 跟 (j * 28) +1 中間,R跟S中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } else { rowj = 6; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 if (x != true) { wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + Math.Ceiling((double)count / 20) + "頁"); } else { wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); } numcount++; #endregion } #region 填入學生資料 //將學生資料填入適當的位置內 wb.Worksheets[0].Cells[rowj, 1].PutValue(st.SelectSingleNode("@學號").InnerText); wb.Worksheets[0].Cells[rowj, 3].PutValue(st.SelectSingleNode("@姓名").InnerText); wb.Worksheets[0].Cells[rowj, 4].PutValue(st.SelectSingleNode("@身分證號").InnerText); wb.Worksheets[0].Cells[rowj, 8].PutValue(Util.ConvertDateStr2(st.SelectSingleNode("@備查日期").InnerText) + "\n" + st.SelectSingleNode("@備查文號").InnerText); wb.Worksheets[0].Cells[rowj, 11].PutValue(st.SelectSingleNode("@異動代號").InnerText); wb.Worksheets[0].Cells[rowj, 12].PutValue(st.SelectSingleNode("@原因及事項").InnerText); if (st.SelectSingleNode("@新學號").InnerText == "") { wb.Worksheets[0].Cells[rowj, 13].PutValue(Util.ConvertDateStr2(st.SelectSingleNode("@異動日期").InnerText)); } else { wb.Worksheets[0].Cells[rowj, 13].PutValue(st.SelectSingleNode("@新學號").InnerText + "\n" + Util.ConvertDateStr2(st.SelectSingleNode("@異動日期").InnerText)); } //wb.Worksheets[0].Cells[rowj, 16].PutValue(st.SelectSingleNode("@備註").InnerText); if (st.SelectSingleNode("@特殊身份代碼") != null) { wb.Worksheets[0].Cells[rowj, 16].PutValue(st.SelectSingleNode("@特殊身份代碼").InnerText); } #endregion i++; rowj++; //回報進度 ReportProgress((int)(((double)recCount * 100.0) / ((double)totalRec))); } #endregion #region 若個數為20倍數,處理單一頁面 if (x == true) { #region 複製樣式-欄高、範圍 //複製樣版前28個 Row(欄高) //for (int m = 0; m < 28; m++) //{ // /* // * 複製 template的第一個 Sheet的第m個 Row // * 到 wb的第一個 Sheet的第(j * 28) + m個 Row // */ // wb.Worksheets[0].Cells.CopyRow(template.Worksheets[0].Cells, m, (j * 28) + m); //} /* * 複製Style(包含儲存格合併的資訊) * 先用CreateRange()選取要複製的Range("A1", "R28") * 再用CopyStyle複製另一個Range中的格式 */ Range range = template.Worksheets[0].Cells.CreateRange(0, 28, false); int t = j * 28; wb.Worksheets[0].Cells.CreateRange(t, 28, false).Copy(range); #endregion #region 填入學校資料 //將學校資料填入適當的位置內 wb.Worksheets[0].Cells[rowi, 13].PutValue(source.SelectSingleNode("@學校代號").InnerText); wb.Worksheets[0].Cells[rowi, 16].PutValue(list.SelectSingleNode("@科別代號").InnerText); wb.Worksheets[0].Cells[rowi + 2, 2].PutValue(source.SelectSingleNode("@學校名稱").InnerText); wb.Worksheets[0].Cells[rowi + 2, 7].PutValue(Convert.ToInt32(source.SelectSingleNode("@學年度").InnerText) + "學年度第" + Convert.ToInt32(source.SelectSingleNode("@學期").InnerText) + "學期"); wb.Worksheets[0].Cells[rowi + 2, 12].PutValue(list.SelectSingleNode("@科別").InnerText); #endregion if (j > 0) { //插入分頁(在i跟i+1中間,O跟P中間) wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); rowj += 8; } rowi += 28; j++; #region 顯示頁數 //顯示頁數 wb.Worksheets[0].Cells[(28 * (j - 1)) + 27, 13].PutValue("第" + numcount + "頁,共" + (Math.Ceiling((double)count / 20) + 1) + "頁"); numcount++; #endregion } #endregion #region 統計人數 //填入統計人數 wb.Worksheets[0].Cells.CreateRange(rowj, 1, 1, 2).UnMerge(); wb.Worksheets[0].Cells.Merge(rowj, 1, 1, 3); wb.Worksheets[0].Cells[rowj, 1].PutValue("合 計 " + count.ToString() + " 名"); #endregion wb.Worksheets[0].HPageBreaks.Add(j * 28, 18); #region 設定變數 //調整新清單所使用變數 numcount = 1; rowj = (28 * j) - 2; rowi = (28 * j); x = false; #endregion } Worksheet mingdao = wb.Worksheets[1]; //範本 Worksheet TemplateWb = wb.Worksheets["電子格式範本"]; //實做頁面 Worksheet mdws = wb.Worksheets[wb.Worksheets.Add()]; //名稱 mdws.Name = "延修生異動名冊"; //範圍 Range range_H = TemplateWb.Cells.CreateRange(0, 1, false); Range range_R = TemplateWb.Cells.CreateRange(1, 1, false); // 107新格式 結束行要 有End 字樣 Range range_R_EndRow = TemplateWb.Cells.CreateRange(2, 1, false); //拷貝range_H mdws.Cells.CreateRange(0, 1, false).Copy(range_H); int mdws_index = 0; DAL.DALTransfer DALTranser = new DAL.DALTransfer(); // 格式轉換 List <GovernmentalDocument.Reports.List.rpt_UpdateRecord> _data = DALTranser.ConvertRptUpdateRecord(source); // 整理封面的列數,能填的值盡量幫他填,剩下無法的 要請使用者自行填寫 // <年級,<班別,科別>> Dictionary <string, Dictionary <string, List <string> > > cover_row_dict = new Dictionary <string, Dictionary <string, List <string> > >(); // 排序 (依 班別、年級、科別代碼、異動代碼) _data = (from data in _data orderby data.ClassType, data.DeptCode, data.UpdateCode select data).ToList(); foreach (GovernmentalDocument.Reports.List.rpt_UpdateRecord rec in _data) { mdws_index++; //每增加一行,複製一次 mdws.Cells.CreateRange(mdws_index, 1, false).Copy(range_R); // 應畢業學年度 mdws.Cells[mdws_index, 0].PutValue(rec.ExpectGraduateSchoolYear); //班別 mdws.Cells[mdws_index, 1].PutValue(rec.ClassType); //科別代碼 mdws.Cells[mdws_index, 2].PutValue(rec.DeptCode); // 2 放上傳類別,請使用者自填 //學號 mdws.Cells[mdws_index, 4].PutValue(rec.StudentNumber); //姓名 mdws.Cells[mdws_index, 5].PutValue(rec.Name); //身分證字號 mdws.Cells[mdws_index, 6].PutValue(rec.IDNumber); //註1 mdws.Cells[mdws_index, 7].PutValue(rec.Comment1); //性別代碼 mdws.Cells[mdws_index, 8].PutValue(rec.GenderCode); //出生日期 mdws.Cells[mdws_index, 9].PutValue(rec.Birthday); //特殊身份代碼 mdws.Cells[mdws_index, 10].PutValue(rec.SpecialStatusCode); //異動原因代碼 mdws.Cells[mdws_index, 11].PutValue(rec.UpdateCode); //異動日期 mdws.Cells[mdws_index, 12].PutValue(rec.UpdateDate); // 異動順序 mdws.Cells[mdws_index, 13].PutValue(rec.Order); //備查日期 mdws.Cells[mdws_index, 14].PutValue(rec.LastADDate); //備查文字 mdws.Cells[mdws_index, 15].PutValue(rec.LastADDoc); //備查文號 mdws.Cells[mdws_index, 16].PutValue(rec.LastADNum); //更正後資料 string strUpdateData = string.Empty; //若是更正後資料有值則填入更正後資料 if (!string.IsNullOrEmpty(rec.NewData)) { strUpdateData = rec.NewData; } //若是新學號中有值則填入新學號 //判斷strUpdateData是否已有值,若是已有值則加入斷行符號 if (!string.IsNullOrEmpty(rec.NewStudNumber)) { strUpdateData += string.IsNullOrEmpty(strUpdateData) ? rec.NewStudNumber : "\n" + rec.NewStudNumber; } mdws.Cells[mdws_index, 17].PutValue(strUpdateData); // 註2 mdws.Cells[mdws_index, 18].PutValue(rec.Comment2); // 雙重學籍編號 mdws.Cells[mdws_index, 19].PutValue(rec.ReplicatedSchoolRollNumber); //備註說明 mdws.Cells[mdws_index, 20].PutValue(rec.Comment); // 整理cover_row_dict //年級 if (!cover_row_dict.ContainsKey(rec.GradeYear)) { cover_row_dict.Add(rec.GradeYear, new Dictionary <string, List <string> >()); } //班別 if (!cover_row_dict[rec.GradeYear].ContainsKey(rec.ClassType)) { cover_row_dict[rec.GradeYear].Add(rec.ClassType, new List <string>()); } //科別 if (!cover_row_dict[rec.GradeYear][rec.ClassType].Contains(rec.DeptCode)) { cover_row_dict[rec.GradeYear][rec.ClassType].Add(rec.DeptCode); } } // 資料末底 加End mdws.Cells.CreateRange(mdws_index + 1, 1, false).Copy(range_R_EndRow); mdws.AutoFitColumns(); //範本 Worksheet TemplateWb_Cover = wb.Worksheets["延修生異動名冊封面範本"]; //實做頁面 Worksheet cover = wb.Worksheets[wb.Worksheets.Add()]; cover.Name = "延修生異動名冊封面"; string school_code = source.SelectSingleNode("@學校代號").InnerText; string school_year = source.SelectSingleNode("@學年度").InnerText; string school_semester = source.SelectSingleNode("@學期").InnerText; //範圍 Range range_H_Cover = TemplateWb_Cover.Cells.CreateRange(0, 1, false); //range_H_Cover cover.Cells.CreateRange(0, 1, false).Copy(range_H_Cover); Range range_R_cover = TemplateWb_Cover.Cells.CreateRange(1, 1, false); // 107新格式 結束行要 有End 字樣 Range range_R_cover_EndRow = TemplateWb_Cover.Cells.CreateRange(2, 1, false); int cover_row_counter = 1; //2018/2/2 穎驊註解 ,下面是新的封面產生方式 foreach (XmlNode list in source.SelectNodes("清單")) { //每增加一行,複製一次 cover.Cells.CreateRange(cover_row_counter, 1, false).Copy(range_R_cover); string gradeYear = list.SelectSingleNode("@年級").InnerText; string deptCode = list.SelectSingleNode("@科別代碼").InnerText; //學校代碼 cover.Cells[cover_row_counter, 0].PutValue(school_code); //學年度 cover.Cells[cover_row_counter, 1].PutValue(school_year); //學期 cover.Cells[cover_row_counter, 2].PutValue(school_semester); //科別代碼 cover.Cells[cover_row_counter, 6].PutValue(deptCode); foreach (XmlElement st in list.SelectNodes("異動名冊封面")) { string reportType = st.SelectSingleNode("@名冊別").InnerText; string scheduledGraduateYear = st.SelectSingleNode("@應畢業學年度").InnerText; string classType = st.SelectSingleNode("@班別").InnerText; string updateType = st.SelectSingleNode("@上傳類別").InnerText; string approvedExtendingStudentCount = st.SelectSingleNode("@輔導延修學生數").InnerText; string originalStudentCount = st.SelectSingleNode("@原有學生數").InnerText; string decreaseStudentCount = st.SelectSingleNode("@減少學生數").InnerText; string modifiedStudentCount = st.SelectSingleNode("@更正學生數").InnerText; string currentStudentCount = st.SelectSingleNode("@現有學生數").InnerText; string remarksContent = st.SelectSingleNode("@備註說明").InnerText; //名冊別 cover.Cells[cover_row_counter, 3].PutValue(reportType); //應畢業學年度 cover.Cells[cover_row_counter, 4].PutValue(scheduledGraduateYear); //班別 cover.Cells[cover_row_counter, 5].PutValue(classType); //上傳類別 cover.Cells[cover_row_counter, 7].PutValue(updateType); //輔導延修學生數 cover.Cells[cover_row_counter, 8].PutValue(approvedExtendingStudentCount); //原有學生數 cover.Cells[cover_row_counter, 9].PutValue(originalStudentCount); //減少學生數 cover.Cells[cover_row_counter, 10].PutValue(decreaseStudentCount); //更正學生數 cover.Cells[cover_row_counter, 11].PutValue(modifiedStudentCount); //現有學生數 cover.Cells[cover_row_counter, 12].PutValue(currentStudentCount); //備註說明 cover.Cells[cover_row_counter, 13].PutValue(remarksContent); } cover_row_counter++; } // 資料末底 加End cover.Cells.CreateRange(cover_row_counter, 1, false).Copy(range_R_cover_EndRow); mdws.Cells.SetColumnWidth(5, 8.5); mdws.Cells.SetColumnWidth(11, 20); wb.Worksheets.ActiveSheetIndex = 0; wb.Worksheets.RemoveAt("電子格式範本"); wb.Worksheets.RemoveAt("延修生異動名冊封面範本"); //儲存 Excel wb.Save(location, FileFormatType.Excel2003); }
/// <summary> /// Deserializes the specified element. /// </summary> /// <param name="element">The element.</param> public override void Deserialize(System.Xml.XmlElement element) { this.AutoGetSource = null; this.Executable = string.Empty; this.HomeDirectory = string.Empty; this.LabelOnSuccess = null; this.Login = null; this.Password = new HiddenPassword(); this.Principal = string.Empty; this.Timeout = new Timeout(); this.Workspace = string.Empty; if (string.Compare(element.GetAttribute("type"), this.TypeName, false) != 0) { throw new InvalidCastException(string.Format("Unable to convert {0} to a {1}", element.GetAttribute("type"), this.TypeName)); } string s = Util.GetElementOrAttributeValue("autoGetSource", element); if (!string.IsNullOrEmpty(s)) { this.AutoGetSource = string.Compare(s, bool.TrueString, true) == 0; } s = Util.GetElementOrAttributeValue("executable", element); if (!string.IsNullOrEmpty(s)) { this.Executable = s; } s = Util.GetElementOrAttributeValue("homeDir", element); if (!string.IsNullOrEmpty(s)) { this.HomeDirectory = s; } s = Util.GetElementOrAttributeValue("labelOnSuccess", element); if (!string.IsNullOrEmpty(s)) { this.LabelOnSuccess = string.Compare(s, bool.TrueString, true) == 0; } s = Util.GetElementOrAttributeValue("login", element); if (!string.IsNullOrEmpty(s)) { this.Login = string.Compare(s, bool.TrueString, true) == 0; } this.Password.Password = Util.GetElementOrAttributeValue("password", element); s = Util.GetElementOrAttributeValue("principal", element); if (!string.IsNullOrEmpty(s)) { this.Principal = s; } XmlElement ele = (XmlElement)element.SelectSingleNode("timeout"); if (ele != null) { this.Timeout.Deserialize(ele); } s = Util.GetElementOrAttributeValue("workspace", element); if (!string.IsNullOrEmpty(s)) { this.Workspace = s; } }
/// <summary> /// Load state from an XML element /// </summary> /// <param name="xmlElement">XML element containing new state</param> public void LoadXml(System.Xml.XmlElement xmlElement) { XmlNamespaceManager xmlNamespaceManager; XmlNodeList xmlNodeList; IEnumerator enumerator; XmlElement iterationXmlElement; HashDataInfo newHashDataInfo; if (xmlElement == null) { throw new ArgumentNullException("xmlElement"); } if (xmlElement.HasAttribute("Id")) { this.id = xmlElement.GetAttribute("Id"); } else { this.id = ""; } xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable); xmlNamespaceManager.AddNamespace("xades", XadesSignedXml.XadesNamespaceUri); xmlNamespaceManager.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl); this.hashDataInfoCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xades:HashDataInfo", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newHashDataInfo = new HashDataInfo(); newHashDataInfo.LoadXml(iterationXmlElement); this.hashDataInfoCollection.Add(newHashDataInfo); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } XmlNode canonicalizationNode = xmlElement.SelectSingleNode("ds:CanonicalizationMethod", xmlNamespaceManager); if (canonicalizationNode != null) { this.canonicalizationMethod = new CanonicalizationMethod(); this.canonicalizationMethod.LoadXml((XmlElement)canonicalizationNode); } xmlNodeList = xmlElement.SelectNodes("xades:EncapsulatedTimeStamp", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.encapsulatedTimeStamp = new EncapsulatedPKIData("EncapsulatedTimeStamp"); this.encapsulatedTimeStamp.LoadXml((XmlElement)xmlNodeList.Item(0)); this.xmlTimeStamp = null; } else { XmlNode nodeEncapsulatedTimeStamp = null; foreach (XmlNode node in xmlElement.ChildNodes) { if (node.Name == "EncapsulatedTimeStamp") { nodeEncapsulatedTimeStamp = node; break; } } if (nodeEncapsulatedTimeStamp != null) { this.encapsulatedTimeStamp = new EncapsulatedPKIData("EncapsulatedTimeStamp"); this.encapsulatedTimeStamp.LoadXml((XmlElement)nodeEncapsulatedTimeStamp); this.xmlTimeStamp = null; } else { xmlNodeList = xmlElement.SelectNodes("xades:XMLTimeStamp", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.xmlTimeStamp = new XMLTimeStamp(); this.xmlTimeStamp.LoadXml((XmlElement)xmlNodeList.Item(0)); this.encapsulatedTimeStamp = null; } else { throw new CryptographicException("EncapsulatedTimeStamp or XMLTimeStamp missing"); } } } }