gpt4 book ai didi

java - 如何使用带有专有 java 后端文档系统的 MS Office

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:57:57 26 4
gpt4 key购买 nike

目前我有一个文档系统,可以在 iframe 中启动 Star Office 或 LibreOffice 中的文档。

展望 future ,我希望保留现有的文档系统,但将其集成到 SharePoint 中,以便我们能够使用 MS Office 打开和编辑文档。

由于没有可与 MS Office 集成的 Java Api,这就是我选择使用 SharePoint 的原因。

我可以设法从 Sharepoint 页面上的链接加载我的文档,但接下来是操作 MS Office 中的保存功能并确保我的文档不会保存在 Sharepoint 中的困难部分。

有没有人做过类似的事。

基本上,我只想使用 MS Office 与我的文档进行交互,而无需将内容存储在共享点中。所以我需要访问保存功能等。

据我所知,Apache POI 不是一个可行的解决方案,因为它不会以物理方式打开文档并允许用户单击文件 -> 保存。我的理解是,它可以通过在代码中操作文档来操作文档,但不能使用 office 中的任何控件。

我在这里读过http://msdn.microsoft.com/en-us/library/office/bb462633(v=office.12).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2您可以重新调整 office 中命令的用途并修改功能区?

谢谢你的建议

看来 WOPI 和 Office Web Apps 是可行的。基本上需要创建一个WOPI应用

最佳答案

好吧,我遇到了同样的问题,所以我实际上用 Apache POI 和 SVG edit 写了一个快速的 PPT 编辑器..但后来我切换到 Office Web Apps..这是 WOPI 服务器的快速实现,我是 Java伙计,所以我的 .NET 技能非常糟糕。编写 servlet 应该是微不足道的。

逻辑很简单:

将 WOPISrc 传递给办公室 Web 应用程序 - 这基本上是您的 WOPI 服务器的 URL,其中包含文件位置。您现在可以忽略 access_token/access_token_ttl。

使用至少 2 个请求访问 WOPISrc url 的 Office Web Apps:

  1. 这将是一个元数据请求,基本上是对 WOPIsrc 的 GET 调用。您将创建一个 WOPI (CheckFileInfo) 对象并将其以 JSON 编码发送回办公网络应用程序。
  2. 现在 Office Web Apps 将请求文件本身,它将附加 (/contents ) 到 WOPIsrc 的末尾。所以只需将其以二进制格式发回即可。
  3. (可选)Office Web Apps 将在保存时对 (WOPISrc + "/contents") 执行 POST。您可以从 POST 中获取数据并保存到磁盘。

注意:Word 不起作用:/您只能查看,对于您需要实现 Cobalt 协议(protocol) (FSSHTTP) 的编辑。我正在研究这个主题,但用 C# 编写会更容易,因为您可以获取 Cobalt 程序集。否则,此协议(protocol)使用 BASE64 编码的二进制消息 (FSSHTTPB) 实现 SOAP (FSSHTTP)

使用如下内容打开 Office Web Apps:

http://OFFICEWEBAPPS.HOST/p/PowerPointFrame.aspx?PowerPointView=EditView&access_token=12345&WOPISrc=URLENCODED_URL_OF_THE_WOPI_SERVER

喜欢:http://WOPISERVER.HOST:2000/wopi/files/1.pptx

这将在您的 c:\temp 中打开 1.pptx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Runtime.Serialization;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.IO;
using System.Runtime.Serialization.Json;

