W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 16년 전 · 5452

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
15년 전 조회 1,919
15년 전 조회 744
15년 전 조회 1,216
15년 전 조회 1,194
15년 전 조회 2,981
15년 전 조회 3,332
15년 전 조회 2,000
15년 전 조회 1,472
15년 전 조회 2,090
15년 전 조회 1,595
15년 전 조회 1,208
15년 전 조회 3,897
15년 전 조회 1,536
15년 전 조회 1,630
15년 전 조회 2,891
15년 전 조회 1,589
15년 전 조회 4,289
15년 전 조회 2,495
15년 전 조회 3,267
15년 전 조회 1,899
15년 전 조회 2,133
15년 전 조회 1,419
15년 전 조회 4,495
15년 전 조회 4,119
15년 전 조회 3,929
15년 전 조회 5,319
15년 전 조회 3,561
15년 전 조회 1,922
15년 전 조회 1,870
15년 전 조회 2,013
15년 전 조회 1,718
16년 전 조회 4,133
16년 전 조회 3,035
16년 전 조회 2,203
16년 전 조회 1,795
16년 전 조회 2,008
16년 전 조회 2,501
16년 전 조회 1,582
16년 전 조회 2,518
16년 전 조회 1,843
16년 전 조회 1,952
16년 전 조회 1,606
16년 전 조회 2,306
16년 전 조회 1,623
16년 전 조회 2,040
16년 전 조회 2,232
16년 전 조회 1,311
16년 전 조회 1,377
16년 전 조회 2,022
16년 전 조회 5,453
16년 전 조회 1,745
16년 전 조회 2,265
16년 전 조회 2,461
16년 전 조회 1,620
16년 전 조회 1,408
16년 전 조회 2,335
16년 전 조회 5,050
16년 전 조회 2,314
16년 전 조회 2,983
16년 전 조회 1,852
16년 전 조회 3,712
16년 전 조회 4,559
16년 전 조회 3,206
16년 전 조회 2,463
16년 전 조회 2,550
16년 전 조회 2,783
16년 전 조회 2,287
16년 전 조회 5,658
16년 전 조회 3,482
16년 전 조회 1,461
16년 전 조회 1,817
16년 전 조회 5,181
16년 전 조회 2,422
16년 전 조회 3,509
16년 전 조회 2,788
16년 전 조회 1,671
16년 전 조회 5,489
16년 전 조회 2,595
16년 전 조회 6,089
16년 전 조회 2,047
16년 전 조회 4,121
16년 전 조회 3,145
16년 전 조회 2,321
16년 전 조회 2,344
16년 전 조회 4,506
16년 전 조회 3,402
16년 전 조회 2,937
16년 전 조회 3,077
16년 전 조회 2,195
16년 전 조회 1,882
16년 전 조회 1,803
16년 전 조회 1,509
16년 전 조회 1,790
16년 전 조회 2,007
16년 전 조회 1,708
16년 전 조회 4,954
16년 전 조회 3,956
16년 전 조회 1,901
16년 전 조회 1,648
16년 전 조회 2,389