2014-10-09 241 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