namespace WopiServerTutorial
{
public class WopiServer
{
private HttpListener Listener;

static void Main(string[] args)
{
WopiServer s = new WopiServer();
s.Start();

Console.WriteLine("A simple wopi webserver. Press a key to quit.");
Console.ReadKey();

s.Stop();
}

public void Start()
{
Listener = new HttpListener();
Listener.Prefixes.Add(@"http://+:8080/");
Listener.Start();
Listener.BeginGetContext(ProcessRequest, Listener);
Console.WriteLine(@"WopiServer Started");
}

public void Stop()
{
Listener.Stop();
}

private void ProcessRequest(IAsyncResult result)
{
HttpListener listener = (HttpListener)result.AsyncState;
HttpListenerContext context = listener.EndGetContext(result);

Console.WriteLine(@"Got a " + context.Request.HttpMethod + " request for URL: " + context.Request.Url.PathAndQuery);
var stringarr = context.Request.Url.AbsolutePath.Split('/');
var rootDir = @"C:\\temp\\";

if (stringarr.Length == 5 && context.Request.HttpMethod.Equals(@"GET"))
{
Console.WriteLine(@"Getting content for the file: " + rootDir + stringarr[3]);

// get file's content
var file = rootDir + stringarr[3];
var stream = new FileStream(file, FileMode.Open);
var fi = new FileInfo(file);

context.Response.ContentType = @"application/octet-stream";
context.Response.ContentLength64 = fi.Length;
stream.CopyTo(context.Response.OutputStream);
context.Response.Close();
}
//else if (stringarr.Length == 5 && context.Request.HttpMethod.Equals(@"POST"))
//{
// // write
//}
else if (stringarr.Length == 4 && context.Request.HttpMethod.Equals(@"GET"))
{
Console.WriteLine(@"Getting metdata for the file: " + rootDir + stringarr[3]);
var fi = new FileInfo(rootDir + stringarr[3]);

CheckFileInfo cfi = new CheckFileInfo();
cfi.AllowExternalMarketplace = false;
cfi.BaseFileName = fi.Name;
cfi.BreadcrumbBrandName = "";
cfi.BreadcrumbBrandUrl = "";
cfi.BreadcrumbDocName = "";
cfi.BreadcrumbDocUrl = "";
cfi.BreadcrumbFolderName = "";
cfi.BreadcrumbFolderUrl = "";
cfi.ClientUrl = "";
cfi.CloseButtonClosesWindow = false;
cfi.CloseUrl = "";
cfi.DisableBrowserCachingOfUserContent = true;
cfi.DisablePrint = true;
cfi.DisableTranslation = true;
cfi.DownloadUrl = "";
cfi.FileUrl = "";
cfi.FileSharingUrl = "";
cfi.HostAuthenticationId = "s-1-5-21-3430578067-4192788304-1690859819-21774";
cfi.HostEditUrl = "";
cfi.HostEmbeddedEditUrl = "";
cfi.HostEmbeddedViewUrl = "";
cfi.HostName = @"SharePoint";
cfi.HostNotes = @"HostBIEnabled";
cfi.HostRestUrl = "";
cfi.HostViewUrl = "";
cfi.IrmPolicyDescription = "";
cfi.IrmPolicyTitle = "";
cfi.OwnerId = @"4257508bfe174aa28b461536d8b6b648";
cfi.PresenceProvider = "AD";
cfi.PresenceUserId = @"S-1-5-21-3430578067-4192788304-1690859819-21774";
cfi.PrivacyUrl = "";
cfi.ProtectInClient = false;
cfi.ReadOnly = false;
cfi.RestrictedWebViewOnly = false;
cfi.SHA256 = "";
cfi.SignoutUrl = "";
cfi.Size = fi.Length;
cfi.SupportsCoauth = false;
cfi.SupportsCobalt = false;
cfi.SupportsFolders = false;
cfi.SupportsLocks = true;
cfi.SupportsScenarioLinks = false;
cfi.SupportsSecureStore = false;
cfi.SupportsUpdate = true;
cfi.TenantId = @"33b62539-8c5e-423c-aa3e-cc2a9fd796f2";
cfi.TermsOfUseUrl = "";
cfi.TimeZone = @"+0300#0000-11-00-01T02:00:00:0000#+0000#0000-03-00-02T02:00:00:0000#-0060";
cfi.UserCanAttend = false;
cfi.UserCanNotWriteRelative = false;
cfi.UserCanPresent = false;
cfi.UserCanWrite = true;
cfi.UserFriendlyName = "";
cfi.UserId = "";
cfi.Version = @"%22%7B59CCD75F%2D0687%2D4F86%2DBBCF%2D059126640640%7D%2C1%22";
cfi.WebEditingDisabled = false;

// encode json
var memoryStream = new MemoryStream();
var json = new DataContractJsonSerializer(typeof(CheckFileInfo));
json.WriteObject(memoryStream, cfi);
memoryStream.Flush();
memoryStream.Position = 0;
StreamReader streamReader = new StreamReader(memoryStream);
var jsonResponse = Encoding.UTF8.GetBytes(streamReader.ReadToEnd());

context.Response.ContentType = @"application/json";
context.Response.ContentLength64 = jsonResponse.Length;
context.Response.OutputStream.Write(jsonResponse, 0, jsonResponse.Length);
context.Response.Close();
}
else
{
byte[] buffer = Encoding.UTF8.GetBytes("");
context.Response.ContentLength64 = buffer.Length;
context.Response.ContentType = @"application/json";
context.Response.OutputStream.Write(buffer, 0, buffer.Length);
context.Response.OutputStream.Close();
}

Listener.BeginGetContext(ProcessRequest, Listener);
}
}

[DataContract]
public class CheckFileInfo
{
[DataMember]
public bool AllowExternalMarketplace { get; set; }
[DataMember]
public string BaseFileName { get; set; }
[DataMember]
public string BreadcrumbBrandName { get; set; }
[DataMember]
public string BreadcrumbBrandUrl { get; set; }
[DataMember]
public string BreadcrumbDocName { get; set; }
[DataMember]
public string BreadcrumbDocUrl { get; set; }
[DataMember]
public string BreadcrumbFolderName { get; set; }
[DataMember]
public string BreadcrumbFolderUrl { get; set; }
[DataMember]
public string ClientUrl { get; set; }
[DataMember]
public bool CloseButtonClosesWindow { get; set; }
[DataMember]
public string CloseUrl { get; set; }
[DataMember]
public bool DisableBrowserCachingOfUserContent { get; set; }
[DataMember]
public bool DisablePrint { get; set; }
[DataMember]
public bool DisableTranslation { get; set; }
[DataMember]
public string DownloadUrl { get; set; }
[DataMember]
public string FileSharingUrl { get; set; }
[DataMember]
public string FileUrl { get; set; }
[DataMember]
public string HostAuthenticationId { get; set; }
[DataMember]
public string HostEditUrl { get; set; }
[DataMember]
public string HostEmbeddedEditUrl { get; set; }
[DataMember]
public string HostEmbeddedViewUrl { get; set; }
[DataMember]
public string HostName { get; set; }
[DataMember]
public string HostNotes { get; set; }
[DataMember]
public string HostRestUrl { get; set; }
[DataMember]
public string HostViewUrl { get; set; }
[DataMember]
public string IrmPolicyDescription { get; set; }
[DataMember]
public string IrmPolicyTitle { get; set; }
[DataMember]
public string OwnerId { get; set; }
[DataMember]
public string PresenceProvider { get; set; }
[DataMember]
public string PresenceUserId { get; set; }
[DataMember]
public string PrivacyUrl { get; set; }
[DataMember]
public bool ProtectInClient { get; set; }
[DataMember]
public bool ReadOnly { get; set; }
[DataMember]
public bool RestrictedWebViewOnly { get; set; }
[DataMember]
public string SHA256 { get; set; }
[DataMember]
public string SignoutUrl { get; set; }
[DataMember]
public long Size { get; set; }
[DataMember]
public bool SupportsCoauth { get; set; }
[DataMember]
public bool SupportsCobalt { get; set; }
[DataMember]
public bool SupportsFolders { get; set; }
[DataMember]
public bool SupportsLocks { get; set; }
[DataMember]
public bool SupportsScenarioLinks { get; set; }
[DataMember]
public bool SupportsSecureStore { get; set; }
[DataMember]
public bool SupportsUpdate { get; set; }
[DataMember]
public string TenantId { get; set; }
[DataMember]
public string TermsOfUseUrl { get; set; }
[DataMember]
public string TimeZone { get; set; }
[DataMember]
public bool UserCanAttend { get; set; }
[DataMember]
public bool UserCanNotWriteRelative { get; set; }
[DataMember]
public bool UserCanPresent { get; set; }
[DataMember]
public bool UserCanWrite { get; set; }
[DataMember]
public string UserFriendlyName { get; set; }
[DataMember]
public string UserId { get; set; }
[DataMember]
public string Version { get; set; }
[DataMember]
public bool WebEditingDisabled { get; set; }
}
}

关于java - 如何使用带有专有 java 后端文档系统的 MS Office,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16937990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com