我正在尝试阅读doc和docx文件.这是代码:
static String distination="E:\\
static String docFileName="Requirements.docx";
public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO code application logic here
ReadFile rf= new ReadFile();
rf.ReadFileParagraph(distination+docFileName);
}
public void ReadFileParagraph(String path) throws FileNotFoundException, IOException
{
FileInputStream fis;
File file = new File(path);
fis=new FileInputStream(file.getAbsolutePath());
String filename=file.getName();
String fileExtension=fileExtension(path);
if(fileExtension.equals("doc"))
{
HWPFDocument document=new HWPFDocument(fis);
WordExtractor DocExtractor = new WordExtractor(document);
ReadDocFile(DocExtractor,filename);
}
else if(fileExtension.equals("docx"))
{
XWPFDocument documentX = new XWPFDocument(fis);
List<XWPFParagraph> pera =documentX.getParagraphs();
ReadDocXFile(pera,filename);
}
else
{
System.out.println("format does not match"); …Run Code Online (Sandbox Code Playgroud) 我通过选择预先存在的组件创建了动态组件实例.例如,
@Component({
selector: 'dynamic-component',
template: `<div #container><ng-content></ng-content></div>`
})
export class DynamicComponent {
@ViewChild('container', {read: ViewContainerRef}) container: ViewContainerRef;
public addComponent(ngItem: Type<WidgetComponent>,selectedPlugin:Plugin): WidgetComponent {
let factory = this.compFactoryResolver.resolveComponentFactory(ngItem);
const ref = this.container.createComponent(factory);
const newItem: WidgetComponent = ref.instance;
newItem.pluginId = Math.random() + '';
newItem.plugin = selectedPlugin;
this._elements.push(newItem);
return newItem;
}
}
Run Code Online (Sandbox Code Playgroud)
我之前存在的组件是ChartWidget和PatientWidget,它扩展了我想在容器中添加的类WidgetComponent.例如,
@Component({
selector: 'chart-widget',
templateUrl: 'chart-widget.component.html',
providers: [{provide: WidgetComponent, useExisting: forwardRef(() => ChartWidget) }]
})
export class ChartWidget extends WidgetComponent implements OnInit {
constructor(ngEl: ElementRef, renderer: Renderer) {
super(ngEl, renderer);
}
ngOnInit() …Run Code Online (Sandbox Code Playgroud)