Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Controls / DataGridClipboardHelper.cs / 1305600 / DataGridClipboardHelper.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; using System.Windows; namespace System.Windows.Controls { internal static class DataGridClipboardHelper { private const string DATAGRIDVIEW_htmlPrefix = "Version:1.0\r\nStartHTML:00000097\r\nEndHTML:{0}\r\nStartFragment:00000133\r\nEndFragment:{1}\r\n"; private const string DATAGRIDVIEW_htmlStartFragment = "\r\n\r\n"; private const string DATAGRIDVIEW_htmlEndFragment = "\r\n\r\n\r\n"; internal static void FormatCell(object cellValue, bool firstCell, bool lastCell, StringBuilder sb, string format) { bool csv = string.Equals(format, DataFormats.CommaSeparatedValue, StringComparison.OrdinalIgnoreCase); if (csv || string.Equals(format, DataFormats.Text, StringComparison.OrdinalIgnoreCase) || string.Equals(format, DataFormats.UnicodeText, StringComparison.OrdinalIgnoreCase)) { if (cellValue != null) { bool escapeApplied = false; int length = sb.Length; FormatPlainText(cellValue.ToString(), csv, new StringWriter(sb, CultureInfo.CurrentCulture), ref escapeApplied); if (escapeApplied) { sb.Insert(length, '"'); } } if (lastCell) { // Last cell sb.Append('\r'); sb.Append('\n'); } else { sb.Append(csv ? ',' : '\t'); } } else if (string.Equals(format, DataFormats.Html, StringComparison.OrdinalIgnoreCase)) { if (firstCell) { // First cell - append start of row sb.Append(""); } sb.Append(" "); } } } internal static void GetClipboardContentForHtml(StringBuilder content) { content.Insert(0, ""); // Start cell if (cellValue != null) { FormatPlainTextAsHtml(cellValue.ToString(), new StringWriter(sb, CultureInfo.CurrentCulture)); } else { sb.Append(" "); } sb.Append(" "); // End cell if (lastCell) { // Last cell - append end of row sb.Append("
"); break; // default: // The seemingly arbitrary 160 comes from RFC if (ch >= 160 && ch < 256) { output.Write(""); output.Write(((int)ch).ToString(NumberFormatInfo.InvariantInfo)); output.Write(';'); } else { output.Write(ch); } break; } prevCh = ch; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; using System.Windows; namespace System.Windows.Controls { internal static class DataGridClipboardHelper { private const string DATAGRIDVIEW_htmlPrefix = "Version:1.0\r\nStartHTML:00000097\r\nEndHTML:{0}\r\nStartFragment:00000133\r\nEndFragment:{1}\r\n"; private const string DATAGRIDVIEW_htmlStartFragment = "\r\n\r\n"; private const string DATAGRIDVIEW_htmlEndFragment = "\r\n\r\n\r\n"; internal static void FormatCell(object cellValue, bool firstCell, bool lastCell, StringBuilder sb, string format) { bool csv = string.Equals(format, DataFormats.CommaSeparatedValue, StringComparison.OrdinalIgnoreCase); if (csv || string.Equals(format, DataFormats.Text, StringComparison.OrdinalIgnoreCase) || string.Equals(format, DataFormats.UnicodeText, StringComparison.OrdinalIgnoreCase)) { if (cellValue != null) { bool escapeApplied = false; int length = sb.Length; FormatPlainText(cellValue.ToString(), csv, new StringWriter(sb, CultureInfo.CurrentCulture), ref escapeApplied); if (escapeApplied) { sb.Insert(length, '"'); } } if (lastCell) { // Last cell sb.Append('\r'); sb.Append('\n'); } else { sb.Append(csv ? ',' : '\t'); } } else if (string.Equals(format, DataFormats.Html, StringComparison.OrdinalIgnoreCase)) { if (firstCell) { // First cell - append start of row sb.Append("
"); break; // default: // The seemingly arbitrary 160 comes from RFC if (ch >= 160 && ch < 256) { output.Write(""); output.Write(((int)ch).ToString(NumberFormatInfo.InvariantInfo)); output.Write(';'); } else { output.Write(ch); } break; } prevCh = ch; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RadialGradientBrush.cs
- ListItemCollection.cs
- DataGridAutomationPeer.cs
- FunctionDescription.cs
- TraceUtility.cs
- SamlAuthenticationStatement.cs
- ApplicationSecurityInfo.cs
- PhysicalFontFamily.cs
- TypeDefinition.cs
- StreamResourceInfo.cs
- SignatureGenerator.cs
- MouseEvent.cs
- GPRECT.cs
- IndentTextWriter.cs
- ListBase.cs
- CapabilitiesRule.cs
- WeakEventTable.cs
- SegmentInfo.cs
- MarshalDirectiveException.cs
- ServiceOperationListItem.cs
- MergeFailedEvent.cs
- GlobalProxySelection.cs
- Block.cs
- FlowLayoutPanel.cs
- Set.cs
- DataObject.cs
- BigInt.cs
- WebAdminConfigurationHelper.cs
- KernelTypeValidation.cs
- MouseButton.cs
- FixedTextView.cs
- TransactionFilter.cs
- SqlConnectionPoolProviderInfo.cs
- TextRangeAdaptor.cs
- TemplatePartAttribute.cs
- ItemsPanelTemplate.cs
- AxisAngleRotation3D.cs
- PartialCachingAttribute.cs
- WizardPanel.cs
- Int64Storage.cs
- PropertyEntry.cs
- DataList.cs
- EventDrivenDesigner.cs
- ExpressionBuilder.cs
- SQLByte.cs
- DesignerSelectionListAdapter.cs
- IItemContainerGenerator.cs
- OracleTransaction.cs
- BmpBitmapEncoder.cs
- ColorConverter.cs
- ReliableChannelFactory.cs
- ImagingCache.cs
- Base64Stream.cs
- DtrList.cs
- LookupNode.cs
- AutoGeneratedFieldProperties.cs
- ListViewInsertionMark.cs
- StorageRoot.cs
- SchemaCollectionPreprocessor.cs
- DbTransaction.cs
- EntityProxyFactory.cs
- AxHostDesigner.cs
- SettingsPropertyValue.cs
- DataListItemEventArgs.cs
- XNodeNavigator.cs
- MemberDomainMap.cs
- ReplyChannelBinder.cs
- RSACryptoServiceProvider.cs
- ObjectCloneHelper.cs
- TextEffect.cs
- WindowsScrollBarBits.cs
- BadImageFormatException.cs
- WebPartTransformerCollection.cs
- SoapFaultCodes.cs
- XmlByteStreamReader.cs
- RSAPKCS1SignatureFormatter.cs
- Label.cs
- Documentation.cs
- RepeaterItemCollection.cs
- RequestCache.cs
- ProtocolsSection.cs
- Validator.cs
- ObjectListItem.cs
- PopupEventArgs.cs
- CatalogPart.cs
- MemberRelationshipService.cs
- SerializationInfo.cs
- XmlSerializableServices.cs
- DisposableCollectionWrapper.cs
- Axis.cs
- ResourceManager.cs
- _OverlappedAsyncResult.cs
- PackWebResponse.cs
- TypeUtils.cs
- serverconfig.cs
- CodeMemberMethod.cs
- BinHexDecoder.cs
- QilCloneVisitor.cs
- XmlProcessingInstruction.cs
- GridViewRowEventArgs.cs