小编Ste*_*son的帖子

单元格中的Excel图像

如何将图像(图像类型)插入Excel工作表中的特定单元格

taperSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelSheets.get_Item("Taper");

Microsoft.Office.Interop.Excel.Range cell = GetMyPictureCELL(taperSheet);

Image myImage = new Image();
RenderTargetBitmap bmp;

bmp = new RenderTargetBitmap((int)this.Width, (int)this.Height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(myViewPort);

myImage.Source = bmp;
myImage.Stretch = Stretch.Uniform;
Run Code Online (Sandbox Code Playgroud)

现在 ?我希望

cell.Add(myImage)
Run Code Online (Sandbox Code Playgroud)

但我认为这并不容易.

/斯特凡

感谢您的输入doitgood

以下代码适用于我

在我的情况下,我的图像源是一个视口(myViewPort)图像的位置由单元格决定

try
{
    Image myImage = new Image();
    RenderTargetBitmap bmp;
    PngBitmapEncoder encoder;
    string fileName;
    System.IO.Stream stream;
    object missing = System.Reflection.Missing.Value; 
    Microsoft.Office.Interop.Excel.Picture pic = null;
    Microsoft.Office.Interop.Excel.Pictures p = null;

    bmp = new RenderTargetBitmap((int)this.Width, (int)this.Height, 96, 96, PixelFormats.Pbgra32);
    bmp.Render(myViewPort);

    myImage.Source = bmp;
    myImage.Stretch = Stretch.Uniform; …
Run Code Online (Sandbox Code Playgroud)

c# wpf excel image cell

6
推荐指数
1
解决办法
3万
查看次数

将RenderTargetBitmap转换为System.Drawing.Image

我有3D WPF视觉图像,我想传递给Excel单元格(通过剪贴板缓冲区)。

使用“正常” BMP图像,它可以工作,但我不知道如何转换RenderTargetBitmap

我的代码如下所示:

System.Windows.Media.Imaging.RenderTargetBitmap renderTarget = myParent.GetViewPortAsImage(DiagramSizeX, DiagramSizeY);
System.Windows.Controls.Image myImage = new System.Windows.Controls.Image();
myImage.Source = renderTarget;

System.Drawing.Bitmap pg = new System.Drawing.Bitmap(DiagramSizeX, DiagramSizeY);
System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(pg);
gr.DrawImage(myImage, 0, 0);

System.Windows.Forms.Clipboard.SetDataObject(pg, true);
sheet.Paste(range);
Run Code Online (Sandbox Code Playgroud)

我的问题是gr.DrawImage不接受a System.Windows.Controls.Image或a System.Windows.Media.Imaging.RenderTargetBitmap;只有一个System.Drawing.Image

如何将转换Controls.Image.Imaging.RenderTargetBitmapImage,或者有没有更简单的方法?

c# wpf system.drawing bitmapimage rendertargetbitmap

5
推荐指数
2
解决办法
8868
查看次数

C# 访问 EXCEL,将单元格格式设置为常规

在 C# 中操作 excel 单元格(通过 COM 对象)时,我应该使用 .Value 还是 .Value2 ?那是

 sheet.Cells[row + n, col].Value = "Hello world"
Run Code Online (Sandbox Code Playgroud)

或者

 sheet.Cells[row + n, col].Value2 = "Hello world"
Run Code Online (Sandbox Code Playgroud)

它们之间有什么区别?

另外,如何将单元格格式设置为“常规”?

sheet.Cells[row + n, col].NumberFormat = "XYZ";  // Not sure what should be here
Run Code Online (Sandbox Code Playgroud)

现在,当我分配一个带有数字“0,34”的单元格时,即使我这样做

sheet.Cells[row + n, col].NumberFormat = "@"; 
Run Code Online (Sandbox Code Playgroud)

我在每个单元格的左上角都会看到这个“小错误”标志

c# excel formatting cell

3
推荐指数
1
解决办法
2万
查看次数

Excel走来走去

如果你有一个单元格的参考,有没有办法在Excel表格中走动?像这样

Microsoft.Office.Interop.Excel.Range cellWalker = mfe.GetMyCell(Mysheet);

cellWalker = cellWalker.GoUpOneRowButKeepColumn();
cellWalker = cellWalker.GoDownOneRowButKeepColumn();
cellWalker = cellWalker.GoLeftOneColumnButKeepRow();
cellWalker = cellWalker.GoRightOneColumnButKeepRow();
Run Code Online (Sandbox Code Playgroud)

关心斯特凡

c# wpf excel move cell

1
推荐指数
1
解决办法
2593
查看次数

C#OrderByDescending

OrderByDescending是如何使用的?

我有一个标签,圈子,这样声明

ReadOnlyCollection<FlangeCircle> Circles
Run Code Online (Sandbox Code Playgroud)

其中包含一个variabel,类型为double的Diameter

我想根据diamter对它们进行排序,所以我试试

FlangeCircle<FlangeCircle> query = Circles.OrderByDescending(p => p.Diameter);
Run Code Online (Sandbox Code Playgroud)

但这不会通过编译器,但以下情况

var query = Circles.OrderByDescending(p => p.Diameter);
Run Code Online (Sandbox Code Playgroud)

为什么这样,我如何用"正确"类型声明查询呢?

/斯特凡

c# arrays collections wpf

1
推荐指数
1
解决办法
1276
查看次数