我正在从 excel 表中复制一个值 8.03,并使用下面的代码从剪贴板中读取 C# 中的值。出来的值是 8.0299999999999994 而不是 8.03。当我查看下面的 xml 时,值为 8.0299999999999994。xlsx 的 zip 文件中的 sheet1.xml 的值也为 8.02999999999999994。但是当我将值复制到记事本时,值会在 8.03 处被复制。我该怎么做才能像记事本一样将值复制为 8.03?
DataObject retrievedData = Clipboard.GetDataObject() as DataObject;
if (retrievedData.GetDataPresent("XML Spreadsheet"))
{
var sourceDataReader = new XmlTextReader(retrievedData.GetData("XML Spreadsheet") as System.IO.Stream);
var doc = XDocument.Load(reader);
var excelWorksheeet = doc.Element("Worksheet");
XNamespace ns = "urn:schemas-microsoft-com:office:spreadsheet";
XName worksheetName = ns + "Worksheet";
var worksheetElement = doc.Root.Element(worksheetName);
}
worksheetElement 具有以下值:
<Worksheet ss:Name="Sheet1" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" ss:DefaultRowHeight="15">
<Row>
<Cell>
<Data ss:Type="Number">8.0299999999999994</Data>
</Cell>
</Row>
</Table>
</Worksheet>