Commit d73405c0 authored by 黄奎's avatar 黄奎

新增引用

parent 0017b5e7
using Aspose.Words.Lists;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using NPOI.OpenXmlFormats;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
......
......@@ -103,6 +103,18 @@ namespace Edu.Common.Data
}
return model;
}
/// <summary>
/// 获取Word数据
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static object GetWordQuestionData(string filePath)
{
var questionList = Common.Plugin.AsposeWordHelper.GetWordData(filePath);
return questionList;
}
}
/// <summary>
......
......@@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspose.Words" Version="21.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.8" />
......@@ -13,25 +14,4 @@
<PackageReference Include="NPOI" Version="2.5.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="Aspose.Pdf">
<HintPath>..\lib\Aspose.Pdf.dll</HintPath>
</Reference>
<Reference Include="Aspose.Words">
<HintPath>..\lib\Aspose.Words.dll</HintPath>
</Reference>
<Reference Include="Spire.License">
<HintPath>..\lib\Spire.License.dll</HintPath>
</Reference>
<Reference Include="Spire.Pdf">
<HintPath>..\lib\Spire.Pdf.dll</HintPath>
</Reference>
<Reference Include="Spire.Presentation">
<HintPath>..\lib\Spire.Presentation.dll</HintPath>
</Reference>
<Reference Include="Spire.XLS">
<HintPath>..\lib\Spire.XLS.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Edu.Common.Plugin
{
/// <summary>
/// AsposeWord帮助类
/// </summary>
public class AsposeWordHelper
{
/// <summary>
/// 获取Word内容
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static List<string> GetWordData(string fileName)
{
Aspose.Words.Document doc = new Aspose.Words.Document(fileName);
List<string> list =new List<string>();
if (doc.FirstSection.Body.Paragraphs.Count > 0)
{
//word中的所有段落
foreach (var item in doc.FirstSection.Body.Paragraphs)
{
string text = Regex.Replace(item.GetText(), "\r", "");
text = text.Replace("\f", "");
text = text.Replace("Evaluation Only. Created with Aspose.Words. Copyright 2003-2021 Aspose Pty Ltd.", "");
if (!string.IsNullOrEmpty(text))
{
list.Add(text);
}
}
}
return list;
}
}
}
......@@ -15,6 +15,25 @@
"Edu.Model.dll": {}
}
},
"Aspose.Words/21.1.0": {
"dependencies": {
"Microsoft.Win32.Registry": "4.7.0",
"SkiaSharp": "2.80.1",
"System.Reflection.Emit": "4.3.0",
"System.Reflection.Emit.ILGeneration": "4.3.0",
"System.Text.Encoding.CodePages": "4.7.0"
},
"runtime": {
"lib/netstandard2.0/Aspose.Words.Pdf2Word.dll": {
"assemblyVersion": "21.1.0.0",
"fileVersion": "21.1.0.0"
},
"lib/netstandard2.0/Aspose.Words.dll": {
"assemblyVersion": "21.1.0.0",
"fileVersion": "21.1.0.0"
}
}
},
"BouncyCastle.NetCore/1.8.3": {
"dependencies": {
"NETStandard.Library": "1.6.1",
......@@ -890,6 +909,39 @@
}
}
},
"SkiaSharp/2.80.1": {
"dependencies": {
"System.Memory": "4.5.3"
},
"runtime": {
"lib/netstandard2.0/SkiaSharp.dll": {
"assemblyVersion": "2.80.0.0",
"fileVersion": "2.80.1.0"
}
},
"runtimeTargets": {
"runtimes/osx/native/libSkiaSharp.dylib": {
"rid": "osx",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win-arm64/native/libSkiaSharp.dll": {
"rid": "win-arm64",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win-x64/native/libSkiaSharp.dll": {
"rid": "win-x64",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win-x86/native/libSkiaSharp.dll": {
"rid": "win-x86",
"assetType": "native",
"fileVersion": "0.0.0.0"
}
}
},
"SSH.NET/2016.1.0": {
"dependencies": {
"Microsoft.CSharp": "4.5.0",
......@@ -1917,6 +1969,7 @@
},
"Edu.Common/1.0.0": {
"dependencies": {
"Aspose.Words": "21.1.0",
"Microsoft.AspNetCore.Http": "2.2.2",
"Microsoft.AspNetCore.Mvc.Formatters.Json": "2.2.0",
"Microsoft.Extensions.Configuration": "3.1.8",
......@@ -1936,6 +1989,13 @@
"serviceable": false,
"sha512": ""
},
"Aspose.Words/21.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-BM2BJz3b8uvN6KzVNSwwrtt0SXQcmzRZ0Cbq6lLOgzCS1fCpS3ieQt2TfeEw3OtvZpNVEWLuJGo1YqQJpMh9Dw==",
"path": "aspose.words/21.1.0",
"hashPath": "aspose.words.21.1.0.nupkg.sha512"
},
"BouncyCastle.NetCore/1.8.3": {
"type": "package",
"serviceable": true,
......@@ -2503,6 +2563,13 @@
"path": "sharpziplib/1.2.0",
"hashPath": "sharpziplib.1.2.0.nupkg.sha512"
},
"SkiaSharp/2.80.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-CiQwnDzG+1JNGzjAN9G/9n/lJgUVA/NPOFgSlEtu6c7qQ0O7P1tMjrXp/+PtWfX0xyyY9ABsFAZK2kW34U7r/A==",
"path": "skiasharp/2.80.1",
"hashPath": "skiasharp.2.80.1.nupkg.sha512"
},
"SSH.NET/2016.1.0": {
"type": "package",
"serviceable": true,
......
......@@ -16,6 +16,25 @@
"Edu.Repository.dll": {}
}
},
"Aspose.Words/21.1.0": {
"dependencies": {
"Microsoft.Win32.Registry": "4.7.0",
"SkiaSharp": "2.80.1",
"System.Reflection.Emit": "4.3.0",
"System.Reflection.Emit.ILGeneration": "4.3.0",
"System.Text.Encoding.CodePages": "4.7.0"
},
"runtime": {
"lib/netstandard2.0/Aspose.Words.Pdf2Word.dll": {
"assemblyVersion": "21.1.0.0",
"fileVersion": "21.1.0.0"
},
"lib/netstandard2.0/Aspose.Words.dll": {
"assemblyVersion": "21.1.0.0",
"fileVersion": "21.1.0.0"
}
}
},
"BouncyCastle.NetCore/1.8.3": {
"dependencies": {
"NETStandard.Library": "1.6.1",
......@@ -891,6 +910,39 @@
}
}
},
"SkiaSharp/2.80.1": {
"dependencies": {
"System.Memory": "4.5.3"
},
"runtime": {
"lib/netstandard2.0/SkiaSharp.dll": {
"assemblyVersion": "2.80.0.0",
"fileVersion": "2.80.1.0"
}
},
"runtimeTargets": {
"runtimes/osx/native/libSkiaSharp.dylib": {
"rid": "osx",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win-arm64/native/libSkiaSharp.dll": {
"rid": "win-arm64",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win-x64/native/libSkiaSharp.dll": {
"rid": "win-x64",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win-x86/native/libSkiaSharp.dll": {
"rid": "win-x86",
"assetType": "native",
"fileVersion": "0.0.0.0"
}
}
},
"SSH.NET/2016.1.0": {
"dependencies": {
"Microsoft.CSharp": "4.5.0",
......@@ -1918,6 +1970,7 @@
},
"Edu.Common/1.0.0": {
"dependencies": {
"Aspose.Words": "21.1.0",
"Microsoft.AspNetCore.Http": "2.2.2",
"Microsoft.AspNetCore.Mvc.Formatters.Json": "2.2.0",
"Microsoft.Extensions.Configuration": "3.1.8",
......@@ -1946,6 +1999,13 @@
"serviceable": false,
"sha512": ""
},
"Aspose.Words/21.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-BM2BJz3b8uvN6KzVNSwwrtt0SXQcmzRZ0Cbq6lLOgzCS1fCpS3ieQt2TfeEw3OtvZpNVEWLuJGo1YqQJpMh9Dw==",
"path": "aspose.words/21.1.0",
"hashPath": "aspose.words.21.1.0.nupkg.sha512"
},
"BouncyCastle.NetCore/1.8.3": {
"type": "package",
"serviceable": true,
......@@ -2513,6 +2573,13 @@
"path": "sharpziplib/1.2.0",
"hashPath": "sharpziplib.1.2.0.nupkg.sha512"
},
"SkiaSharp/2.80.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-CiQwnDzG+1JNGzjAN9G/9n/lJgUVA/NPOFgSlEtu6c7qQ0O7P1tMjrXp/+PtWfX0xyyY9ABsFAZK2kW34U7r/A==",
"path": "skiasharp/2.80.1",
"hashPath": "skiasharp.2.80.1.nupkg.sha512"
},
"SSH.NET/2016.1.0": {
"type": "package",
"serviceable": true,
......
......@@ -824,5 +824,19 @@ namespace Edu.WebApi.Controllers.Course
return model;
}
/// <summary>
/// 解析Word
/// </summary>
/// <param name="filePath"></param>
/// <param name="CourseId"></param>
/// <param name="Uid"></param>
/// <returns></returns>
public ApiResult ImportWordQuestion(string filePath, int CourseId, int Uid)
{
var userInfo = base.GetUserInfo(Uid);
var data = Common.Data.QuestionHelper.GetWordQuestionData(filePath);
return ApiResult.Success();
}
}
}
\ No newline at end of file
......@@ -38,10 +38,12 @@ namespace Edu.WebApi.Controllers.Upload
return new ApiResult { Code = (int)ResultCode.Fail, Message = "未选择文件", Data = "" };
}
var json = !string.IsNullOrEmpty(Request.Form["params"]) ? JObject.Parse(Request.Form["params"].ToString()) : null;
Int32.TryParse(json["Analysis"].ToString(), out int Analysis);
Int32.TryParse(json["Excel"].ToString(), out int Excel);
Int32.TryParse(json["CourseId"].ToString(), out int CourseId);
Int32.TryParse(json["Uid"].ToString(), out int Uid);
Int32.TryParse((json["Analysis"]!=null? json["Analysis"].ToString():"0"), out int Analysis);
Int32.TryParse((json["Excel"] != null ? json["Excel"].ToString() : "0"), out int Excel);
Int32.TryParse((json["Word"] != null ? json["Word"].ToString() : "0"), out int Word);
Int32.TryParse((json["CourseId"] != null ? json["CourseId"].ToString() : "0"), out int CourseId);
Int32.TryParse((json["Uid"] != null ? json["Uid"].ToString() : "0"), out int Uid);
string filename = files[0].FileName;
string fileExtention = System.IO.Path.GetExtension(files[0].FileName);
......@@ -58,10 +60,11 @@ namespace Edu.WebApi.Controllers.Upload
}
string path = Guid.NewGuid().ToString() + fileExtention;
string basepath = AppContext.BaseDirectory;
string path_server = basepath + "\\upfile\\temporary\\" + path;
if (!Directory.Exists(basepath + "\\upfile\\temporary"))
string tempPath = basepath + "\\upfile\\temporary\\" + DateTime.Now.ToString("yyyyMMdd")+"\\";
string path_server = tempPath + path;
if (!Directory.Exists(tempPath))
{
Directory.CreateDirectory(basepath + "\\upfile\\temporary");
Directory.CreateDirectory(tempPath);
}
using (FileStream fstream = new FileStream(path_server, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
......@@ -73,6 +76,11 @@ namespace Edu.WebApi.Controllers.Upload
{
return new QuestionController().ImportExcelQuestion(path_server, CourseId, Uid);
}
//导入Word文件
if (Analysis == 1 && Word == 1 && CourseId > 0)
{
return new QuestionController().ImportWordQuestion(path_server, CourseId, Uid);
}
return ApiResult.Success("", new { Name = filename, Path = path_server });
}
catch (Exception ex)
......
......@@ -18,6 +18,7 @@
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aspose.Words" Version="21.1.0" />
<PackageReference Include="JWT" Version="5.3.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment