2014-10-09 246 views
0

如何在Excel表格中导出NSImage?将NSImage导出为Excel表格

当我尝试执行下面的操作时,Microsoft Excel应用程序无法读取内容。

NSBitmapImageRep *imageRep = [self.displayView bitmapImageRepForCachingDisplayInRect:[self.displayView bounds]]; 
[imageRep setSize:self.displayView.frame.size]; 
       [self.displayView cacheDisplayInRect:[self.displayView bounds] toBitmapImageRep:imageRep]; 
NSImage *image1 = [[NSImage alloc] initWithSize:NSMakeSize(imageRep.pixelsWide, imageRep.pixelsHigh)]; 
[image1 addRepresentation:imageRep]; 
[[image1 TIFFRepresentation] 
writeToFile:@"AbsolutePath/ExportImageTest.xlsx"atomically:YES]; 

可以任何一个建议我如何导出视图转换为Excel表格中的NSImage?

+0

一个TIFF不是一个Excel电子表格。你为什么相信用.xlsx编写一个TIFF会将它变成一个? – 2014-10-09 14:49:59

+0

是的,你是对的布拉德,但你可以帮助我在Excel工作表上使用NSImage完成这项工作吗?有没有办法做到这一点? – 2014-10-10 09:36:56

回答

1

当您拨打writeToFile:automatically:时,它会在该路径上保存tiff,但不会将其添加到xlsx。 您需要知道什么是xlsx格式,然后决定如何将文件写入它。

这可能会帮助:

Creating Excel (.xlsx) files in Cocoa

+0

您分享的链接显示了如何将标签放置在实际图片应显示在Excel表格外的位置。我想要一个实际的图像在Excel表格中。 – 2014-10-10 09:38:03

+0

你可以在那个img标签中使用base64吗? – Krzysztof 2014-10-10 09:56:26