【C#将.doc转换为.htm】教程文章相关的互联网学习教程文章

使用C#和BizTalk将Excel(xlsx)转换为XML【代码】

我已经查看了这个论坛上关于类似问题的大多数主题,但没有找到我正在寻找的内容. 我正在尝试使用C#编写BizTalk 2013 R2的管道组件,只是将传入的Excel 2010 .xlsx文件转换为它的裸/基XML表示. 我不想对它运行任何模板或XLST转换它或类似的东西.我只是想按原样返回所述电子表格的基础XML表示. 看起来这应该是一项非常简单的任务,但我根本无法弄清楚如何去做. 我发现的一切都需要使用DataTables并循环遍历行和单元格(通过OpenXML)来输出...

c# – 无法将类型X强制转换为类型Y.LINQ to Entities仅支持强制转换EDM原语或枚举类型【代码】

我完全理解这个错误,但有没有办法实现一些代码,以便linq实体理解我的自定义类型应该被视为十进制基本类型? 我已经创建了一个自定义Money类型,它接受一个构造函数重载的可空小数.它具有隐式运算符重载和所有其他类型的酷爵士乐.我想在我的linq中使用这个自定义类型实体投影,但是标题中的错误. 是否有一个属性,我可以在我的Money类型上声明,“嘿,为了linq投影的目的,我是原始类型十进制”? 是否有某种方式自定义表达式树/访问者可以...

c# – 为什么在某些值类型的数组之间进行转换似乎打破了类型安全性?【代码】

参见英文答案 > Why does my C# array lose type sign information when cast to object? 4个以下代码:object array = new int[] {-1}; Console.WriteLine("array is uint[]: {0}", array is uint[]); Console.WriteLine("array[0]: {0:X}", ((uint[])array)[0]);打印以下内容,没有任何错误:array is uint[]: Truearray[0]: FFFFFFFF这似乎是我所特有的,因为它似乎打破了类型安全.执行以下操...

将每像素2字节的MONO-16位图像转换为MONO-16位,C#中每像素1字节【代码】

我在C#工作,我有一个单色相机给我两个连续的图像.我想减去这些图像. 相机设置为MONO-16,分辨率为1980960. 相机向我返回2457600个元素的向量,因为每个像素由两个字节表示,因此{1980960 = 1228800} * 2个字节/像素= 2457600. 问题是我必须将两个2457600元素向量转换为两个1228800向量才能进行减法. 所以我需要将2457600的两个连续元素组合成一个元素,这样我最终得到一个1228800元素的向量,其元素有16位范围(0-65536). 我可能需要创建...

c# – 当使用的值可以隐式转换为这些结构时,为什么我不能使用带有两个结构的重载==?【代码】

我注意到在应用operator ==时,用户定义的隐式转换行为与用户定义的隐式转换到任意结构MyStruct的行为之间存在差异. 如果我有:public struct IntA {public IntA(int value){ m_value = value; }public static implicit operator int(IntA a){ return a.m_value; }private int m_value; }public struct IntB {public IntB(int value){ m_value = value; }public static implicit operator int(IntB b){ return b.m_value; }private ...

c# – 我想在EST中初始化DateTime,然后转换为Universal TIme【代码】

我想在东部标准时间初始化DateTime,然后转换为通用时间. 我有一个DateTime(CurrentDT),其TimeZone未设置,但它在EST中.它是从下面的sting解析的“ddd, d MMM yyyy H:mm:ss”我写了以下代码来解决问题.TimeZoneInfo currentTimeZone=null;currentTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); CurrentDT=TimeZoneInfo.ConvertTime(CurrentDT, currentTimeZone);CurrentDT = CurrentDT.ToUniversal...

c# – 将类型转换(向下转换)为另一个子类型时的运行时错误【代码】

在我创建的许多其他类型中,可以使用downCast类型我通常也创建一个扩展方法,因此它更容易管理…BaseTypeM BTDerV : BaseTypeM BTDerLastDescndnt : BTDerV现在我创建一个LastDerived类型并将其值分配给ParentTypeBTDerV BTDer;BTDerLastDescndnt BTDerLastDesc = new BTDerLastDescndnt(parA, ParB);this.BTDer = BTDerLastDesc;然后使用downCast扩展var LDesc = this.BTDer.AsBTDerLastDescndnt();这实际上是public static BTDerLa...

c# – 将int转换为string用于dropdownlistfor【代码】

我有一个年龄的int属性,以及可供选择的年龄的选择列表.检索数据进行编辑时,我在添加tostring()方法时遇到错误:Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.所以我的viewmodel看起来像:public int LowerAgeLimit { get; set; } public List<SelectListItem> Ages { get; set; }我的查询是正确检索数据,然后在视图中我试图将数...

c# – 附加信息:将值[string]转换为[enum]类型时出错【代码】

每当我尝试反序列化下面的json字符串时,我收到此错误: 错误:Additional information: Error converting value“invalid_request_error” to type ‘ErrorType’. Path ‘type’, line 2,position 33.Json字符串{"error": {"type": "invalid_request_error","message": "Invalid request (check that your POST content type is application/x-www-form-urlencoded). If you have any questions, we can help at https://support....

c# – 如何防止Android中页面转换之间出现白屏?【代码】

我注意到我的Android版Xamarin.Forms应用暂时在页面转换之间显示白屏.在启动时和页面加载之间,我想知道在Xamarin.Forms中处理这种情况的最佳方法是什么? 我在资源样式中尝试了这些设置,但没有运气:<style name="AppDefaultTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"><item name="android:windowTranslucentStatus">true</item><item name="android:windowIsTranslucent">true</item><item name="android:windowDis...

c# – 转换EPSG:4326投影到EPSG:3857 mercator【代码】

我使用sharpmap从MSSQL渲染边框(几何)作为PNG图像.这一切都运作良好,除了国家在平面图像格式上看起来太“宽”. 据我了解,我需要创建EPSG转换:3857投影,但我不知道该怎么做. 这是我的代码var map = new Map(new Size(request.Width, request.Height));map.BackColor = Color.Transparent;var countryGeometry = GeometryFromWKT.Parse(dto.CountryWkt);IProvider countryProvider = new GeometryFeatureProvider(countryGeometry);...

Xamarin Android:在C中将字符串从C#转换为Unicode字符串的正确方法是什么?【代码】

我正在编写一个Xamarin Android应用程序,并尝试编写Xamarin应用程序需要传递数据的C本机库.我需要将一个Unicode字符串传递给库,但是当我尝试时,我会遇到一些奇怪的行为. 在我的本机共享库中,我有以下代码:extern "C" void logANSI(const char* data) {__android_log_print(ANDROID_LOG_INFO, "StringMarshaling", "ANSI data: %s", data); }extern "C" void logUnicode(const wchar_t* data) {__android_log_print(ANDROID_LOG_IN...

c# – 在聚合之前如何将值转换为long?【代码】

从EF核心2.1.4开始,如果我们将int值转换为long或long?在聚合之前(可能是为了避免算术溢出),此强制转换不会影响生成的查询,无论如何都会发生溢出.using Microsoft.EntityFrameworkCore; using System; using System.Linq;namespace EfCoreBugs {class Program{static void Main(string[] args){using (var dbContext = new MyDbContext()){Console.WriteLine(dbContext.Payments.Sum(x => (long?)x.Amount));}Console.ReadLine();}...

c# – 扩展方法问题的IEnumerable转换【代码】

我有以下类和扩展类(对于此示例):public class Person<T> {public T Value { get; set; } }public static class PersonExt {public static void Process<TResult>(this Person<IEnumerable<TResult>> p){// Do something with .Any().Console.WriteLine(p.Value.Any());} }我期待我可以编写类似下面的东西,它会起作用,但它不会:var x = new Person<List<String>>(); x.Process();由于List在继承树中比IEnumerable低,这不应该有效...

c# – 转换为数字的单词表示【代码】

使用C#我需要将一个整数转换为它的单词表示,并且只能达到5到10.有没有比这更好的方法呢?static string[] numberwords = {"zero","one","two","three","four","five" };public static string GetNumberAsString(int value) {return numberwords[value]; }解决方法:你需要走多远? 我的猜测是你需要几个数组来做你需要的一般情况,比如“一个”到“二十”,“二十”到“九十”几十,“千”,“百万”等.